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
b8285f03
Commit
b8285f03
authored
Jul 09, 2019
by
Никита Ефремов
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed the name of core directory, added files generation on start of redirector-watch
parent
623eae9a
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
35 additions
and
21 deletions
+35
-21
__init__.py
dev/__init__.py
+0
-0
const.py
dev/const.py
+0
-0
generators.py
dev/generators.py
+0
-0
logger.py
dev/logger.py
+0
-0
parser.py
dev/parser.py
+0
-0
redirector.py
dev/redirector.py
+33
-19
setup.py
setup.py
+2
-2
No files found.
core
/__init__.py
→
dev
/__init__.py
View file @
b8285f03
File moved
core
/const.py
→
dev
/const.py
View file @
b8285f03
File moved
core
/generators.py
→
dev
/generators.py
View file @
b8285f03
File moved
core
/logger.py
→
dev
/logger.py
View file @
b8285f03
File moved
core
/parser.py
→
dev
/parser.py
View file @
b8285f03
File moved
core
/redirector.py
→
dev
/redirector.py
View file @
b8285f03
...
...
@@ -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
(
y
file
,
Watch
)
except
pyinotify
.
PyinotifyError
as
e
:
raise
self
.
RedirectorWatchException
(
"Can
\'
t set inotify for yamll file
%
s"
%
y
file
,
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
])
setup.py
View file @
b8285f03
...
...
@@ -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
...
...
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