Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nginx-redirector
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
eterfund
nginx-redirector
Commits
58f9de1c
Commit
58f9de1c
authored
Jul 02, 2019
by
Nick Yefremov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed little bugs and codestyle errors
parent
0092920c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
59 deletions
+48
-59
parser.py
core/parser.py
+2
-2
redirector.py
core/redirector.py
+7
-12
setup.py
setup.py
+39
-45
No files found.
core/parser.py
View file @
58f9de1c
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
))
core/redirector.py
View file @
58f9de1c
...
...
@@ -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
)
setup.py
View file @
58f9de1c
...
...
@@ -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
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment