mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-03-25 08:55:50 +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
|
||||
path = ~/.contacts/
|
||||
fileext = .vcf
|
||||
#create = True # create directory if it doesn't exist
|
||||
#encoding = utf-8
|
||||
|
||||
[storage bob_contacts_remote]
|
||||
type = carddav
|
||||
|
|
|
|||
|
|
@ -26,3 +26,11 @@ class TestFilesystemStorage(StorageTests):
|
|||
if collection is not None:
|
||||
os.makedirs(os.path.join(path, 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',)
|
||||
|
||||
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
|
||||
collection parameter (see
|
||||
|
|
@ -38,10 +38,19 @@ class FilesystemStorage(Storage):
|
|||
will trigger a re-download of everything (but *should* not cause
|
||||
data-loss of any kind).
|
||||
:param encoding: File encoding for items.
|
||||
:param create: Create directories if they don't exist.
|
||||
'''
|
||||
super(FilesystemStorage, self).__init__(**kwargs)
|
||||
if collection is not None:
|
||||
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.path = expand_path(path)
|
||||
self.encoding = encoding
|
||||
|
|
|
|||
Loading…
Reference in a new issue