From 50e12f3df208637adc6bbe2017665dcc60e448a5 Mon Sep 17 00:00:00 2001 From: Jonas Gunz Date: Wed, 1 Jun 2022 18:48:02 +0200 Subject: Allow omission of include and exclude set default options for include and exclude --- rss_to_gitea/config.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/rss_to_gitea/config.py b/rss_to_gitea/config.py index faf3350..96f9ef9 100644 --- a/rss_to_gitea/config.py +++ b/rss_to_gitea/config.py @@ -27,6 +27,16 @@ STRUCTURE_DICT_LIST={ } } +DEFAULTS_DICT_LIST={ + 'feeds': { + 'url':None, + 'name':None, + 'assign':None, + 'exclude': [], + 'include': [] + } +} + class ConfigError(Exception): @@ -61,6 +71,7 @@ class Config: with open(_file, 'r') as f: self.config = yaml.load(f.read(), Loader=yaml.FullLoader) + self._populate_defaults() self._validate() def __iter__(self): @@ -84,6 +95,14 @@ class Config: elif type(_dict[e]) is not _spec[e]: raise ConfigError(f'{_context}Key {e} is {type(_dict[e])}. Should be {_spec[e]}') + def _populate_defaults(self): + # this is a holy mess. It works. And at time of writing made sense. + for lst in DEFAULTS_DICT_LIST: + for entry in range(len(self.config[lst])): + for default in DEFAULTS_DICT_LIST[lst]: + if not default in self.config[lst][entry]: + self.config[lst][entry][default] = DEFAULTS_DICT_LIST[lst][default] + def _validate(self): Config._validate_dict(self.config, STRUCTURE) -- cgit v1.2.3