mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-07-14 14:35:47 +00:00
remove own implementations of getlist and getpath method in order to use
converters feature
This commit is contained in:
@ -92,7 +92,8 @@ class Handler:
|
||||
|
||||
config = Configuration()
|
||||
config.load(args.configuration)
|
||||
root = config.getpath("repository", "root")
|
||||
# wtf???
|
||||
root = config.getpath("repository", "root") # pylint: disable=assignment-from-no-return
|
||||
architectures = RepositoryPaths.known_architectures(root)
|
||||
|
||||
if not architectures:
|
||||
|
@ -52,9 +52,9 @@ class Auth:
|
||||
self.logger = logging.getLogger("http")
|
||||
|
||||
self.allow_read_only = configuration.getboolean("auth", "allow_read_only")
|
||||
self.allowed_paths = set(configuration.getlist("auth", "allowed_paths"))
|
||||
self.allowed_paths = set(configuration.getlist("auth", "allowed_paths", fallback=[]))
|
||||
self.allowed_paths.update(self.ALLOWED_PATHS)
|
||||
self.allowed_paths_groups = set(configuration.getlist("auth", "allowed_paths_groups"))
|
||||
self.allowed_paths_groups = set(configuration.getlist("auth", "allowed_paths_groups", fallback=[]))
|
||||
self.allowed_paths_groups.update(self.ALLOWED_PATHS_GROUPS)
|
||||
self.enabled = provider.is_enabled
|
||||
self.max_age = configuration.getint("auth", "max_age", fallback=7 * 24 * 3600)
|
||||
|
@ -53,10 +53,10 @@ class Task:
|
||||
self.package = package
|
||||
self.paths = paths
|
||||
|
||||
self.archbuild_flags = configuration.getlist("build", "archbuild_flags")
|
||||
self.archbuild_flags = configuration.getlist("build", "archbuild_flags", fallback=[])
|
||||
self.build_command = configuration.get("build", "build_command")
|
||||
self.makepkg_flags = configuration.getlist("build", "makepkg_flags")
|
||||
self.makechrootpkg_flags = configuration.getlist("build", "makechrootpkg_flags")
|
||||
self.makepkg_flags = configuration.getlist("build", "makepkg_flags", fallback=[])
|
||||
self.makechrootpkg_flags = configuration.getlist("build", "makechrootpkg_flags", fallback=[])
|
||||
|
||||
@property
|
||||
def cache_path(self) -> Path:
|
||||
|
@ -41,13 +41,14 @@ class Configuration(configparser.RawConfigParser):
|
||||
|
||||
ARCHITECTURE_SPECIFIC_SECTIONS = ["build", "html", "rsync", "s3", "sign", "web"]
|
||||
|
||||
_UNSET = object()
|
||||
|
||||
def __init__(self) -> None:
|
||||
"""
|
||||
default constructor. In the most cases must not be called directly
|
||||
"""
|
||||
configparser.RawConfigParser.__init__(self, allow_no_value=True)
|
||||
configparser.RawConfigParser.__init__(self, allow_no_value=True, converters={
|
||||
"list": lambda value: value.split(),
|
||||
"path": self.__convert_path,
|
||||
})
|
||||
self.path: Optional[Path] = None
|
||||
|
||||
@property
|
||||
@ -89,6 +90,17 @@ class Configuration(configparser.RawConfigParser):
|
||||
"""
|
||||
return f"{section}:{suffix}"
|
||||
|
||||
def __convert_path(self, parsed: str) -> Path:
|
||||
"""
|
||||
convert string value to path object
|
||||
:param parsed: string configuration value
|
||||
:return: path object which represents the configuration value
|
||||
"""
|
||||
value = Path(parsed)
|
||||
if self.path is None or value.is_absolute():
|
||||
return value
|
||||
return self.path.parent / value
|
||||
|
||||
def dump(self) -> Dict[str, Dict[str, str]]:
|
||||
"""
|
||||
dump configuration to dictionary
|
||||
@ -99,35 +111,11 @@ class Configuration(configparser.RawConfigParser):
|
||||
for section in self.sections()
|
||||
}
|
||||
|
||||
def getlist(self, section: str, key: str) -> List[str]:
|
||||
"""
|
||||
get space separated string list option
|
||||
:param section: section name
|
||||
:param key: key name
|
||||
:return: list of string if option is set, empty list otherwise
|
||||
"""
|
||||
raw = self.get(section, key, fallback=None)
|
||||
if not raw: # empty string or none
|
||||
return []
|
||||
return raw.split()
|
||||
# pylint and mypy are too stupid to find these methods
|
||||
# pylint: disable=missing-function-docstring,multiple-statements,unused-argument,no-self-use
|
||||
def getlist(self, *args: Any, **kwargs: Any) -> List[str]: ...
|
||||
|
||||
def getpath(self, section: str, key: str, fallback: Any = _UNSET) -> Path:
|
||||
"""
|
||||
helper to generate absolute configuration path for relative settings value
|
||||
:param section: section name
|
||||
:param key: key name
|
||||
:param fallback: optional fallback value
|
||||
:return: absolute path according to current path configuration
|
||||
"""
|
||||
try:
|
||||
value = Path(self.get(section, key))
|
||||
except (configparser.NoOptionError, configparser.NoSectionError):
|
||||
if fallback is self._UNSET:
|
||||
raise
|
||||
value = fallback
|
||||
if self.path is None or not isinstance(value, Path) or value.is_absolute():
|
||||
return value
|
||||
return self.path.parent / value
|
||||
def getpath(self, *args: Any, **kwargs: Any) -> Path: ...
|
||||
|
||||
def load(self, path: Path) -> None:
|
||||
"""
|
||||
|
@ -60,7 +60,7 @@ class Properties:
|
||||
self.paths = RepositoryPaths(configuration.getpath("repository", "root"), architecture)
|
||||
self.paths.create_tree()
|
||||
|
||||
self.ignore_list = configuration.getlist("build", "ignore_packages")
|
||||
self.ignore_list = configuration.getlist("build", "ignore_packages", fallback=[])
|
||||
self.pacman = Pacman(configuration)
|
||||
self.sign = GPG(architecture, configuration)
|
||||
self.repo = Repo(self.name, self.paths, self.sign.repository_sign_args)
|
||||
|
Reference in New Issue
Block a user