Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow sync from singlefile #1064

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ docs/_build/
vdirsyncer/version.py
.hypothesis
coverage.xml

.vscode
.env
27 changes: 7 additions & 20 deletions vdirsyncer/storage/singlefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from typing import Iterable

from atomicwrites import atomic_write
from pathlib import Path

from .. import exceptions
from ..utils import checkfile
Expand Down Expand Up @@ -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")
Comment on lines -64 to -72
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment here: #1056 (comment)

Copy link
Author

@azbarcea azbarcea Apr 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think removing this block is solves your initial intent, if I understand it right (will come back with more explanation in #1056 )

I can also confirm that the import from singlefile was now successful with current .patch.

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):
Expand Down