diff options
| author | 2020-06-29 00:33:22 -0400 | |
|---|---|---|
| committer | 2020-06-29 00:33:22 -0400 | |
| commit | 02dd2886783cd303cff6890a741152d013bb00ce (patch) | |
| tree | e5d4a805888147de8efe514a3c55e303230a508b /gallery_dl/config.py | |
| parent | 8c911e3d62a430f5630c13d51b47201fa8ff3cd1 (diff) | |
New upstream version 1.14.2.upstream/1.14.2
Diffstat (limited to 'gallery_dl/config.py')
| -rw-r--r-- | gallery_dl/config.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/gallery_dl/config.py b/gallery_dl/config.py index 5303616..a3c71cd 100644 --- a/gallery_dl/config.py +++ b/gallery_dl/config.py @@ -108,6 +108,38 @@ def interpolate(path, key, default=None, *, conf=_config): return default +def interpolate_common(common, paths, key, default=None, *, conf=_config): + """Interpolate the value of 'key' + using multiple 'paths' along a 'common' ancestor + """ + if key in conf: + return conf[key] + + # follow the common path + try: + for p in common: + conf = conf[p] + if key in conf: + default = conf[key] + except Exception: + return default + + # try all paths until a value is found + value = util.SENTINEL + for path in paths: + c = conf + try: + for p in path: + c = c[p] + if key in c: + value = c[key] + except Exception: + pass + if value is not util.SENTINEL: + return value + return default + + def set(path, key, value, *, conf=_config): """Set the value of property 'key' for this session""" for p in path: |
