[Calypso] [PATCH 1/3] Add per-collection configuration.

Guido Günther agx at sigxcpu.org
Sat Apr 9 15:15:00 PDT 2016


On Sat, Apr 09, 2016 at 06:09:41PM +0000, Jelmer Vernooij wrote:
> From: chrysn <chrysn at fsfe.org>
> 
> 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 | 27 +++++++++++++++++++++++++++
>  collection-config | 14 ++++++++++++++
>  2 files changed, 41 insertions(+)
>  create mode 100644 collection-config
> 
> diff --git a/calypso/webdav.py b/calypso/webdav.py
> index 1bcfecc..5573997 100644
> --- a/calypso/webdav.py
> +++ b/calypso/webdav.py
> @@ -37,6 +37,8 @@ import vobject
>  import re
>  import subprocess
>  
> +import ConfigParser
> +
>  from . import config, paths
>  
>  #
> @@ -230,6 +232,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 +268,22 @@ class Collection(object):
>          self.remove_file(path)
>          self.insert_file(path)
>  
> +    __metadatafile = property(lambda self: os.path.join(self.path, ".calypso-collection"))
> +
> +    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 +291,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)
> @@ -313,6 +338,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

Looks good to me.
 -- Guido


More information about the Calypso mailing list