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

Fixed little bugs and codestyle errors

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