mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-04-27 14:57:41 +00:00
Use name from config for representing storages
This commit is contained in:
parent
2fd4aaead3
commit
1fff7efff5
4 changed files with 17 additions and 7 deletions
|
|
@ -49,9 +49,10 @@ def test_load_config(tmpdir, monkeypatch):
|
||||||
assert general == {'foo': 1, 'status_path': status_path}
|
assert general == {'foo': 1, 'status_path': status_path}
|
||||||
assert pairs == {'bob': ('bob_a', 'bob_b', {'bam': True}, {'foo': 'bar'})}
|
assert pairs == {'bob': ('bob_a', 'bob_b', {'bam': True}, {'foo': 'bar'})}
|
||||||
assert storages == {
|
assert storages == {
|
||||||
'bob_a': {'type': 'filesystem', 'path': contacts_path,
|
'bob_a': {'type': 'filesystem', 'path': contacts_path, 'fileext':
|
||||||
'fileext': '.vcf', 'yesno': False, 'number': 42},
|
'.vcf', 'yesno': False, 'number': 42,
|
||||||
'bob_b': {'type': 'carddav'}
|
'instance_name': 'bob_a'},
|
||||||
|
'bob_b': {'type': 'carddav', 'instance_name': 'bob_b'}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert len(errors) == 1
|
assert len(errors) == 1
|
||||||
|
|
|
||||||
|
|
@ -157,5 +157,5 @@ def test_get_class_init_args_on_storage():
|
||||||
from vdirsyncer.storage.memory import MemoryStorage
|
from vdirsyncer.storage.memory import MemoryStorage
|
||||||
|
|
||||||
all, required = utils.get_class_init_args(MemoryStorage)
|
all, required = utils.get_class_init_args(MemoryStorage)
|
||||||
assert all == set(['collection', 'read_only'])
|
assert all == set(['collection', 'read_only', 'instance_name'])
|
||||||
assert not required
|
assert not required
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,7 @@ def load_config(fname, pair_options=('collections', 'conflict_resolution')):
|
||||||
|
|
||||||
def handle_storage(storage_name, options):
|
def handle_storage(storage_name, options):
|
||||||
storages.setdefault(storage_name, {}).update(options)
|
storages.setdefault(storage_name, {}).update(options)
|
||||||
|
storages[storage_name]['instance_name'] = storage_name
|
||||||
|
|
||||||
def handle_pair(pair_name, options):
|
def handle_pair(pair_name, options):
|
||||||
a, b = options.pop('a'), options.pop('b')
|
a, b = options.pop('a'), options.pop('b')
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,14 @@ class Storage(object):
|
||||||
'''
|
'''
|
||||||
|
|
||||||
fileext = '.txt'
|
fileext = '.txt'
|
||||||
storage_name = None # The name used in the config file.
|
|
||||||
|
# The string used in the config to denote the type of storage. Should be
|
||||||
|
# overridden by subclasses.
|
||||||
|
storage_name = None
|
||||||
|
|
||||||
|
# The string used in the config to denote a particular instance. Should be
|
||||||
|
# overridden during instantiation.
|
||||||
|
instance_name = None
|
||||||
|
|
||||||
# A value of True means the storage does not support write-methods such as
|
# A value of True means the storage does not support write-methods such as
|
||||||
# upload, update and delete. A value of False means the storage does
|
# upload, update and delete. A value of False means the storage does
|
||||||
|
|
@ -46,12 +53,13 @@ class Storage(object):
|
||||||
# The attribute values to show in the representation of the storage.
|
# The attribute values to show in the representation of the storage.
|
||||||
_repr_attributes = ()
|
_repr_attributes = ()
|
||||||
|
|
||||||
def __init__(self, read_only=None):
|
def __init__(self, instance_name=None, read_only=None):
|
||||||
if read_only is None:
|
if read_only is None:
|
||||||
read_only = self.read_only
|
read_only = self.read_only
|
||||||
if self.read_only and not read_only:
|
if self.read_only and not read_only:
|
||||||
raise ValueError('This storage is read-only.')
|
raise ValueError('This storage is read-only.')
|
||||||
self.read_only = bool(read_only)
|
self.read_only = bool(read_only)
|
||||||
|
self.instance_name = instance_name
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def discover(cls, **kwargs):
|
def discover(cls, **kwargs):
|
||||||
|
|
@ -66,7 +74,7 @@ class Storage(object):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<{}(**{})>'.format(
|
return self.instance_name or '<{}(**{})>'.format(
|
||||||
self.__class__.__name__,
|
self.__class__.__name__,
|
||||||
dict((x, getattr(self, x)) for x in self._repr_attributes)
|
dict((x, getattr(self, x)) for x in self._repr_attributes)
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue