From f3aa259944c6d8f26c20fb099b37dc0614c5f58a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Volkan=20=C5=9Eahin?= Date: Tue, 2 Aug 2016 18:13:04 +0300 Subject: [PATCH] minor fixing --- opt/ahenk/base/plugin/file_handler.py | 33 +++++++++++++++++++++++++++ opt/ahenk/base/timer/setup_timer.py | 2 -- opt/ahenk/base/timer/timer.py | 1 + 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 opt/ahenk/base/plugin/file_handler.py diff --git a/opt/ahenk/base/plugin/file_handler.py b/opt/ahenk/base/plugin/file_handler.py new file mode 100644 index 0000000..25de887 --- /dev/null +++ b/opt/ahenk/base/plugin/file_handler.py @@ -0,0 +1,33 @@ +import os +import signal + +from watchdog.events import FileSystemEventHandler + +from base.command.commander import Commander +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]: + print('event_type:'+str(event.event_type)) + if event.event_type in ('created', 'modified', 'moved'): + plu_path = event.src_path + if event.event_type == 'moved': + plu_path = event.dest_path + print('plu_path'+str(plu_path)) + 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): + if event.is_directory: + self.process(event) diff --git a/opt/ahenk/base/timer/setup_timer.py b/opt/ahenk/base/timer/setup_timer.py index 2d16c07..27eadfa 100644 --- a/opt/ahenk/base/timer/setup_timer.py +++ b/opt/ahenk/base/timer/setup_timer.py @@ -1,5 +1,3 @@ -from multiprocessing import Process - class SetupTimer: @staticmethod diff --git a/opt/ahenk/base/timer/timer.py b/opt/ahenk/base/timer/timer.py index e715bc7..d0662c4 100644 --- a/opt/ahenk/base/timer/timer.py +++ b/opt/ahenk/base/timer/timer.py @@ -1,6 +1,7 @@ import time import threading + class Timer(threading.Thread): def __init__(self, timeout, timeout_function, checker_func=None, checker_success_function=None, **kwargs): threading.Thread.__init__(self)