diff --git a/opt/ahenk/base/plugin/file_handler.py b/opt/ahenk/base/plugin/file_handler.py index 25de887..a29837f 100644 --- a/opt/ahenk/base/plugin/file_handler.py +++ b/opt/ahenk/base/plugin/file_handler.py @@ -14,12 +14,10 @@ class FileEventHandler(FileSystemEventHandler): 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) diff --git a/opt/ahenk/base/plugin/plugin_install_listener.py b/opt/ahenk/base/plugin/plugin_install_listener.py index 48e9212..e21d436 100644 --- a/opt/ahenk/base/plugin/plugin_install_listener.py +++ b/opt/ahenk/base/plugin/plugin_install_listener.py @@ -1,43 +1,20 @@ -import os -import signal +import threading import time -from watchdog.events import FileSystemEventHandler from watchdog.observers import Observer -from base.command.commander import Commander -from base.system.system import System +from base.plugin.file_handler import FileEventHandler -class FileEventHandler(FileSystemEventHandler): +class PluginInstallListener(threading.Thread): def __init__(self, plugin_path): + threading.Thread.__init__(self) self.path = plugin_path - def process(self, event): - - if event.src_path != self.path[:-1]: - if event.event_type in ('created', 'modified', 'moved'): - plu_path = event.src_path - if event.event_type == 'moved': - plu_path = event.dest_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) - - -class PluginInstallListener: - def listen(self, path): + def run(self): observer = Observer() - event_handler = FileEventHandler(path) - observer.schedule(event_handler, path, recursive=False) + event_handler = FileEventHandler(self.path) + observer.schedule(event_handler, self.path, recursive=False) observer.start() try: while True: diff --git a/opt/ahenk/base/plugin/plugin_manager.py b/opt/ahenk/base/plugin/plugin_manager.py index a9a70c5..154475d 100644 --- a/opt/ahenk/base/plugin/plugin_manager.py +++ b/opt/ahenk/base/plugin/plugin_manager.py @@ -4,7 +4,6 @@ # Author: Volkan Şahin import imp import os -from multiprocessing import Process from base.Scope import Scope from base.model.PluginBean import PluginBean @@ -34,7 +33,8 @@ class PluginManager(object): self.plugins = [] self.pluginQueueDict = dict() - self.listener = self.install_listener() + # self.listener = \ + self.install_listener() self.delayed_profiles = {} self.delayed_tasks = {} @@ -265,10 +265,9 @@ class PluginManager(object): return None def install_listener(self): - listener = PluginInstallListener() - thread = Process(target=listener.listen, args=(System.Ahenk.plugins_path(),)) - thread.start() - return thread + listener = PluginInstallListener(System.Ahenk.plugins_path()) + listener.setDaemon(True) + listener.start() def is_plugin_loaded(self, plugin_name): try: