1
0
Fork 0
mirror of https://github.com/yavook/kiwi-scp.git synced 2024-12-25 18:42:59 +00:00

load from directory

This commit is contained in:
Jörn-Michael Miehe 2020-08-20 12:30:06 +02:00
parent d99f26e3cf
commit 3468570403
3 changed files with 10 additions and 12 deletions

View file

@ -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]

View file

@ -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

View file

@ -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()
]