From b15104b1d3577666f571d1c8066f6b26b317d5fd Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sat, 27 Mar 2021 03:06:08 +0300 Subject: cgit-repos.conf: path to my_repos.py can be relative --- cgit/repos/main.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'cgit') diff --git a/cgit/repos/main.py b/cgit/repos/main.py index a1b5bae..c8af42f 100644 --- a/cgit/repos/main.py +++ b/cgit/repos/main.py @@ -13,6 +13,7 @@ import sys from cgit.repos.cgit import CGit, Output from cgit.repos.repo import BitbucketRepo, GithubRepo, Repo +import cgit.repos.utils as utils DEFAULT_OUTPUT_DIR = '/var/tmp/cgit-repos/output' @@ -49,12 +50,19 @@ def parse_args(argv=None): class Config: @staticmethod def read(path): - config = configparser.ConfigParser() - config.read(path) - return Config(config) + return Config(path) - def __init__(self, impl): - self.impl = impl + def __init__(self, path): + self.path = os.path.abspath(path) + self.impl = configparser.ConfigParser() + self.impl.read(path) + + def _resolve_relative(self, path): + if os.path.isabs(path): + return path + with utils.chdir(os.path.dirname(self.path)): + path = os.path.abspath(path) + return path @property def output(self): @@ -83,7 +91,8 @@ class Config: @property def my_repos(self): - return self.impl.get('DEFAULT', 'my_repos', fallback=DEFAULT_MY_REPOS_PATH) + path = self.impl.get('DEFAULT', 'my_repos', fallback=DEFAULT_MY_REPOS_PATH) + return self._resolve_relative(path) def import_my_repos(self): sys.path.append(os.path.dirname(self.my_repos)) -- cgit v1.2.3