From 19be72a173d14bd0f30e647e6a008e7204f2f00b Mon Sep 17 00:00:00 2001 From: Christian Schwamborn Date: Sat, 31 Dec 2022 14:04:25 +0100 Subject: [PATCH 1/2] add some blacklist code --- vdirsyncer/cli/config.py | 8 +++++++- vdirsyncer/cli/discover.py | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/vdirsyncer/cli/config.py b/vdirsyncer/cli/config.py index 59e7425d..ce2e4280 100644 --- a/vdirsyncer/cli/config.py +++ b/vdirsyncer/cli/config.py @@ -60,6 +60,7 @@ def _validate_collections_param(collections): raise ValueError("`collections` parameter must be a list or `null`.") collection_names = set() + collection_blacklist = set() for i, collection in enumerate(collections): try: @@ -87,9 +88,14 @@ def _validate_collections_param(collections): if collection_name in collection_names: raise ValueError("Duplicate value.") collection_names.add(collection_name) + + if collection[0] == '!': + collection_blacklist.add(collection_name[1:]) except ValueError as e: raise ValueError(f"`collections` parameter, position {i}: {str(e)}") + return collection_blacklist + class _ConfigReader: def __init__(self, f): @@ -233,7 +239,7 @@ def __init__(self, full_config, name, options): "Set `collections = null` explicitly in your pair config." ) else: - _validate_collections_param(self.collections) + self.blacklist=_validate_collections_param(self.collections) if options: raise ValueError("Unknown options: {}".format(", ".join(options))) diff --git a/vdirsyncer/cli/discover.py b/vdirsyncer/cli/discover.py index c28af141..adc9ed49 100644 --- a/vdirsyncer/cli/discover.py +++ b/vdirsyncer/cli/discover.py @@ -97,6 +97,7 @@ async def collections_for_pair( rv = await aiostream.stream.list( expand_collections( shortcuts=pair.collections, + blacklist=pair.blacklist, config_a=pair.config_a, config_b=pair.config_b, get_a_discovered=a_discovered.get_self, @@ -194,6 +195,7 @@ async def _discover(self): async def expand_collections( shortcuts, + blacklist, config_a, config_b, get_a_discovered, @@ -221,6 +223,10 @@ async def expand_collections( if collection in handled_collections: continue + elif collection[0] == '!': + continue + elif collection in blacklist: + continue handled_collections.add(collection) a_args = await _collection_from_discovered( From 54084be7ff9a65437d6e246b4af4a652d0706e2a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 31 Dec 2022 13:25:02 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- vdirsyncer/cli/config.py | 4 ++-- vdirsyncer/cli/discover.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/vdirsyncer/cli/config.py b/vdirsyncer/cli/config.py index ce2e4280..6e70032f 100644 --- a/vdirsyncer/cli/config.py +++ b/vdirsyncer/cli/config.py @@ -89,7 +89,7 @@ def _validate_collections_param(collections): raise ValueError("Duplicate value.") collection_names.add(collection_name) - if collection[0] == '!': + if collection[0] == "!": collection_blacklist.add(collection_name[1:]) except ValueError as e: raise ValueError(f"`collections` parameter, position {i}: {str(e)}") @@ -239,7 +239,7 @@ def __init__(self, full_config, name, options): "Set `collections = null` explicitly in your pair config." ) else: - self.blacklist=_validate_collections_param(self.collections) + self.blacklist = _validate_collections_param(self.collections) if options: raise ValueError("Unknown options: {}".format(", ".join(options))) diff --git a/vdirsyncer/cli/discover.py b/vdirsyncer/cli/discover.py index adc9ed49..84e7bda1 100644 --- a/vdirsyncer/cli/discover.py +++ b/vdirsyncer/cli/discover.py @@ -223,7 +223,7 @@ async def expand_collections( if collection in handled_collections: continue - elif collection[0] == '!': + elif collection[0] == "!": continue elif collection in blacklist: continue