Fixed a lot of bugs and implemented deletion of unused notifiers

parent b8b6c22b
...@@ -3,10 +3,10 @@ import os ...@@ -3,10 +3,10 @@ import os
import pyinotify import pyinotify
import asyncore import asyncore
from mymodule import generators from core import generators
from mymodule import logger from core import logger
from mymodule import parser from core import parser
from mymodule import const from core import const
redirector_watch = None redirector_watch = None
...@@ -57,8 +57,8 @@ class RedirectorWatch: ...@@ -57,8 +57,8 @@ class RedirectorWatch:
self.redirector = Redirector() self.redirector = Redirector()
self.parser = parser.ConfigReader(logger=self.logger) self.parser = parser.ConfigReader(logger=self.logger)
self.mask = pyinotify.IN_MODIFY self.mask = pyinotify.IN_MODIFY
self.wm_pool = [] self.pool = {}
self.n_pool = []
def watch(self, yaml_file): def watch(self, yaml_file):
if not yaml_file: if not yaml_file:
...@@ -73,12 +73,15 @@ class RedirectorWatch: ...@@ -73,12 +73,15 @@ class RedirectorWatch:
# creating class Watch with custom static 'yaml_file' argument # creating class Watch with custom static 'yaml_file' argument
def create_watch_class(self, yaml_file): def create_watch_class(self, yaml_file):
global redirector_watch
class Watch(pyinotify.ProcessEvent): class Watch(pyinotify.ProcessEvent):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
self.redirector = kwargs.pop("redirector") self.redirector = kwargs.pop("redirector")
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
def process_IN_MODIFY(self, event): 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) self.redirector.generate(yaml_file, event.pathname)
return Watch return Watch
...@@ -86,10 +89,9 @@ class RedirectorWatch: ...@@ -86,10 +89,9 @@ class RedirectorWatch:
def set_inotify(self, yaml_file, Watch_class): def set_inotify(self, yaml_file, Watch_class):
wm = pyinotify.WatchManager() wm = pyinotify.WatchManager()
self.add_files(yaml_file, wm) self.add_files(yaml_file, wm)
self.wm_pool.append(wm)
notifier = pyinotify.ThreadedNotifier(wm, Watch_class(redirector=self.redirector)) notifier = pyinotify.ThreadedNotifier(wm, Watch_class(redirector=self.redirector))
notifier.start() notifier.start()
self.n_pool.append(notifier) self.pool[yaml_file] = [wm, notifier]
def add_files(self, file_, wm): def add_files(self, file_, wm):
file_list = self.parser.parse_yaml(file_) 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