Changed the name of core directory, added files generation on start of redirector-watch

parent 623eae9a
......@@ -2,11 +2,12 @@ import sys
import os
import pyinotify
import asyncore
import argparse as ap
from core import generators
from core import logger
from core import parser
from core import const
from dev import generators
from dev import logger
from dev import parser
from dev import const
redirector_watch = None
......@@ -63,13 +64,13 @@ class RedirectorWatch:
def watch(self, yaml_file):
if not yaml_file:
raise self.RedirectorWatchException("yaml_file list is empty", Exception)
yaml_file = yaml_file if isinstance(yaml_file, list) else [yaml_file]
for yfile in yaml_file:
Watch = self.create_watch_class(yfile)
try:
self.set_inotify(yfile, Watch)
except pyinotify.PyinotifyError as e:
raise self.RedirectorWatchException("Can\'t set inotify for yamll file %s" % yfile, e)
Watch = self.create_watch_class(yaml_file)
for map_path, _ in self.parser.parse_yaml(yaml_file):
self.redirector.generate(yaml_file, map_path)
try:
self.set_inotify(yaml_file, Watch)
except pyinotify.PyinotifyError as e:
raise self.RedirectorWatchException("Can\'t set inotify for yamll file %s" % yaml_file, e)
# creating class Watch with custom static 'yaml_file' argument
def create_watch_class(self, yaml_file):
......@@ -80,9 +81,14 @@ class RedirectorWatch:
super().__init__(*args, **kwargs)
def process_IN_MODIFY(self, event):
redirector_watch.pool[yaml_file][1].stop()
try:
redirector_watch.pool[yaml_file][1].stop()
except RuntimeError as e:
print("hello there")
redirector_watch.pool[yaml_file] = None
print("Proccessing...")
self.redirector.generate(yaml_file, event.pathname)
redirector_watch.watch(yaml_file)
return Watch
# we suggest that self.watch_manager already exists
......@@ -106,19 +112,27 @@ class RedirectorWatch:
def main(args=None):
parser = ap.ArgumentParser(description='Redirector: nginx config generator')
parser.add_argument('yaml_file', metavar='Y', type=str, nargs=1, help='.yaml file that defines project and it\'s content')
parser.add_argument('map_file', metavar='M', type=str, nargs=1, help='.map file that defines redirects for project')
if not args:
args = sys.argv[1:]
args = parser.parse_args()
redirector = Redirector()
try:
redirector.generate(*args)
redirector.generate(args.yaml_file[0], args.map_file[0])
except (Redirector.RedirectorGenerationError, redirector.RedirectorParserError) as e:
print("CRITICAL:\n" + str(e))
def watch(args=None):
global redirector_watch
if not redirector_watch:
redirector_watch = RedirectorWatch()
parser = ap.ArgumentParser(description='Redirector watchdog utility')
parser.add_argument('filename', metavar='Y', type=str, nargs=1,
help='Sets watch on the content of .yaml file')
if not args:
args = sys.argv[1:]
redirector_watch.watch(args)
args = parser.parse_args()
global redirector_watch
redirector_watch = RedirectorWatch()
redirector_watch.watch(args.filename[0])
......@@ -24,8 +24,8 @@ setup(
packages=find_packages(),
entry_points={
'console_scripts': [
'redirector = core.redirector:main',
'redirector-watch = core.redirector:watch'
'redirector = dev.redirector:main',
'redirector-watch = dev.redirector:watch'
]
},
classifiers=classifiers_list
......
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