Correct abs_map_path getting for watcher.py

parent 1385575c
......@@ -5,3 +5,5 @@ venv/
dist/
nginx_redirector.egg-info/
build/
*.log
......@@ -94,12 +94,19 @@ class ConfigReader:
@staticmethod
def parse_yaml(file_dir):
return_list = []
#print('file_dir is', file_dir)
yaml_dir = os.path.dirname(os.path.abspath(file_dir))
print('yaml_dir from parse_yaml', yaml_dir)
with open(file_dir, 'r') as stream:
data = load(stream, Loader=Loader)
for project in data.get("projects"):
map_path = project.get("map")
rel_map_path = os.path.relpath(map_path, start=yaml_dir)
abs_map_path = os.path.join(rel_map_path, yaml_dir, os.path.basename(map_path))
abs_map_path = os.path.normpath(abs_map_path)
print('abs_map_path from parse_yaml', abs_map_path)
project_prefix = project.get("prefix")
return_list.append((map_path, project_prefix))
return_list.append((abs_map_path, project_prefix))
return return_list
def parse_map(self, map_file, yaml_file):
......
......@@ -27,9 +27,15 @@ class RedirectorWatch:
if not yaml_file:
raise self.RedirectorWatchException("yaml_file list is empty", Exception)
Watch = self.create_watch_class(yaml_file)
yaml_dir = os.path.dirname(os.path.abspath(yaml_file))
for map_path, _ in self.parser.parse_yaml(yaml_file):
print('is error here', map_path)
self.redirector.generate(yaml_file, map_path)
rel_map_path = os.path.relpath(map_path, start=yaml_dir)
abs_map_path = os.path.join(rel_map_path, yaml_dir, os.path.basename(map_path))
abs_map_path = os.path.normpath(abs_map_path)
self.redirector.generate(yaml_file, abs_map_path)
try:
self.set_inotify(yaml_file, Watch)
except pyinotify.PyinotifyError as e:
......@@ -56,14 +62,17 @@ class RedirectorWatch:
# we suggest that self.watch_manager already exists
def set_inotify(self, yaml_file, Watch_class):
print('trying to set_inotify on {}'.format(yaml_file))
wm = pyinotify.WatchManager()
self.add_files(yaml_file, wm)
notifier = pyinotify.ThreadedNotifier(wm, Watch_class(redirector=self.redirector))
notifier.start()
self.pool[yaml_file] = [wm, notifier]
print('self.pool is', self.pool)
def add_files(self, file_, wm):
file_list = self.parser.parse_yaml(file_)
for map_path, _ in file_list:
abs_map_path = os.path.abspath(map_path)
wdd = wm.add_watch(abs_map_path, self.mask, rec=True)
......@@ -88,3 +97,4 @@ def watch(args=None):
if __name__ == "__main__":
watch()
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