MCPcopy
hub / github.com/pimutils/vdirsyncer / discover

Method discover

vdirsyncer/storage/singlefile.py:51–79  ·  view source on GitHub ↗
(cls, path, **kwargs)

Source from the content-addressed store, hash-verified

49
50 @classmethod
51 def discover(cls, path, **kwargs):
52 if kwargs.pop('collection', None) is not None:
53 raise TypeError('collection argument must not be given.')
54
55 path = os.path.abspath(expand_path(path))
56 try:
57 path_glob = path % '*'
58 except TypeError:
59 # If not exactly one '%s' is present, we cannot discover
60 # collections because we wouldn't know which name to assign.
61 raise NotImplementedError()
62
63 placeholder_pos = path.index('%s')
64
65 for subpath in glob.iglob(path_glob):
66 if os.path.isfile(subpath):
67 args = dict(kwargs)
68 args['path'] = subpath
69
70 collection_end = (
71 placeholder_pos
72 + 2 # length of '%s'
73 + len(subpath)
74 - len(path)
75 )
76 collection = subpath[placeholder_pos:collection_end]
77 args['collection'] = collection
78
79 yield args
80
81 @classmethod
82 def create_collection(cls, collection, **kwargs):

Callers

nothing calls this directly

Calls 1

expand_pathFunction · 0.85

Tested by

no test coverage detected