Fixed a lot of bugs and implemented deletion of unused notifiers

parent b8b6c22b
......@@ -3,10 +3,10 @@ import os
import pyinotify
import asyncore
from mymodule import generators
from mymodule import logger
from mymodule import parser
from mymodule import const
from core import generators
from core import logger
from core import parser
from core import const
redirector_watch = None
......@@ -57,8 +57,8 @@ class RedirectorWatch:
self.redirector = Redirector()
self.parser = parser.ConfigReader(logger=self.logger)
self.mask = pyinotify.IN_MODIFY
self.wm_pool = []
self.n_pool = []
self.pool = {}
def watch(self, yaml_file):
if not yaml_file:
......@@ -73,12 +73,15 @@ class RedirectorWatch:
# creating class Watch with custom static 'yaml_file' argument
def create_watch_class(self, yaml_file):
global redirector_watch
class Watch(pyinotify.ProcessEvent):
def __init__(self, *args, **kwargs):
self.redirector = kwargs.pop("redirector")
super().__init__(*args, **kwargs)
def process_IN_MODIFY(self, event):
redirector_watch.pool[yaml_file][1].stop()
redirector_watch.pool[yaml_file] = None
self.redirector.generate(yaml_file, event.pathname)
return Watch
......@@ -86,10 +89,9 @@ class RedirectorWatch:
def set_inotify(self, yaml_file, Watch_class):
wm = pyinotify.WatchManager()
self.add_files(yaml_file, wm)
self.wm_pool.append(wm)
notifier = pyinotify.ThreadedNotifier(wm, Watch_class(redirector=self.redirector))
notifier.start()
self.n_pool.append(notifier)
self.pool[yaml_file] = [wm, notifier]
def add_files(self, file_, wm):
file_list = self.parser.parse_yaml(file_)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment