[Calypso] [PATCH 2/2] Scan directories to allow finding subcollections.

Guido Günther agx at sigxcpu.org
Mon May 16 02:02:32 PDT 2016


On Mon, May 09, 2016 at 08:35:32PM +0000, Jelmer Vernooij wrote:
> From: Jelmer Vernooij <jelmer at jelmer.uk>

This is contained in

    [Calypso] [PATCH 3/4] When scanning for children, allow directories
    (as subcollections).

right?
 -- Guido

> 
> This is necessary for e.g. davdroid.
> ---
>  calypso/webdav.py | 25 ++++++++++++++++++-------
>  1 file changed, 18 insertions(+), 7 deletions(-)
> 
> diff --git a/calypso/webdav.py b/calypso/webdav.py
> index 0299c7a..9a478e5 100644
> --- a/calypso/webdav.py
> +++ b/calypso/webdav.py
> @@ -38,7 +38,7 @@ import subprocess
>  
>  import ConfigParser
>  
> -from . import config, paths
> +from . import paths
>  
>  METADATA_FILENAME = ".calypso-collection"
>  
> @@ -257,6 +257,14 @@ class Collection(object):
>              self.log.exception("Insert %s failed", path)
>              return
>  
> +    def insert_directory(self, path):
> +         try:
> +            item = Collection(path)
> +            self.my_items.append(item)
> +         except Exception, ex:
> +            self.log.exception("Insert %s failed", path)
> +            return
> +
>      def remove_file(self, path):
>          old_items=[]
>          for old_item in self.my_items:
> @@ -303,6 +311,8 @@ class Collection(object):
>          for filename in filenames:
>              if filename == METADATA_FILENAME:
>                  continue
> +            if filename == '.git':
> +                continue
>              filepath = os.path.join(self.path, filename)
>              for file in self.files:
>                  if filepath == file.path:
> @@ -312,19 +322,20 @@ class Collection(object):
>                          self.scan_file(filepath)
>                      break
>              else:
> -                if os.path.isdir(filepath):
> -                    self.log.debug("Ignoring directory %s in scan_dir", filepath)
> -                else:
> -                    self.log.debug("New %s", filepath)
> -                    newfiles.append(Pathtime(filepath))
> +                self.log.debug("New %s", filepath)
> +                newfiles.append(Pathtime(filepath))
> +                if not os.path.isdir(filepath):
>                      self.insert_file(filepath)
> +                else:
> +                    self.insert_directory("/".join([self.urlpath, filename]))
>          for file in self.files:
>              if not file.path in filenames:
>                  self.log.debug("Removed %s", file.path)
>                  self.remove_file(file.path)
>          h = hashlib.sha1()
>          for item in self.my_items:
> -            h.update(item.etag)
> +            if getattr(item, 'etag', None):
> +                h.update(item.etag)
>          self._ctag = '%d-' % self.mtime + h.hexdigest()
>          self.files = newfiles
>                  
> -- 
> 2.8.1
> 
> _______________________________________________
> Calypso mailing list
> Calypso at keithp.com
> http://keithp.com/mailman/listinfo/calypso


More information about the Calypso mailing list