fix description in absence of .git/description, Collection.urlpath
authorchrysn <chrysn@fsfe.org>
Thu, 3 Apr 2014 13:02:28 +0000 (15:02 +0200)
committerchrysn <chrysn@fsfe.org>
Sun, 28 Feb 2016 16:28:06 +0000 (17:28 +0100)
in order to have a sensible default for descriptions, collections now
retain their url paths (previously, only the absolute file system path
was stored).

calypso/webdav.py

index f6b84abd43ae28f661e0bc5dbd6e9e51d5b6d5f8..12a9817b6ed1e57f4dee680589fd2fb7d427936e 100644 (file)
@@ -233,11 +233,12 @@ class Collection(object):
     """Internal collection class."""
 
     def get_description(self):
-        f = codecs.open(os.path.join(self.path, ".git/description"), encoding='utf-8')
         try:
-            return f.read()
-        finally:
-            f.close()
+            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
+            return self.urlpath
+        return f.read()
 
     def read_file(self, path):
         text = codecs.open(path,encoding='utf-8').read()
@@ -304,6 +305,7 @@ class Collection(object):
         
         self.log = logging.getLogger(__name__)
         self.encoding = "utf-8"
+        self.urlpath = path
         self.owner = paths.url_to_owner(path)
         self.path = paths.url_to_file(path)
         self.pattern = os.path.join(self.path, "*")