[fix] Fix prefix writing in project redirects

parent be19fe65
...@@ -39,9 +39,7 @@ class HtaccessReader: ...@@ -39,9 +39,7 @@ class HtaccessReader:
f = open(abs_path, 'r', encoding='UTF-8') f = open(abs_path, 'r', encoding='UTF-8')
for line in f: for line in f:
print('line is', line) if len(line) > 2 and not line.startswith('#') and '#' not in line:
if len(line) > 2 and not line.startswith('#'):
res.append('\n') res.append('\n')
res.append('# {}'.format(line)) # for tests res.append('# {}'.format(line)) # for tests
res.append(self.line_parser.parse_line(line)) res.append(self.line_parser.parse_line(line))
......
import os import os
NAME = "nginx-redirector" NAME = "nginx-redirector"
VERSION = "1.0.0" VERSION = "0.1.2"
AUTHOR = "Nikita Yefremov, David Dobryakov" AUTHOR = "Nikita Yefremov, David Dobryakov"
EMAIL = "kantegory@etersoft.ru" EMAIL = "kantegory@etersoft.ru"
PYTHON_VERSION = "3.8.1" PYTHON_VERSION = "3.8.1"
......
...@@ -50,6 +50,7 @@ class MapGenerator: ...@@ -50,6 +50,7 @@ class MapGenerator:
def generate_map(self, redirects, project_name): def generate_map(self, redirects, project_name):
data = self.start_line % project_name data = self.start_line % project_name
for arg1, arg2 in redirects: for arg1, arg2 in redirects:
# print('redirect is', arg1, arg2)
data += "\n\t%s\t%s;" % (arg1, arg2) data += "\n\t%s\t%s;" % (arg1, arg2)
data += self.endline data += self.endline
return data return data
......
...@@ -41,23 +41,20 @@ class MapLineParser: ...@@ -41,23 +41,20 @@ class MapLineParser:
print(line[0]) print(line[0])
if line[0].startswith("~"): if line[0].startswith("~"):
line[0] = "~" + prefix + line[0][1:] line[0] = "~" + line[0][1:]
if line[0].startswith("//"): # if new URI relative to the root if line[0].startswith("//"): # if new URI relative to the root
line[0] = line[0][1:] # cutting out extra '/' at the beginning line[0] = line[0][1:] # cutting out extra '/' at the beginning
line[1] = prefix + line[1]
elif line[1].startswith("//"): elif line[1].startswith("//"):
line[1] = line[1][1:] line[1] = line[1][1:]
line[0] = prefix + line[0] if not line[0].startswith("~") else line[0] line[0] = line[0]
elif self.url_absolute.fullmatch(line[1]): elif self.url_absolute.fullmatch(line[1]):
line[0] = prefix + line[0]
options = ['301'] options = ['301']
return_code = 1 return_code = 1
else: # default url else: # default url
line[0] = prefix + line[0] if not line[0].startswith("~") else line[0] line[0] = line[0] if not line[0].startswith("~") else line[0]
line[1] = prefix + line[1]
return return_code, line[0], line[1], options return return_code, line[0], line[1], options
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment