mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-04-27 14:57:41 +00:00
Fix #20
This commit is contained in:
parent
8f6b3003cc
commit
46910dbc4f
3 changed files with 20 additions and 1 deletions
|
|
@ -21,6 +21,8 @@ collections = private,coworkers # collections = addressbooks in this case
|
||||||
type = filesystem
|
type = filesystem
|
||||||
path = ~/.contacts/
|
path = ~/.contacts/
|
||||||
fileext = .vcf
|
fileext = .vcf
|
||||||
|
#create = True # create directory if it doesn't exist
|
||||||
|
#encoding = utf-8
|
||||||
|
|
||||||
[storage bob_contacts_remote]
|
[storage bob_contacts_remote]
|
||||||
type = carddav
|
type = carddav
|
||||||
|
|
|
||||||
|
|
@ -26,3 +26,11 @@ class TestFilesystemStorage(StorageTests):
|
||||||
if collection is not None:
|
if collection is not None:
|
||||||
os.makedirs(os.path.join(path, collection))
|
os.makedirs(os.path.join(path, collection))
|
||||||
return {'path': path, 'fileext': '.txt', 'collection': collection}
|
return {'path': path, 'fileext': '.txt', 'collection': collection}
|
||||||
|
|
||||||
|
def test_create_directory(self, tmpdir):
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
self.storage_class(str(tmpdir), '.txt', collection='lol',
|
||||||
|
create=False)
|
||||||
|
|
||||||
|
self.storage_class(str(tmpdir), '.txt', collection='asd')
|
||||||
|
assert tmpdir.listdir() == [tmpdir.join('asd')]
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ class FilesystemStorage(Storage):
|
||||||
_repr_attributes = ('path',)
|
_repr_attributes = ('path',)
|
||||||
|
|
||||||
def __init__(self, path, fileext, collection=None, encoding='utf-8',
|
def __init__(self, path, fileext, collection=None, encoding='utf-8',
|
||||||
**kwargs):
|
create=True, **kwargs):
|
||||||
'''
|
'''
|
||||||
:param path: Absolute path to a vdir or collection, depending on the
|
:param path: Absolute path to a vdir or collection, depending on the
|
||||||
collection parameter (see
|
collection parameter (see
|
||||||
|
|
@ -38,10 +38,19 @@ class FilesystemStorage(Storage):
|
||||||
will trigger a re-download of everything (but *should* not cause
|
will trigger a re-download of everything (but *should* not cause
|
||||||
data-loss of any kind).
|
data-loss of any kind).
|
||||||
:param encoding: File encoding for items.
|
:param encoding: File encoding for items.
|
||||||
|
:param create: Create directories if they don't exist.
|
||||||
'''
|
'''
|
||||||
super(FilesystemStorage, self).__init__(**kwargs)
|
super(FilesystemStorage, self).__init__(**kwargs)
|
||||||
if collection is not None:
|
if collection is not None:
|
||||||
path = os.path.join(path, collection)
|
path = os.path.join(path, collection)
|
||||||
|
if not os.path.isdir(path):
|
||||||
|
if create:
|
||||||
|
os.makedirs(path, 0750)
|
||||||
|
else:
|
||||||
|
raise ValueError('Directory {} does not exist. Use create = '
|
||||||
|
'True in your configuration to automatically '
|
||||||
|
'create it, or create it '
|
||||||
|
'yourself.'.format(path))
|
||||||
self.collection = collection
|
self.collection = collection
|
||||||
self.path = expand_path(path)
|
self.path = expand_path(path)
|
||||||
self.encoding = encoding
|
self.encoding = encoding
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue