mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2024-11-22 15:32:19 +03:00
new plugin listener
This commit is contained in:
parent
cee4901319
commit
cc113eb664
1 changed files with 47 additions and 0 deletions
47
opt/ahenk/base/plugin/plugin_install_listener.py
Normal file
47
opt/ahenk/base/plugin/plugin_install_listener.py
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
import os
|
||||||
|
import signal
|
||||||
|
import time
|
||||||
|
|
||||||
|
from watchdog.events import FileSystemEventHandler
|
||||||
|
from watchdog.observers import Observer
|
||||||
|
|
||||||
|
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.event_type == 'created':
|
||||||
|
result = Commander().set_event([None, 'load', '-p', event.src_path.replace(self.path, '')])
|
||||||
|
if result is True:
|
||||||
|
if System.Ahenk.is_running() is True:
|
||||||
|
os.kill(int(System.Ahenk.get_pid_number()), signal.SIGALRM)
|
||||||
|
elif event.event_type == 'deleted':
|
||||||
|
# TODO
|
||||||
|
print('plugin removed')
|
||||||
|
|
||||||
|
def on_created(self, event):
|
||||||
|
if event.is_directory:
|
||||||
|
self.process(event)
|
||||||
|
|
||||||
|
def on_deleted(self, event):
|
||||||
|
if event.is_directory:
|
||||||
|
self.process(event)
|
||||||
|
|
||||||
|
|
||||||
|
class PluginInstallListener:
|
||||||
|
def listen(self, path):
|
||||||
|
observer = Observer()
|
||||||
|
event_handler = FileEventHandler(path)
|
||||||
|
observer.schedule(event_handler, path, recursive=False)
|
||||||
|
observer.start()
|
||||||
|
try:
|
||||||
|
while True:
|
||||||
|
time.sleep(1)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
observer.stop()
|
||||||
|
observer.join()
|
Loading…
Reference in a new issue