Update parser.py: fix path for every input params

parent 179ade80
NAME = "redirector"
NAME = "nginx-redirector"
VERSION = "1.0"
AUTHOR = "Nikita Yefremov"
EMAIL = "enk@etersoft.ru"
PYTHON_VERSION = "3.6"
VERSION_STATUS = "alpha"
NGINX_DIR = "/etc/nginx" # /home/enk
CONFIG_YAML = '/etc/redirector/config.yaml'
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"
......@@ -104,11 +104,15 @@ class ConfigReader:
def parse_map(self, map_file, yaml_file):
res = [[], {}]
res_prefix = None
# normalize path
abs_map_path = os.path.abspath(os.path.realpath(map_file))
try:
for map_path, prefix in self.parse_yaml(yaml_file):
if map_path == map_file or os.getcwd() + "/" + map_path == map_file:
if map_path in abs_map_path:
res_prefix = prefix.split("/")[-1] # Last directory of map_path a project's name
with open(map_file, "r") as file:
with open(abs_map_path, "r") as file:
for i, line in enumerate(file):
request_url, redirect_url, option = None, None, []
try:
......@@ -131,6 +135,7 @@ class ConfigReader:
else:
res[1][opt_] = [(request_url, redirect_url)]
return res, res_prefix
except YAMLError as e:
self.logger.log("Error occurred while reading %s" % yaml_file + str(e))
......
projects:
- map: tests/test.map
prefix: /test
- map: tests/test2.map
prefix: /test2
\ No newline at end of file
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