From 34685704033b66f0afc5908efb51eb575a4d14ff Mon Sep 17 00:00:00 2001 From: ldericher Date: Thu, 20 Aug 2020 12:30:06 +0200 Subject: [PATCH] load from directory --- src/kiwi/config.py | 16 +++++++--------- src/kiwi/projects.py | 4 ++-- src/kiwi/subcommands/conf.py | 2 +- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/kiwi/config.py b/src/kiwi/config.py index 84cc462..ac56457 100644 --- a/src/kiwi/config.py +++ b/src/kiwi/config.py @@ -113,20 +113,18 @@ class LoadedConfig(Config): __instances = {} @classmethod - def get(cls): - cwd = os.getcwd() - - if cwd not in LoadedConfig.__instances: + def get(cls, directory='.'): + if directory not in LoadedConfig.__instances: # create singleton for new path result = DefaultConfig.get() - # update with current dir's kiwi.yml + # update with that dir's kiwi.yml try: - result = result._update_from_file(KIWI_CONF_NAME) + result = result._update_from_file(os.path.join(directory, KIWI_CONF_NAME)) except FileNotFoundError: - logging.info(f"No '{KIWI_CONF_NAME}' found at '{cwd}'. Using defaults.") + logging.info(f"No '{KIWI_CONF_NAME}' found at '{directory}'. Using defaults.") - LoadedConfig.__instances[cwd] = result + LoadedConfig.__instances[directory] = result # return singleton - return LoadedConfig.__instances[cwd] + return LoadedConfig.__instances[directory] diff --git a/src/kiwi/projects.py b/src/kiwi/projects.py index 4459363..65c75d0 100644 --- a/src/kiwi/projects.py +++ b/src/kiwi/projects.py @@ -35,10 +35,10 @@ class Projects: return result @classmethod - def from_dir(cls): + def from_dir(cls, directory='.'): return cls.from_projects([ Project.from_file_name(file_name) - for file_name in os.listdir() + for file_name in os.listdir(directory) ]) @classmethod diff --git a/src/kiwi/subcommands/conf.py b/src/kiwi/subcommands/conf.py index 86a379e..bfbd933 100644 --- a/src/kiwi/subcommands/conf.py +++ b/src/kiwi/subcommands/conf.py @@ -73,7 +73,7 @@ class ConfCleanCommand(SubCommand): result = True affected_projects = [ - project.conf_dir_name() + project.get_name() for project in Projects.from_dir() if project.has_configs() ]