From 80454460ced287fb82135eeaf8c4058606536856 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Sat, 16 Nov 2024 21:13:57 +0100 Subject: [PATCH] [config] support accumulating non-list values fixes 1264fc518b276b5caecc2cf45b90029acbd59ed4 --- gallery_dl/config.py | 10 ++++++++-- gallery_dl/job.py | 2 -- test/test_config.py | 18 ++++++++++++++++++ 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/gallery_dl/config.py b/gallery_dl/config.py index 855fb4f7..f932e3a5 100644 --- a/gallery_dl/config.py +++ b/gallery_dl/config.py @@ -261,13 +261,19 @@ def accumulate(path, key, conf=_config): if key in conf: value = conf[key] if value: - result.extend(value) + if isinstance(value, list): + result.extend(value) + else: + result.append(value) for p in path: conf = conf[p] if key in conf: value = conf[key] if value: - result[:0] = value + if isinstance(value, list): + result[:0] = value + else: + result.insert(0, value) except Exception: pass return result diff --git a/gallery_dl/job.py b/gallery_dl/job.py index be244279..f58cc05d 100644 --- a/gallery_dl/job.py +++ b/gallery_dl/job.py @@ -619,8 +619,6 @@ class DownloadJob(Job): pp_opts = cfg("postprocessor-options") pp_list = [] - if isinstance(postprocessors, (dict, str)): - postprocessors = (postprocessors,) for pp_dict in postprocessors: if isinstance(pp_dict, str): pp_dict = pp_conf.get(pp_dict) or {"name": pp_dict} diff --git a/test/test_config.py b/test/test_config.py index bbe288ff..1d49d776 100644 --- a/test/test_config.py +++ b/test/test_config.py @@ -117,6 +117,24 @@ class TestConfig(unittest.TestCase): self.assertEqual( config.accumulate(("c", "c"), "l"), [5, 6]) + config.set(() , "l", 4) + config.set(("c",) , "l", [2, 3]) + config.set(("c", "c"), "l", 1) + self.assertEqual( + config.accumulate((), "l") , [4]) + self.assertEqual( + config.accumulate(("c",), "l") , [2, 3, 4]) + self.assertEqual( + config.accumulate(("c", "c"), "l"), [1, 2, 3, 4]) + + config.set(("c",), "l", None) + self.assertEqual( + config.accumulate((), "l") , [4]) + self.assertEqual( + config.accumulate(("c",), "l") , [4]) + self.assertEqual( + config.accumulate(("c", "c"), "l"), [1, 4]) + def test_set(self): config.set(() , "c", [1, 2, 3]) config.set(("b",) , "c", [1, 2, 3])