aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2022-06-01 18:48:02 +0200
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2022-06-01 18:48:02 +0200
commit50e12f3df208637adc6bbe2017665dcc60e448a5 (patch)
tree19fe83ec40da56911cc3259201531a1b5d52b1ed
parent85c9adaef0b343153e825fbbd6e52d1653428949 (diff)
downloadatom_to_gitea-50e12f3df208637adc6bbe2017665dcc60e448a5.tar.gz
Allow omission of include and exclude
set default options for include and exclude
-rw-r--r--rss_to_gitea/config.py19
1 files changed, 19 insertions, 0 deletions
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)