From e4a7f0577df5516447c81475b0f0f714f28bc099 Mon Sep 17 00:00:00 2001 From: Alexandru Zbarcea Date: Thu, 20 Apr 2023 14:43:23 -0400 Subject: [PATCH 1/3] Allow sync from singlefile --- .gitignore | 3 +++ vdirsyncer/storage/singlefile.py | 27 +++++++-------------------- 2 files changed, 10 insertions(+), 20 deletions(-) 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..df4ea63d 100644 --- a/vdirsyncer/storage/singlefile.py +++ b/vdirsyncer/storage/singlefile.py @@ -7,6 +7,7 @@ from typing import Iterable from atomicwrites import atomic_write +from pathlib import Path from .. import exceptions from ..utils import checkfile @@ -61,28 +62,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): From 9335ae8d846ea854fbb7707d1e5491859b088a16 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 20 Apr 2023 18:51:26 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- vdirsyncer/storage/singlefile.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vdirsyncer/storage/singlefile.py b/vdirsyncer/storage/singlefile.py index df4ea63d..48cb786a 100644 --- a/vdirsyncer/storage/singlefile.py +++ b/vdirsyncer/storage/singlefile.py @@ -7,7 +7,7 @@ from typing import Iterable from atomicwrites import atomic_write -from pathlib import Path +from pathlib import Path from .. import exceptions from ..utils import checkfile @@ -64,7 +64,7 @@ async def discover(cls, path, **kwargs): args = dict(kwargs) - # By convention the collection name of a unified .vcf file will the + # 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)) From 0fb7257838d741302813c9d50dd9afd9ef1aa7d1 Mon Sep 17 00:00:00 2001 From: Alexandru Zbarcea Date: Fri, 21 Apr 2023 10:51:21 -0400 Subject: [PATCH 3/3] organize imports --- vdirsyncer/storage/singlefile.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/vdirsyncer/storage/singlefile.py b/vdirsyncer/storage/singlefile.py index 48cb786a..b2b32e14 100644 --- a/vdirsyncer/storage/singlefile.py +++ b/vdirsyncer/storage/singlefile.py @@ -1,13 +1,12 @@ 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 -from pathlib import Path from .. import exceptions from ..utils import checkfile