diff --git a/src/doblib/__init__.py b/src/doblib/__init__.py index 85cdcf4..e50bfd9 100644 --- a/src/doblib/__init__.py +++ b/src/doblib/__init__.py @@ -1 +1 @@ -VERSION = "0.18.1" +VERSION = "0.19.0" diff --git a/src/doblib/aggregate.py b/src/doblib/aggregate.py index fd6d60c..27eebf5 100644 --- a/src/doblib/aggregate.py +++ b/src/doblib/aggregate.py @@ -110,11 +110,7 @@ def _aggregator(self, args, mode=None): sem = threading.Semaphore(jobs) err_queue = Queue() - default = self.get(base.SECTION, "repo", default={}) - repos = { - key: utils.merge(default, value, replace=["merges"]) - for key, value in self.get("repos", default={}).items() - } + repos = self.get("repos", default={}) for repo_dict in get_repos(repos, args.force): if not err_queue.empty(): break diff --git a/src/doblib/env.py b/src/doblib/env.py index 1fe9f48..710edbc 100644 --- a/src/doblib/env.py +++ b/src/doblib/env.py @@ -104,6 +104,15 @@ def _post_process_config(self): current = set(map(os.path.abspath, current)) self.set("odoo", "options", "addons_path", value=current) + # Apply repos default + default = self.get(base.SECTION, "repo", default={}) + repos = { + key: utils.merge(default, value, replace=["merges"]) + for key, value in self.get("repos", default={}).items() + } + + self.set("repos", value=repos) + def get(self, *key, default=None): """Get a specific value of the configuration""" data = self._config diff --git a/src/doblib/utils.py b/src/doblib/utils.py index 68b84f5..ed82ac4 100644 --- a/src/doblib/utils.py +++ b/src/doblib/utils.py @@ -51,13 +51,21 @@ def error(msg, *args): def check_filters(name, whitelist=None, blacklist=None): """Check the name against the whitelist and blacklist""" - if whitelist and not any(fnmatch(name, pat) for pat in whitelist): - return False + def matches(patterns): + return [len(pat.replace("*", "")) for pat in patterns if fnmatch(name, pat)] - if blacklist and any(fnmatch(name, pat) for pat in blacklist): - return False + # Per default everything is allowed + if not whitelist and not blacklist: + return True - return True + whitelist_matches = matches(whitelist or []) + blacklist_matches = matches(blacklist or []) + + if whitelist_matches and blacklist_matches: + # The most specific pattern wins + return max(whitelist_matches) > max(blacklist_matches) + + return whitelist_matches and not blacklist_matches def default_parser(command): diff --git a/tests/test_utils.py b/tests/test_utils.py index 50851d2..d0ab523 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -54,6 +54,7 @@ def test_check_filters(): assert utils.check_filters("abc", whitelist=["*"]) assert not utils.check_filters("abc", blacklist=["*"]) assert not utils.check_filters("abc", whitelist=["a*"], blacklist=["ab*"]) + assert utils.check_filters("abcd", whitelist=["abc*"], blacklist=["ab*"]) assert utils.check_filters("aac", whitelist=["a*"], blacklist=["ab*"]) assert not utils.check_filters("bac", whitelist=["a*"], blacklist=["ab*"])