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
aa3d7f3f
Commit
aa3d7f3f
authored
Jul 14, 2020
by
Давид Добряков
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate from const.py to config.ini
parent
a927f491
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
28 additions
and
22 deletions
+28
-22
.gitignore
.gitignore
+1
-1
MANIFEST.in
MANIFEST.in
+2
-0
Makefile
Makefile
+1
-1
__init__.py
redirector/conf/__init__.py
+2
-0
config.ini
redirector/conf/config.ini
+2
-2
config.py
redirector/conf/config.py
+5
-3
redirector.py
redirector/redirector.py
+3
-3
const.py
redirector/utils/const.py
+0
-4
generators.py
redirector/utils/generators.py
+8
-5
watcher.py
redirector/watcher.py
+1
-1
setup.py
setup.py
+3
-2
No files found.
.gitignore
View file @
aa3d7f3f
...
...
@@ -6,4 +6,4 @@ dist/
nginx_redirector.egg-info/
build/
*.log
*.pyc
MANIFEST.in
0 → 100644
View file @
aa3d7f3f
include redirector/conf/config.ini
Makefile
View file @
aa3d7f3f
reinstall
:
pip uninstall nginx-redirector
-y
&&
python setup.py
install
pip uninstall nginx-redirector
-y
&&
python setup.py
install
&&
redirector-config
--edit
nginx_dir /home/kantegory/pvt/redirector-tests
redirector/conf/__init__.py
0 → 100644
View file @
aa3d7f3f
#!/usr/bin/env python
# -*- coding: utf-8 -*-
redirector/conf/config.ini
View file @
aa3d7f3f
[DEFAULT]
nginx_dir
=
/etc/nginx
maps_dir
=
$
(nginx_dir)s/maps
config_dir
=
$(nginx_dir)s/location_
includes
maps_dir
=
%
(nginx_dir)s/maps
config_dir
=
%(nginx_dir)s/location-
includes
redirector/conf/config.py
View file @
aa3d7f3f
import
configparser
import
argparse
as
ap
import
os
class
Config
:
def
__init__
(
self
):
self
.
config
=
configparser
.
ConfigParser
()
self
.
filename
=
'
config.ini'
self
.
filename
=
'
{}/config.ini'
.
format
(
os
.
path
.
dirname
(
__file__
))
def
read_config
(
self
,
filename
=
'config.ini'
):
self
.
filename
=
filename
def
read_config
(
self
,
filename
=
None
):
if
filename
:
self
.
filename
=
filename
self
.
config
.
read
(
self
.
filename
)
def
get_default_dir
(
self
,
dir_key
):
...
...
redirector/redirector.py
View file @
aa3d7f3f
...
...
@@ -7,7 +7,7 @@ import argparse as ap
from
redirector.utils
import
generators
from
redirector.utils
import
logger
from
redirector.utils
import
parser
from
redirector.utils
import
const
class
Redirector
:
def
__init__
(
self
,
logger
=
None
):
...
...
@@ -51,6 +51,6 @@ def main(args=None):
print
(
"CRITICAL:
\n
"
+
str
(
e
))
#
if __name__ == "__main__":
#
main()
if
__name__
==
"__main__"
:
main
()
redirector/utils/const.py
View file @
aa3d7f3f
...
...
@@ -5,7 +5,3 @@ EMAIL = "enk@etersoft.ru"
PYTHON_VERSION
=
"3.6"
VERSION_STATUS
=
"alpha"
NGINX_DIR
=
"/home/kantegory/pvt/redirector-tests"
#"/etc/nginx" # /home/enk
CONFIG_YAML
=
"/home/kantegory/pvt/nginx-redirector/config.yaml"
MAPS_DIR
=
NGINX_DIR
+
"/maps"
CONFIG_DIR
=
NGINX_DIR
+
"/location-includes"
redirector/utils/generators.py
View file @
aa3d7f3f
from
redirector.
utils
import
const
from
redirector.
conf.config
import
Config
class
Generator
:
def
__init__
(
self
):
...
...
@@ -9,17 +9,20 @@ class Generator:
redirects_map
=
self
.
map_gen
.
generate_map
(
redirects_data
[
0
],
project_name
)
redirects_with_options
=
self
.
map_gen
.
generate_opt_map
(
redirects_data
[
1
],
project_name
)
conf_data
=
self
.
conf_gen
.
generate_config
(
project_name
,
[
code
for
code
,
data
in
redirects_with_options
])
config
=
Config
()
config
.
read_config
()
try
:
with
open
(
con
st
.
MAPS_DIR
+
"/
%
s.map"
%
project_name
,
"w"
)
as
map_file
:
with
open
(
con
fig
.
get_default_dir
(
'MAPS_DIR'
)
+
"/
%
s.map"
%
project_name
,
"w"
)
as
map_file
:
map_file
.
write
(
redirects_map
)
for
code
,
data
in
redirects_with_options
:
if
code
==
"301"
:
code
=
"permanent"
elif
code
==
"302"
:
code
=
"redirect"
with
open
(
con
st
.
MAPS_DIR
+
"/
%
s_
%
s_options.map"
%
(
project_name
,
code
),
"w"
)
as
map_file
:
with
open
(
con
fig
.
get_default_dir
(
'MAPS_DIR'
)
+
"/
%
s_
%
s_options.map"
%
(
project_name
,
code
),
"w"
)
as
map_file
:
map_file
.
write
(
data
)
with
open
(
con
st
.
CONFIG_DIR
+
"/
%
s.conf"
%
project_name
,
"w"
)
as
conf_file
:
with
open
(
con
fig
.
get_default_dir
(
'CONFIG_DIR'
)
+
"/
%
s.conf"
%
project_name
,
"w"
)
as
conf_file
:
conf_file
.
write
(
conf_data
)
except
Exception
as
e
:
print
(
e
)
...
...
@@ -83,4 +86,4 @@ class ConfigGenerator:
data
+=
(
self
.
opt_start_line
%
(
project_name
,
code
))
+
(
self
.
opt_rewrite_line
%
(
project_name
,
project_name
,
code
,
"break"
))
+
(
self
.
option_line
%
code
)
return
data
redirector/watcher.py
View file @
aa3d7f3f
...
...
@@ -7,7 +7,7 @@ import argparse as ap
from
redirector.utils
import
generators
from
redirector.utils
import
logger
from
redirector.utils
import
parser
from
redirector.utils
import
const
from
redirector.redirector
import
Redirector
...
...
setup.py
View file @
aa3d7f3f
...
...
@@ -21,12 +21,13 @@ classifiers_list = [
setup
(
name
=
const
.
NAME
,
version
=
"0.1.1"
,
packages
=
[
'redirector'
,
'redirector.utils'
,
'redirector.tests'
],
packages
=
[
'redirector'
,
'redirector.utils'
,
'redirector.tests'
,
'redirector.conf'
],
entry_points
=
{
'console_scripts'
:
[
'redirector = redirector.redirector:main'
,
'redirector-watch = redirector.watcher:watch'
,
'redirector-convert = redirector.htaccess_parser:main'
'redirector-convert = redirector.htaccess_parser:main'
,
'redirector-config = redirector.conf.config:main'
]
},
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