mirror of
https://github.com/yavook/kiwi-scp.git
synced 2024-11-22 04:43:00 +00:00
load from directory
This commit is contained in:
parent
d99f26e3cf
commit
3468570403
3 changed files with 10 additions and 12 deletions
|
@ -113,20 +113,18 @@ class LoadedConfig(Config):
|
||||||
__instances = {}
|
__instances = {}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get(cls):
|
def get(cls, directory='.'):
|
||||||
cwd = os.getcwd()
|
if directory not in LoadedConfig.__instances:
|
||||||
|
|
||||||
if cwd not in LoadedConfig.__instances:
|
|
||||||
# create singleton for new path
|
# create singleton for new path
|
||||||
result = DefaultConfig.get()
|
result = DefaultConfig.get()
|
||||||
|
|
||||||
# update with current dir's kiwi.yml
|
# update with that dir's kiwi.yml
|
||||||
try:
|
try:
|
||||||
result = result._update_from_file(KIWI_CONF_NAME)
|
result = result._update_from_file(os.path.join(directory, KIWI_CONF_NAME))
|
||||||
except FileNotFoundError:
|
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 singleton
|
||||||
return LoadedConfig.__instances[cwd]
|
return LoadedConfig.__instances[directory]
|
||||||
|
|
|
@ -35,10 +35,10 @@ class Projects:
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_dir(cls):
|
def from_dir(cls, directory='.'):
|
||||||
return cls.from_projects([
|
return cls.from_projects([
|
||||||
Project.from_file_name(file_name)
|
Project.from_file_name(file_name)
|
||||||
for file_name in os.listdir()
|
for file_name in os.listdir(directory)
|
||||||
])
|
])
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
|
@ -73,7 +73,7 @@ class ConfCleanCommand(SubCommand):
|
||||||
result = True
|
result = True
|
||||||
|
|
||||||
affected_projects = [
|
affected_projects = [
|
||||||
project.conf_dir_name()
|
project.get_name()
|
||||||
for project in Projects.from_dir()
|
for project in Projects.from_dir()
|
||||||
if project.has_configs()
|
if project.has_configs()
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in a new issue