repo-cloner/repo_cloner/lib/cloner_config.py
Václav Valíček cb5e934c4a
ClonerConfig + tests
Signed-off-by: Václav Valíček <valicek1994@gmail.com>
2022-06-26 05:22:19 +02:00

43 lines
1.5 KiB
Python

from repo_cloner.lib.default_cloner_config import DefaultClonerConfig
class ClonerConfig(DefaultClonerConfig):
def __init__(self):
super().__init__()
self.__properties = list(filter(self.has_property, dir(self)))
self.__values = {}
def __try_default(self, key: str, default_value):
if not self.has_property(key):
raise KeyError(f"{key} is not recognized config option")
if key in self.__values:
return self.__values[key]
return default_value
@property
def cloner_project_name(self) -> str:
return self.__try_default("cloner_project_name", super(ClonerConfig, self).cloner_project_name)
@property
def cloner_repo_url(self) -> str:
return self.__try_default("cloner_repo_url", super(ClonerConfig, self).cloner_repo_url)
@property
def cloner_interval(self) -> int:
return self.__try_default("cloner_interval", super(ClonerConfig, self).cloner_interval)
@property
def cloner_submodules(self) -> bool:
return self.__try_default("cloner_submodules", super(ClonerConfig, self).cloner_submodules)
@property
def cloner_submodule_depth(self) -> int:
return self.__try_default("cloner_submodule_depth", super(ClonerConfig, self).cloner_submodule_depth)
def _set_property(self, key: str, value):
if not self.has_property(key):
raise KeyError(f"{key} is not recognized config option")
if not isinstance(value, type(self.__getattribute__(key))):
raise ValueError(f"Invalid value for key {key}: type is {type(value)}")
self.__values[key] = value