Fix map path for any paths

parent 404580b9
...@@ -106,11 +106,14 @@ class ConfigReader: ...@@ -106,11 +106,14 @@ class ConfigReader:
res_prefix = None res_prefix = None
# normalize path # 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: try:
for map_path, prefix in self.parse_yaml(yaml_file): 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 res_prefix = prefix.split("/")[-1] # Last directory of map_path a project's name
with open(abs_map_path, "r") as file: with open(abs_map_path, "r") as file:
for i, line in enumerate(file): for i, line in enumerate(file):
......
...@@ -8,6 +8,7 @@ import generators ...@@ -8,6 +8,7 @@ import generators
import logger import logger
import parser import parser
import const import const
from redirector import Redirector
redirector_watch = None redirector_watch = None
...@@ -26,6 +27,7 @@ class RedirectorWatch: ...@@ -26,6 +27,7 @@ class RedirectorWatch:
raise self.RedirectorWatchException("yaml_file list is empty", Exception) raise self.RedirectorWatchException("yaml_file list is empty", Exception)
Watch = self.create_watch_class(yaml_file) Watch = self.create_watch_class(yaml_file)
for map_path, _ in self.parser.parse_yaml(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) self.redirector.generate(yaml_file, map_path)
try: try:
self.set_inotify(yaml_file, Watch) self.set_inotify(yaml_file, Watch)
...@@ -62,8 +64,8 @@ class RedirectorWatch: ...@@ -62,8 +64,8 @@ class RedirectorWatch:
def add_files(self, file_, wm): def add_files(self, file_, wm):
file_list = self.parser.parse_yaml(file_) file_list = self.parser.parse_yaml(file_)
for map_path, _ in file_list: for map_path, _ in file_list:
cwd = os.getcwd() abs_map_path = os.path.abspath(map_path)
wdd = wm.add_watch(cwd + "/" + map_path, self.mask, rec=True) wdd = wm.add_watch(abs_map_path, self.mask, rec=True)
class RedirectorWatchException(Exception): class RedirectorWatchException(Exception):
def __init__(self, message, errors): def __init__(self, message, errors):
......
# comment # comment
/some-page /another-page /some-page /another-page
...@@ -13,4 +12,4 @@ ...@@ -13,4 +12,4 @@
/some-page //other-project/some-page /some-page //other-project/some-page
# absolute redirect # absolute redirect
/special-project https://github.com/etersoft/special-project /special-project https://github.com/etersoft/special-project
\ No newline at end of file
projects: projects:
- map: tests/test.map - map: /home/kantegory/pvt/nginx-redirector/tests/test.map
prefix: /test 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