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
a62218c4
Commit
a62218c4
authored
Jul 10, 2019
by
Никита Ефремов
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed files generation and fixed bugs for testing
parent
b8285f03
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
17 deletions
+23
-17
const.py
dev/const.py
+3
-3
generators.py
dev/generators.py
+19
-13
setup.py
setup.py
+1
-1
No files found.
dev/const.py
View file @
a62218c4
...
...
@@ -5,7 +5,7 @@ EMAIL = "enk@etersoft.ru"
PYTHON_VERSION
=
"3.6"
VERSION_STATUS
=
"alpha"
REDIRECTOR_DIR
=
"/root/redirector
"
# /home/enk
NGINX_DIR
=
"/etc/nginx
"
# /home/enk
CONFIG_YAML
=
'/etc/redirector/config.yaml'
MAPS_DIR
=
REDIRECTOR
_DIR
+
"/maps"
CONFIG_DIR
=
REDIRECTOR
_DIR
+
"/location-includes"
MAPS_DIR
=
NGINX
_DIR
+
"/maps"
CONFIG_DIR
=
NGINX
_DIR
+
"/location-includes"
dev/generators.py
View file @
a62218c4
class
MapGenerator
:
def
__init__
(
self
):
self
.
start_lines
=
[
"map $uri $
%
s-redirect {"
,
"
\n
map $uri $
%
s-option-redirect {"
,
"
\n
map $uri $
%
s-option {"
]
self
.
start_line
=
"map $uri $
%
s_redirect {"
self
.
codes_dict
=
{
'301'
:
"permanent"
,
'302'
:
'redirect'
}
self
.
endline
=
"
\n
}"
def
generate_map
(
self
,
redirects_sorted
,
project_name
):
data
=
""
for
i
,
map_type
in
enumerate
(
self
.
start_lines
):
data
+=
map_type
%
project_name
for
arg1
,
arg2
in
redirects_sorted
[
i
]:
data
+=
"
\n\t
%
s
\t
%
s;"
%
(
arg1
,
arg2
)
data
+=
self
.
endline
data
=
self
.
start_line
%
project_name
for
arg1
,
arg2
in
redirects_sorted
[
0
]:
data
+=
"
\n\t
%
s
\t
%
s;"
%
(
arg1
,
arg2
)
for
arg1
,
arg2
in
redirects_sorted
[
1
]:
data
+=
"
\n\t
%
s
\t
%
s;"
%
(
arg1
,
arg2
)
"""
for i, args in enumerate(redirects_sorted[1]):
try:
key_ = redirects_sorted[2][i]
except KeyError:
key_ = None
data = "
\n\t
%
s
\t
%
s;"
%
(args[0], args[1]) if not key_
else "
\n\t
%
s
\t
%
s
\t
%
s;"
%
(args[0], args[1], key_)
"""
data
+=
self
.
endline
return
data
class
ConfigGenerator
:
def
__init__
(
self
):
self
.
start_line
=
"if
($
%
s-
redirect) {
\n
"
self
.
rewrite_line
=
"
\t
rewrite ^/
%
s/(.^)$ $
%
s
-
redirect redirect;
\n
}"
self
.
start_line
=
"if
($
%
s_
redirect) {
\n
"
self
.
rewrite_line
=
"
\t
rewrite ^/
%
s/(.^)$ $
%
s
_
redirect redirect;
\n
}"
def
generate_conf
(
self
,
project_name
):
return
(
self
.
start_line
%
project_name
)
+
(
self
.
rewrite_line
%
(
project_name
,
project_name
))
...
...
setup.py
View file @
a62218c4
import
os
from
setuptools
import
setup
,
find_packages
from
core
import
const
from
dev
import
const
classifiers_list
=
[
"Development Status :: 4 - Beta"
,
...
...
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