diff --git a/.gitignore b/.gitignore index 5848bd2e..5a673ed7 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,6 @@ docs/_build/ vdirsyncer/version.py .hypothesis coverage.xml + +.vscode +.env diff --git a/vdirsyncer/storage/singlefile.py b/vdirsyncer/storage/singlefile.py index 12f48bb0..b2b32e14 100644 --- a/vdirsyncer/storage/singlefile.py +++ b/vdirsyncer/storage/singlefile.py @@ -1,9 +1,9 @@ import collections import contextlib import functools -import glob import logging import os +from pathlib import Path from typing import Iterable from atomicwrites import atomic_write @@ -61,28 +61,14 @@ async def discover(cls, path, **kwargs): if kwargs.pop("collection", None) is not None: raise TypeError("collection argument must not be given.") - path = os.path.abspath(expand_path(path)) - try: - path_glob = path % "*" - except TypeError: - # If not exactly one '%s' is present, we cannot discover - # collections because we wouldn't know which name to assign. - raise NotImplementedError - - placeholder_pos = path.index("%s") + args = dict(kwargs) - for subpath in glob.iglob(path_glob): - if os.path.isfile(subpath): - args = dict(kwargs) - args["path"] = subpath - - collection_end = ( - placeholder_pos + 2 + len(subpath) - len(path) # length of '%s' - ) - collection = subpath[placeholder_pos:collection_end] - args["collection"] = collection + # By convention the collection name of a unified .vcf file will the + # file's stem (name of the file without extension) + args["collection"] = Path(path).stem + args["path"] = os.path.abspath(expand_path(path)) - yield args + yield args @classmethod async def create_collection(cls, collection, **kwargs):