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

Jelmer Vernooij jelmer at jelmer.uk
Thu May 19 11:43:41 PDT 2016


This is required for DavDroid, never versions of which discover the available collection URLs and show them to the user.

I agree that tests would be really nice, but that's a big investment at the moment as the code doesn't lend itself to testing well and there are no existing tests to build on. At the moment I'm merely trying to keep my own setup working :/

On 16 May 2016 11:03:51 CEST, "Guido Günther" <agx at sigxcpu.org> wrote:
>On Sun, May 15, 2016 at 10:35:31PM +0000, Jelmer Vernooij wrote:
>> From: Jelmer Vernooij <jelmer at jelmer.uk>
>> 
>> ---
>>  calypso/webdav.py | 29 +++++++++++++++++++++--------
>>  1 file changed, 21 insertions(+), 8 deletions(-)
>> 
>> diff --git a/calypso/webdav.py b/calypso/webdav.py
>> index e198a14..4b52d67 100644
>> --- a/calypso/webdav.py
>> +++ b/calypso/webdav.py
>> @@ -265,6 +265,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:
>> @@ -311,6 +319,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:
>> @@ -320,25 +330,28 @@ 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)
>> +            else:
>> +                h.update(item.ctag)
>>          self._ctag = '%d-' % self.mtime + h.hexdigest()
>>          self.files = newfiles
>> -                
>> +
>>      def __init__(self, path):
>>          """Initialize the collection with ``cal`` and ``user``
>parameters."""
>> -        
>> +
>>          self.log = logging.getLogger(__name__)
>>          self.encoding = "utf-8"
>>          self.urlpath = path
>> -- 
>> 2.8.1
>
>A testcase would help to review this. The target is to allow
>subcollections as subfolders? If so LGTM but it would be great to have
>a
>testcase for these kind of tings so we don't break it in the future
>(and
>it gets simpler to review).
>Cheers,
> -- Guido

-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.


More information about the Calypso mailing list