[Calypso-commits] [calypso] 01/02: Add per-collection configuration.

Jelmer Vernooij jelmer at moszumanska.debian.org
Sat Apr 9 22:37:42 UTC 2016


This is an automated email from the git hooks/post-receive script.

jelmer pushed a commit to branch master
in repository calypso.

commit 11060547faef4a8582b288a8a619b5b4b0868e55
Author: chrysn <chrysn at fsfe.org>
Date:   Fri Apr 4 13:24:40 2014 +0200

    Add per-collection configuration.
    
    this is necessary to support empty calendars/address books with clients
    that rely on autodiscovery.
    
    pre-existing collections need per-collection configs for upgrading, as
    their content will allow guessing.
---
 calypso/webdav.py | 31 +++++++++++++++++++++++++++++++
 collection-config | 14 ++++++++++++++
 2 files changed, 45 insertions(+)

diff --git a/calypso/webdav.py b/calypso/webdav.py
index 1bcfecc..e059d19 100644
--- a/calypso/webdav.py
+++ b/calypso/webdav.py
@@ -37,8 +37,12 @@ import vobject
 import re
 import subprocess
 
+import ConfigParser
+
 from . import config, paths
 
+METADATA_FILENAME = ".calypso-collection"
+
 #
 # Recursive search for 'name' within 'vobject'
 #
@@ -230,6 +234,11 @@ class Collection(object):
 
     def get_description(self):
         try:
+            return str(self.metadata.get('collection', 'description'))
+        except (ConfigParser.NoSectionError, ConfigParser.NoOptionError, ValueError):
+            pass
+
+        try:
             f = codecs.open(os.path.join(self.path, ".git/description"), encoding='utf-8')
         except IOError:
             # .git/description is not present eg when the complete server is a single git repo
@@ -261,6 +270,22 @@ class Collection(object):
         self.remove_file(path)
         self.insert_file(path)
 
+    __metadatafile = property(lambda self: os.path.join(self.path, METADATA_FILENAME))
+
+    def scan_metadata(self, force):
+        try:
+            mtime = os.path.getmtime(self.__metadatafile)
+        except OSError:
+            mtime = 0
+            force = True
+
+        if not force and mtime == self.mtime and self.metadata is not None:
+            return
+
+        parser = ConfigParser.RawConfigParser()
+        parser.read(self.__metadatafile)
+        self.metadata = parser
+
     def scan_dir(self, force):
         try:
             mtime = os.path.getmtime(self.path)
@@ -268,6 +293,8 @@ class Collection(object):
             mtime = 0
             force = True
 
+        self.scan_metadata(force)
+
         if not force and mtime == self.mtime:
             return
         self.log.debug("Scan %s", self.path)
@@ -275,6 +302,8 @@ class Collection(object):
         filenames = glob.glob(self.pattern)
         newfiles = []
         for filename in filenames:
+            if filename == METADATA_FILENAME:
+                continue
             for file in self.files:
                 if filename == file.path:
                     newfiles.append(file)
@@ -313,6 +342,8 @@ class Collection(object):
         self.mtime = 0
         self._ctag = ''
         self.etag = hashlib.sha1(self.path).hexdigest()
+        self.metadata = None
+        self.metadata_mtime = None
         self.scan_dir(False)
         self.tag = "Collection"
 
diff --git a/collection-config b/collection-config
new file mode 100644
index 0000000..4ce34a4
--- /dev/null
+++ b/collection-config
@@ -0,0 +1,14 @@
+# Per-collection config file for Calypso
+#
+# Name it .calypso-collection and place it into a collection to tune its
+# behavior; a typical location for it would be
+# ~/.config/calypso/calendars/private/test/.calypso-collection
+
+[collection]
+# Short name. Defaults to the collection's path.
+displayname = My Calendar
+# Description used for the addressbook-description and calendar-description
+# WebDAV properties. Defaults to the collection's path.
+description = Collection of all my personal dates.
+
+# vim:ft=cfg

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/calypso/calypso.git



More information about the Calypso-commits mailing list