Commit 58f9de1c authored by Nick Yefremov's avatar Nick Yefremov

Fixed little bugs and codestyle errors

parent 0092920c
import os import os
from yaml import load, dump from yaml import load, YAMLError
try: try:
from yaml import CLoader as Loader, CDumper as Dumper from yaml import CLoader as Loader, CDumper as Dumper
except ImportError: except ImportError:
...@@ -122,6 +122,6 @@ class ConfigReader: ...@@ -122,6 +122,6 @@ class ConfigReader:
res[1].append((request_url, redirect_url)) res[1].append((request_url, redirect_url))
res[2].append((request_url, options)) res[2].append((request_url, options))
return res, res_prefix return res, res_prefix
except yaml.YAMLError as e: except YAMLError as e:
self.logger.log("Error occurred while reading %s" % yaml_file + str(e)) self.logger.log("Error occurred while reading %s" % yaml_file + str(e))
...@@ -38,21 +38,18 @@ class Redirector: ...@@ -38,21 +38,18 @@ class Redirector:
def __init__(self, message, errors): def __init__(self, message, errors):
super().__init__(message) super().__init__(message)
self.errors = errors self.errors = errors
class RedirectorGenerationError(Exception): class RedirectorGenerationError(Exception):
def __init__(self, message, errors): def __init__(self, message, errors):
super().__init__(message) super().__init__(message)
self.errors = errors self.errors = errors
class RedirectorInputDataError(Exception): class RedirectorInputDataError(Exception):
def __init__(self, message, errors): def __init__(self, message, errors):
super().__init__(message) super().__init__(message)
self.errors = errors self.errors = errors
"""
Need to take care of unusual behavior of server - lagging, reboots, etc -> need some kind of saving file
"""
class RedirectorWatch: class RedirectorWatch:
def __init__(self): def __init__(self):
self.logger = logger.Logger("redirector-watch.log") self.logger = logger.Logger("redirector-watch.log")
...@@ -60,7 +57,7 @@ class RedirectorWatch: ...@@ -60,7 +57,7 @@ class RedirectorWatch:
self.parser = parser.ConfigReader(logger=self.logger) self.parser = parser.ConfigReader(logger=self.logger)
self.mask = pyinotify.IN_MODIFY | pyinotify.IN_DELETE self.mask = pyinotify.IN_MODIFY | pyinotify.IN_DELETE
self.watch_manager = pyinotify.WatchManager() self.watch_manager = pyinotify.WatchManager()
self.notifier = None
def watch(self, yaml_file): def watch(self, yaml_file):
class Watch(pyinotify.ProcessEvent): class Watch(pyinotify.ProcessEvent):
...@@ -78,15 +75,15 @@ class RedirectorWatch: ...@@ -78,15 +75,15 @@ class RedirectorWatch:
wdd = self.watch_manager.add_watch(cwd + "/" + map_path, self.mask, rec=True) wdd = self.watch_manager.add_watch(cwd + "/" + map_path, self.mask, rec=True)
asyncore.loop() asyncore.loop()
def main(args=None): def main(args=None):
if not args: if not args:
args = sys.argv[1:] args = sys.argv[1:]
redirector = Redirector() redirector = Redirector()
try: try:
redirector.generate(*args) redirector.generate(*args)
except (Redirector.RedirectorGenerationError, redirector.RedirectorParserError) as e: except (Redirector.RedirectorGenerationError, redirector.RedirectorParserError) as e:
print("CRITICAL:\n" + str(e)) print("CRITICAL:\n" + str(e))
def watch(args=None): def watch(args=None):
...@@ -95,5 +92,3 @@ def watch(args=None): ...@@ -95,5 +92,3 @@ def watch(args=None):
print(args) print(args)
watch_ = RedirectorWatch() watch_ = RedirectorWatch()
watch_.watch(args) watch_.watch(args)
...@@ -6,28 +6,28 @@ from distutils.command.install import install ...@@ -6,28 +6,28 @@ from distutils.command.install import install
# from distutils import log # from distutils import log
from core import const from core import const
##### #####
data_files_list = [ data_files_list = [
['/etc/redirector'] ['/etc/redirector']
] ]
for maps_list_item in ( ("etc/redirector", "core"), ): for maps_list_item in (("etc/redirector", "core"),):
data_files_list.append(( maps_list_item[0], [ os.path.join(maps_list_item[1], item) for item data_files_list.append((maps_list_item[0], [os.path.join(maps_list_item[1], item) for item
in os.listdir(maps_list_item[1]) if os.path.isfile(maps_list_item[1] + '/'+ item) and item not in (".gitignore", "__pycache__") ] )) in os.listdir(maps_list_item[1]) if
os.path.isfile(maps_list_item[1] + '/' + item) and item not in (
".gitignore", "__pycache__")]))
classifiers_list = [
"Development Status :: 4 - Beta", classifiers_list = [
"Environment :: Plugins", "Development Status :: 4 - Beta",
"Operating System :: Ubuntu", "Environment :: Plugins",
"Programming Language :: Python%s" % const.PYTHON_VERSION, "Operating System :: Ubuntu",
"Topic :: System", "Programming Language :: Python%s" % const.PYTHON_VERSION,
"Topic :: Utilities", "Topic :: System",
{ "Topic :: Utilities",
"alpha" : "Development Status :: 3 - Alpha", {
"beta" : "Development Status :: 4 - Beta", "alpha": "Development Status :: 3 - Alpha",
"stable" : "Development Status :: 5 - Production/Stable" "beta": "Development Status :: 4 - Beta",
}[const.VERSION_STATUS] "stable": "Development Status :: 5 - Production/Stable"
}[const.VERSION_STATUS]
] ]
""" """
...@@ -37,39 +37,33 @@ config ...@@ -37,39 +37,33 @@ config
""" """
##### Private classes #####
class RedirectorInstall(install) :
### Public ###
def run(self) : # Private classes #
install.run(self) class RedirectorInstall(install):
def run(self):
install.run(self)
# Main #
##### Main #####
setup( setup(
name = const.NAME, name=const.NAME,
version = const.VERSION, version=const.VERSION,
author = const.AUTHOR, author=const.AUTHOR,
author_email = const.EMAIL, author_email=const.EMAIL,
# maintainer = const.MAINTAINER, # maintainer = const.MAINTAINER,
# maintainer_email =const.MAINTAINER_EMAIL, # maintainer_email =const.MAINTAINER_EMAIL,
description = "Utility for generating nginx .config and .map files from custom config files", description="Utility for generating nginx .config and .map files from custom config files",
packages = None, packages=None,
data_files = data_files_list, data_files=data_files_list,
requires = [ requires=[
"pyyaml", "pyyaml",
"pyinotify" "pyinotify"
], ],
cmdclass = { "install" : RedirectorInstall }, cmdclass={"install": RedirectorInstall},
classifiers = classifiers_list 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