2016-08-24 18:05:54 +03:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# Author: Volkan Şahin <volkansah.in> <bm.volkansahin@gmail.com>
|
|
|
|
|
2016-08-02 18:13:04 +03:00
|
|
|
import os
|
|
|
|
import signal
|
|
|
|
|
|
|
|
from watchdog.events import FileSystemEventHandler
|
|
|
|
|
2016-09-21 12:05:48 +03:00
|
|
|
from base.command.command_manager import Commander
|
2016-08-02 18:13:04 +03:00
|
|
|
from base.system.system import System
|
|
|
|
|
|
|
|
|
|
|
|
class FileEventHandler(FileSystemEventHandler):
|
|
|
|
def __init__(self, plugin_path):
|
|
|
|
self.path = plugin_path
|
|
|
|
|
|
|
|
def process(self, event):
|
|
|
|
|
|
|
|
if event.src_path != self.path[:-1]:
|
2016-08-04 18:11:00 +03:00
|
|
|
if event.event_type == 'moved':
|
|
|
|
plu_path = event.dest_path
|
2016-08-02 18:13:04 +03:00
|
|
|
result = Commander().set_event([None, 'load', '-p', plu_path.replace(self.path, '')])
|
|
|
|
if result is True and System.Ahenk.is_running() is True:
|
|
|
|
os.kill(int(System.Ahenk.get_pid_number()), signal.SIGALRM)
|
|
|
|
elif event.event_type == 'deleted':
|
|
|
|
result = Commander().set_event([None, 'remove', '-p', event.src_path.replace(self.path, '')])
|
|
|
|
if result is True and System.Ahenk.is_running() is True:
|
|
|
|
os.kill(int(System.Ahenk.get_pid_number()), signal.SIGALRM)
|
|
|
|
|
|
|
|
def on_any_event(self, event):
|
2016-08-04 18:11:00 +03:00
|
|
|
|
2016-08-02 18:13:04 +03:00
|
|
|
if event.is_directory:
|
|
|
|
self.process(event)
|