Skip to content

Commit 6359c7b

Browse files
committed
Implement refreshrate and calendar-timezone property support
1 parent 8f659ea commit 6359c7b

File tree

4 files changed

+102
-7
lines changed

4 files changed

+102
-7
lines changed

tests/test_config.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,21 @@ def test_order(self):
126126
self._config.set_order(None)
127127
self.assertRaises(KeyError, self._config.get_order)
128128

129+
def test_refreshrate(self):
130+
self.assertRaises(KeyError, self._config.get_refreshrate)
131+
self._config.set_refreshrate("PT1H")
132+
self.assertEqual("PT1H", self._config.get_refreshrate())
133+
self._config.set_refreshrate(None)
134+
self.assertRaises(KeyError, self._config.get_refreshrate)
135+
136+
def test_timezone(self):
137+
self.assertRaises(KeyError, self._config.get_timezone)
138+
tz_data = "BEGIN:VTIMEZONE\r\nTZID:America/New_York\r\nEND:VTIMEZONE"
139+
self._config.set_timezone(tz_data)
140+
self.assertEqual(tz_data, self._config.get_timezone())
141+
self._config.set_timezone(None)
142+
self.assertRaises(KeyError, self._config.get_timezone)
143+
129144

130145
class FileMetadataTests(TestCase, MetadataTests):
131146
def setUp(self):

xandikos/store/config.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,38 @@ def get_order(self) -> str:
8282
def set_order(self, order: str) -> None:
8383
raise NotImplementedError(self.set_order)
8484

85+
def get_refreshrate(self) -> str:
86+
"""Get the recommended refresh rate for this collection.
87+
88+
Returns: Refresh rate in ISO 8601 duration format
89+
Raises: KeyError if not set
90+
"""
91+
raise NotImplementedError(self.get_refreshrate)
92+
93+
def set_refreshrate(self, refreshrate: str | None) -> None:
94+
"""Set the recommended refresh rate for this collection.
95+
96+
Args:
97+
refreshrate: Refresh rate in ISO 8601 duration format, or None to unset
98+
"""
99+
raise NotImplementedError(self.set_refreshrate)
100+
101+
def get_timezone(self) -> str:
102+
"""Get the calendar timezone.
103+
104+
Returns: iCalendar VTIMEZONE component as a string
105+
Raises: KeyError if not set
106+
"""
107+
raise NotImplementedError(self.get_timezone)
108+
109+
def set_timezone(self, timezone: str | None) -> None:
110+
"""Set the calendar timezone.
111+
112+
Args:
113+
timezone: iCalendar VTIMEZONE component as a string, or None to unset
114+
"""
115+
raise NotImplementedError(self.set_timezone)
116+
85117

86118
class FileBasedCollectionMetadata(CollectionMetadata):
87119
"""Metadata for a configuration."""
@@ -172,3 +204,24 @@ def set_order(self, order):
172204
del self._configparser["calendar"]["order"]
173205
else:
174206
self._configparser["calendar"]["order"] = order
207+
self._save("Set calendar order.")
208+
209+
def get_refreshrate(self):
210+
return self._configparser["DEFAULT"]["refreshrate"]
211+
212+
def set_refreshrate(self, refreshrate):
213+
if refreshrate is not None:
214+
self._configparser["DEFAULT"]["refreshrate"] = refreshrate
215+
else:
216+
del self._configparser["DEFAULT"]["refreshrate"]
217+
self._save("Set refresh rate.")
218+
219+
def get_timezone(self):
220+
return self._configparser["DEFAULT"]["timezone"]
221+
222+
def set_timezone(self, timezone):
223+
if timezone is not None:
224+
self._configparser["DEFAULT"]["timezone"] = timezone
225+
else:
226+
del self._configparser["DEFAULT"]["timezone"]
227+
self._save("Set timezone.")

xandikos/store/git.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,36 @@ def set_order(self, order):
182182
config.set(b"xandikos", b"calendar-order", order.encode("utf-8"))
183183
self._write_config(config)
184184

185+
def get_refreshrate(self):
186+
config = self._repo.get_config()
187+
refreshrate = config.get(b"xandikos", b"refreshrate")
188+
if refreshrate == b"":
189+
raise KeyError
190+
return refreshrate.decode(DEFAULT_ENCODING)
191+
192+
def set_refreshrate(self, refreshrate):
193+
config = self._repo.get_config()
194+
if refreshrate is not None:
195+
config.set(b"xandikos", b"refreshrate", refreshrate.encode(DEFAULT_ENCODING))
196+
else:
197+
config.set(b"xandikos", b"refreshrate", b"")
198+
self._write_config(config)
199+
200+
def get_timezone(self):
201+
config = self._repo.get_config()
202+
timezone = config.get(b"xandikos", b"timezone")
203+
if timezone == b"":
204+
raise KeyError
205+
return timezone.decode(DEFAULT_ENCODING)
206+
207+
def set_timezone(self, timezone):
208+
config = self._repo.get_config()
209+
if timezone is not None:
210+
config.set(b"xandikos", b"timezone", timezone.encode(DEFAULT_ENCODING))
211+
else:
212+
config.set(b"xandikos", b"timezone", b"")
213+
self._write_config(config)
214+
185215

186216
class GitStore(Store):
187217
"""A Store backed by a Git Repository."""

xandikos/web.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -528,12 +528,10 @@ def get_quota_available_bytes(self):
528528
raise KeyError
529529

530530
def get_refreshrate(self):
531-
# TODO(jelmer): Support setting refreshrate
532-
raise KeyError
531+
return self.store.config.get_refreshrate()
533532

534533
def set_refreshrate(self, value):
535-
# TODO(jelmer): Store refreshrate
536-
raise NotImplementedError(self.set_refreshrate)
534+
self.store.config.set_refreshrate(value)
537535

538536

539537
class Collection(StoreBasedCollection, webdav.Collection):
@@ -604,11 +602,10 @@ def set_calendar_order(self, order):
604602
self.store.config.set_order(order)
605603

606604
def get_calendar_timezone(self):
607-
# TODO(jelmer): Read from config
608-
raise KeyError
605+
return self.store.config.get_timezone()
609606

610607
def set_calendar_timezone(self, content):
611-
raise NotImplementedError(self.set_calendar_timezone)
608+
self.store.config.set_timezone(content)
612609

613610
def _ensure_metadata_directory(self):
614611
"""Ensure .xandikos/ metadata directory exists, migrating from old .xandikos config file if needed."""

0 commit comments

Comments
 (0)