diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2021-03-27 03:06:08 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2021-03-27 03:21:58 +0300 |
commit | b15104b1d3577666f571d1c8066f6b26b317d5fd (patch) | |
tree | f280d00bee10c46cf87e5476090d9ef246c1a51e | |
parent | minor refactoring (diff) | |
download | cgitize-b15104b1d3577666f571d1c8066f6b26b317d5fd.tar.gz cgitize-b15104b1d3577666f571d1c8066f6b26b317d5fd.zip |
cgit-repos.conf: path to my_repos.py can be relative
-rwxr-xr-x | .ci/local/test.sh | 2 | ||||
-rw-r--r-- | cgit/repos/main.py | 21 |
2 files changed, 16 insertions, 7 deletions
diff --git a/.ci/local/test.sh b/.ci/local/test.sh index 2045e1e..7f1a958 100755 --- a/.ci/local/test.sh +++ b/.ci/local/test.sh @@ -40,7 +40,7 @@ setup_cgit_repos_conf() { cat <<EOF | tee "$cgit_repos_conf_path" [DEFAULT] -my_repos = $my_repos_path +my_repos = $( basename -- "$my_repos_path" ) output = $output_path EOF } 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)) |