From 71687a7e646907c1c77137ceb1294bf18ec7307f Mon Sep 17 00:00:00 2001 From: William Coe Date: Fri, 8 May 2020 09:31:12 +1000 Subject: [PATCH] config: support configuration via Python dict When using the mirror tool as a library it is convenient to configure it via a dict. --- rpm_s3_mirror/config.py | 9 +++++++++ rpm_s3_mirror/mirror.py | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/rpm_s3_mirror/config.py b/rpm_s3_mirror/config.py index b4e9b51..ad25310 100644 --- a/rpm_s3_mirror/config.py +++ b/rpm_s3_mirror/config.py @@ -78,3 +78,12 @@ def __init__(self, path): def _populate_required(self): with open(self.path) as f: self._config.update(json.load(f)) + + +class DictConfig(Config): + def __init__(self, config_dict): + self._config.update(config_dict) + super().__init__() + + def _populate_required(self): + pass diff --git a/rpm_s3_mirror/mirror.py b/rpm_s3_mirror/mirror.py index 20fe9a8..1b454b5 100644 --- a/rpm_s3_mirror/mirror.py +++ b/rpm_s3_mirror/mirror.py @@ -35,7 +35,7 @@ def __init__(self, config): ) self.repositories = [RPMRepository(base_url=url) for url in config.upstream_repositories] - def sync(self, bootstrap): + def sync(self, bootstrap=False): start = time.monotonic() for upstream_repository in self.repositories: mirror_start = time.monotonic()