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
b8b6c22b
Commit
b8b6c22b
authored
Jul 04, 2019
by
Никита Ефремов
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added and partly debugged multithreaded RedirectorWatch
parent
6e897a1e
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
62 deletions
+54
-62
const.py
core/const.py
+1
-1
redirector.py
core/redirector.py
+43
-15
setup.py
setup.py
+10
-46
No files found.
core/const.py
View file @
b8b6c22b
...
...
@@ -5,7 +5,7 @@ EMAIL = "enk@etersoft.ru"
PYTHON_VERSION
=
"3.6"
VERSION_STATUS
=
"alpha"
REDIRECTOR_DIR
=
"/
home/enk/var/lib
/redirector"
# /home/enk
REDIRECTOR_DIR
=
"/
root
/redirector"
# /home/enk
CONFIG_YAML
=
'/etc/redirector/config.yaml'
MAPS_DIR
=
REDIRECTOR_DIR
+
"/maps"
CONFIG_DIR
=
REDIRECTOR_DIR
+
"/location-includes"
core/redirector.py
View file @
b8b6c22b
...
...
@@ -3,11 +3,12 @@ import os
import
pyinotify
import
asyncore
from
cor
e
import
generators
from
cor
e
import
logger
from
cor
e
import
parser
from
cor
e
import
const
from
mymodul
e
import
generators
from
mymodul
e
import
logger
from
mymodul
e
import
parser
from
mymodul
e
import
const
redirector_watch
=
None
class
Redirector
:
def
__init__
(
self
,
logger
=
None
):
...
...
@@ -55,11 +56,23 @@ class RedirectorWatch:
self
.
logger
=
logger
.
Logger
(
"redirector-watch.log"
)
self
.
redirector
=
Redirector
()
self
.
parser
=
parser
.
ConfigReader
(
logger
=
self
.
logger
)
self
.
mask
=
pyinotify
.
IN_MODIFY
|
pyinotify
.
IN_DELETE
self
.
w
atch_manager
=
pyinotify
.
WatchManager
()
self
.
n
otifier
=
None
self
.
mask
=
pyinotify
.
IN_MODIFY
self
.
w
m_pool
=
[]
self
.
n
_pool
=
[]
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
)
# creating class Watch with custom static 'yaml_file' argument
def
create_watch_class
(
self
,
yaml_file
):
class
Watch
(
pyinotify
.
ProcessEvent
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
self
.
redirector
=
kwargs
.
pop
(
"redirector"
)
...
...
@@ -67,13 +80,27 @@ class RedirectorWatch:
def
process_IN_MODIFY
(
self
,
event
):
self
.
redirector
.
generate
(
yaml_file
,
event
.
pathname
)
self
.
notifier
=
pyinotify
.
AsyncNotifier
(
self
.
watch_manager
,
Watch
(
redirector
=
self
.
redirector
))
file_list
=
self
.
parser
.
parse_yaml
(
yaml_file
)
return
Watch
# we suggest that self.watch_manager already exists
def
set_inotify
(
self
,
yaml_file
,
Watch_class
):
wm
=
pyinotify
.
WatchManager
()
self
.
add_files
(
yaml_file
,
wm
)
self
.
wm_pool
.
append
(
wm
)
notifier
=
pyinotify
.
ThreadedNotifier
(
wm
,
Watch_class
(
redirector
=
self
.
redirector
))
notifier
.
start
()
self
.
n_pool
.
append
(
notifier
)
def
add_files
(
self
,
file_
,
wm
):
file_list
=
self
.
parser
.
parse_yaml
(
file_
)
for
map_path
,
_
in
file_list
:
cwd
=
os
.
getcwd
()
wdd
=
self
.
watch_manager
.
add_watch
(
cwd
+
"/"
+
map_path
,
self
.
mask
,
rec
=
True
)
asyncore
.
loop
()
wdd
=
wm
.
add_watch
(
cwd
+
"/"
+
map_path
,
self
.
mask
,
rec
=
True
)
class
RedirectorWatchException
(
Exception
):
def
__init__
(
self
,
message
,
errors
):
super
()
.
__init__
(
message
)
self
.
errors
=
errors
def
main
(
args
=
None
):
...
...
@@ -87,8 +114,9 @@ def main(args=None):
def
watch
(
args
=
None
):
global
redirector_watch
if
not
redirector_watch
:
redirector_watch
=
RedirectorWatch
()
if
not
args
:
args
=
sys
.
argv
[
1
:]
print
(
args
)
watch_
=
RedirectorWatch
()
watch_
.
watch
(
args
)
redirector_watch
.
watch
(
args
)
setup.py
View file @
b8b6c22b
import
os
import
shutil
from
distutils.core
import
setup
from
distutils.command.install
import
install
# from distutils import log
from
setuptools
import
setup
,
find_packages
from
core
import
const
#####
data_files_list
=
[
[
'/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"
,
...
...
@@ -30,40 +17,17 @@ classifiers_list = [
}[
const
.
VERSION_STATUS
]
]
"""
add readme
add requirements.txt
config
"""
# Private classes #
class
RedirectorInstall
(
install
):
def
run
(
self
):
install
.
run
(
self
)
# Main #
setup
(
name
=
const
.
NAME
,
version
=
const
.
VERSION
,
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"
,
packages
=
None
,
data_files
=
data_files_list
,
requires
=
[
"pyyaml"
,
"pyinotify"
],
cmdclass
=
{
"install"
:
RedirectorInstall
},
version
=
"0.1"
,
packages
=
find_packages
(),
entry_points
=
{
'console_scripts'
:
[
'redirector = core.redirector:main'
,
'redirector-watch = core.redirector:watch'
]
},
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