mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-04-27 14:57:41 +00:00
Add storage_name parameter on storages
This commit is contained in:
parent
a1f7c4cb00
commit
55ad24db3d
8 changed files with 29 additions and 12 deletions
|
|
@ -87,7 +87,6 @@ def test_expand_collection(monkeypatch):
|
||||||
s.collection = 'a{}'.format(i)
|
s.collection = 'a{}'.format(i)
|
||||||
yield s
|
yield s
|
||||||
|
|
||||||
|
|
||||||
class TypeB(object):
|
class TypeB(object):
|
||||||
@classmethod
|
@classmethod
|
||||||
def discover(cls, **config):
|
def discover(cls, **config):
|
||||||
|
|
@ -100,7 +99,6 @@ def test_expand_collection(monkeypatch):
|
||||||
s.collection = 'b{}'.format(i)
|
s.collection = 'b{}'.format(i)
|
||||||
yield s
|
yield s
|
||||||
|
|
||||||
|
|
||||||
import vdirsyncer.storage
|
import vdirsyncer.storage
|
||||||
monkeypatch.setitem(vdirsyncer.storage.storage_names, 'mytype_a', TypeA)
|
monkeypatch.setitem(vdirsyncer.storage.storage_names, 'mytype_a', TypeA)
|
||||||
monkeypatch.setitem(vdirsyncer.storage.storage_names, 'mytype_b', TypeB)
|
monkeypatch.setitem(vdirsyncer.storage.storage_names, 'mytype_b', TypeB)
|
||||||
|
|
|
||||||
|
|
@ -138,7 +138,7 @@ def storage_instance_from_config(config, description=None):
|
||||||
invalid = given - all
|
invalid = given - all
|
||||||
|
|
||||||
cli_logger.critical('error: Failed to initialize {}'
|
cli_logger.critical('error: Failed to initialize {}'
|
||||||
.format(description or storage_name))
|
.format(description or cls.storage_name))
|
||||||
|
|
||||||
if not missing and not invalid:
|
if not missing and not invalid:
|
||||||
cli_logger.exception('')
|
cli_logger.exception('')
|
||||||
|
|
@ -146,12 +146,12 @@ def storage_instance_from_config(config, description=None):
|
||||||
if missing:
|
if missing:
|
||||||
cli_logger.critical(
|
cli_logger.critical(
|
||||||
u'error: {} storage requires the parameters: {}'
|
u'error: {} storage requires the parameters: {}'
|
||||||
.format(storage_name, u', '.join(missing)))
|
.format(cls.storage_name, u', '.join(missing)))
|
||||||
|
|
||||||
if invalid:
|
if invalid:
|
||||||
cli_logger.critical(
|
cli_logger.critical(
|
||||||
u'error: {} storage doesn\'t take the parameters: {}'
|
u'error: {} storage doesn\'t take the parameters: {}'
|
||||||
.format(storage_name, u', '.join(invalid)))
|
.format(cls.storage_name, u', '.join(invalid)))
|
||||||
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,10 +17,23 @@ from .filesystem import FilesystemStorage
|
||||||
from .http import HttpStorage
|
from .http import HttpStorage
|
||||||
from .singlefile import SingleFileStorage
|
from .singlefile import SingleFileStorage
|
||||||
|
|
||||||
storage_names = {
|
|
||||||
'caldav': CaldavStorage,
|
def _generate_storage_dict(*classes):
|
||||||
'carddav': CarddavStorage,
|
rv = {}
|
||||||
'filesystem': FilesystemStorage,
|
for cls in classes:
|
||||||
'http': HttpStorage,
|
key = cls.storage_name
|
||||||
'singlefile': SingleFileStorage
|
assert key
|
||||||
}
|
assert isinstance(key, str)
|
||||||
|
assert key not in rv
|
||||||
|
rv[key] = cls
|
||||||
|
return rv
|
||||||
|
|
||||||
|
storage_names = _generate_storage_dict(
|
||||||
|
CaldavStorage,
|
||||||
|
CarddavStorage,
|
||||||
|
FilesystemStorage,
|
||||||
|
HttpStorage,
|
||||||
|
SingleFileStorage
|
||||||
|
)
|
||||||
|
|
||||||
|
del _generate_storage_dict
|
||||||
|
|
|
||||||
|
|
@ -69,6 +69,7 @@ class Storage(object):
|
||||||
looked for.
|
looked for.
|
||||||
'''
|
'''
|
||||||
fileext = '.txt'
|
fileext = '.txt'
|
||||||
|
storage_name = None # the name used in the config file
|
||||||
_repr_attributes = ()
|
_repr_attributes = ()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
|
||||||
|
|
@ -287,6 +287,7 @@ class CaldavStorage(DavStorage):
|
||||||
in the normal usecase.
|
in the normal usecase.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
storage_name = 'caldav'
|
||||||
fileext = '.ics'
|
fileext = '.ics'
|
||||||
item_mimetype = 'text/calendar'
|
item_mimetype = 'text/calendar'
|
||||||
dav_header = 'calendar-access'
|
dav_header = 'calendar-access'
|
||||||
|
|
@ -383,6 +384,7 @@ class CarddavStorage(DavStorage):
|
||||||
CardDAV. Usable as ``carddav`` in the config file.
|
CardDAV. Usable as ``carddav`` in the config file.
|
||||||
''' + DavStorage.__doc__
|
''' + DavStorage.__doc__
|
||||||
|
|
||||||
|
storage_name = 'carddav'
|
||||||
fileext = '.vcf'
|
fileext = '.vcf'
|
||||||
item_mimetype = 'text/vcard'
|
item_mimetype = 'text/vcard'
|
||||||
dav_header = 'addressbook'
|
dav_header = 'addressbook'
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ class FilesystemStorage(Storage):
|
||||||
:param create: Create directories if they don't exist.
|
:param create: Create directories if they don't exist.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
storage_name = 'filesystem'
|
||||||
_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',
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,7 @@ class HttpStorage(Storage):
|
||||||
url = https://example.com/holidays_from_hicksville.ics
|
url = https://example.com/holidays_from_hicksville.ics
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
storage_name = 'http'
|
||||||
_repr_attributes = ('username', 'url')
|
_repr_attributes = ('username', 'url')
|
||||||
_items = None
|
_items = None
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,7 @@ class SingleFileStorage(Storage):
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
storage_name = 'singlefile'
|
||||||
_repr_attributes = ('path',)
|
_repr_attributes = ('path',)
|
||||||
|
|
||||||
_write_mode = 'wb'
|
_write_mode = 'wb'
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue