From 6ef94e512ec9830de2de84b98f26c77cecc14d7d Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Fri, 7 Mar 2014 00:36:52 +0100 Subject: [PATCH] Fix #2 Very inefficient but works 100% --- config.example | 1 + vdirsyncer/storage/dav/base.py | 4 ++-- vdirsyncer/storage/dav/caldav.py | 27 +++++++++++++++++++++------ vdirsyncer/storage/dav/carddav.py | 21 +++++++++++---------- 4 files changed, 35 insertions(+), 18 deletions(-) diff --git a/config.example b/config.example index f9961ef..9f67e5c 100644 --- a/config.example +++ b/config.example @@ -25,6 +25,7 @@ fileext = .vcf [storage bob_contacts_remote] type = carddav +#item_types = VTODO,VEVENT url = https://owncloud.example.com/remote.php/carddav/addressbooks/bob/default/ #username = # blabla #password = # blabla diff --git a/vdirsyncer/storage/dav/base.py b/vdirsyncer/storage/dav/base.py index f57971e..d40f89e 100644 --- a/vdirsyncer/storage/dav/base.py +++ b/vdirsyncer/storage/dav/base.py @@ -214,11 +214,11 @@ class DavStorage(Storage): ) self._check_response(response) - def list(self): + def _list(self, xml): response = self._request( 'REPORT', '', - data=self.list_xml, + data=xml, headers=self._default_headers() ) response.raise_for_status() diff --git a/vdirsyncer/storage/dav/caldav.py b/vdirsyncer/storage/dav/caldav.py index 1560b89..2a5de6e 100644 --- a/vdirsyncer/storage/dav/caldav.py +++ b/vdirsyncer/storage/dav/caldav.py @@ -23,6 +23,7 @@ class CaldavStorage(DavStorage): dav_header = 'calendar-access' start_date = None end_date = None + item_types = None get_multi_template = ''' @@ -64,7 +70,7 @@ class CaldavStorage(DavStorage): - + {caldavfilter} @@ -72,10 +78,19 @@ class CaldavStorage(DavStorage): ''' start = self.start_date end = self.end_date + caldavfilter = '' if start is not None and end is not None: start = start.strftime(CALDAV_DT_FORMAT) end = end.strftime(CALDAV_DT_FORMAT) caldavfilter = ('' .format(start=start, end=end)) - return data.format(caldavfilter=caldavfilter) - return data.format(caldavfilter='') + return data.format(caldavfilter=caldavfilter, component='{item_type}') + + def list(self): + hrefs = set() + for t in self.item_types: + xml = self._list_template.format(item_type=t) + for href, etag in self._list(xml): + assert href not in hrefs + hrefs.add(href) + yield href, etag diff --git a/vdirsyncer/storage/dav/carddav.py b/vdirsyncer/storage/dav/carddav.py index 6b720d2..52a94ca 100644 --- a/vdirsyncer/storage/dav/carddav.py +++ b/vdirsyncer/storage/dav/carddav.py @@ -30,13 +30,14 @@ class CarddavStorage(DavStorage): get_multi_data_query = '{urn:ietf:params:xml:ns:carddav}address-data' - list_xml = ''' - - - - - - - - ''' + def list(self): + return self._list(''' + + + + + + + + ''')