Fix map path for any paths

parent 404580b9
......@@ -106,11 +106,14 @@ class ConfigReader:
res_prefix = None
# normalize path
abs_map_path = os.path.abspath(os.path.realpath(map_file))
yaml_dir = os.path.dirname(os.path.abspath(yaml_file))
map_file_name = os.path.split(map_file)[-1] # get tail of map path from arg
try:
for map_path, prefix in self.parse_yaml(yaml_file):
if map_path in abs_map_path:
rel_map_path = os.path.relpath(map_path, start=yaml_dir)
abs_map_path = "{}/{}".format(yaml_dir, rel_map_path)
if map_file_name in abs_map_path:
res_prefix = prefix.split("/")[-1] # Last directory of map_path a project's name
with open(abs_map_path, "r") as file:
for i, line in enumerate(file):
......
......@@ -8,6 +8,7 @@ import generators
import logger
import parser
import const
from redirector import Redirector
redirector_watch = None
......@@ -26,6 +27,7 @@ class RedirectorWatch:
raise self.RedirectorWatchException("yaml_file list is empty", Exception)
Watch = self.create_watch_class(yaml_file)
for map_path, _ in self.parser.parse_yaml(yaml_file):
print('is error here', map_path)
self.redirector.generate(yaml_file, map_path)
try:
self.set_inotify(yaml_file, Watch)
......@@ -62,8 +64,8 @@ class RedirectorWatch:
def add_files(self, file_, wm):
file_list = self.parser.parse_yaml(file_)
for map_path, _ in file_list:
cwd = os.getcwd()
wdd = wm.add_watch(cwd + "/" + map_path, self.mask, rec=True)
abs_map_path = os.path.abspath(map_path)
wdd = wm.add_watch(abs_map_path, self.mask, rec=True)
class RedirectorWatchException(Exception):
def __init__(self, message, errors):
......
# comment
/some-page /another-page
......
projects:
- map: tests/test.map
- map: /home/kantegory/pvt/nginx-redirector/tests/test.map
prefix: /test
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