mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2024-12-23 14:32:18 +03:00
threads convert to daemon
This commit is contained in:
parent
f13482c515
commit
a5c864d33f
3 changed files with 12 additions and 38 deletions
|
@ -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)
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
# Author: Volkan Şahin <volkansah.in> <bm.volkansahin@gmail.com>
|
||||
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:
|
||||
|
|
Loading…
Reference in a new issue