Преглед изворни кода

Create the directory structure if none found.

Lukasz Langa пре 14 година
родитељ
комит
537d6b6fd2
1 измењених фајлова са 11 додато и 5 уклоњено
  1. 11 5
      radicale/ical.py

+ 11 - 5
radicale/ical.py

@@ -185,16 +185,20 @@ class Calendar(object):
         path = "/".join(attributes[:min(len(attributes), 2)])
         path = path.replace("/", os.sep)
         abs_path = os.path.join(FOLDER, path)
-        if os.path.isdir(abs_path):
+        if os.path.isdir(abs_path) or len(attributes) == 1:
             if depth == "0":
                 result.append(cls(path, principal=True))
             else:
                 if include_container:
                     result.append(cls(path, principal=True))
-                for f in next(os.walk(abs_path))[2]:
-                    f_path = os.path.join(path, f)
-                    if cls.is_vcalendar(os.path.join(abs_path, f)):
-                        result.append(cls(f_path))
+                try:
+                    for f in next(os.walk(abs_path))[2]:
+                        f_path = os.path.join(path, f)
+                        if cls.is_vcalendar(os.path.join(abs_path, f)):
+                            result.append(cls(f_path))
+                except StopIteration:
+                    # directory does not exist yet
+                    pass
         else:
             calendar = cls(path)
             if depth == "0":
@@ -284,6 +288,8 @@ class Calendar(object):
 
     def write(self, headers=None, items=None):
         """Write calendar with given parameters."""
+        if self.is_principal:
+            return
         headers = headers or self.headers or (
             Header("PRODID:-//Radicale//NONSGML Radicale Server//EN"),
             Header("VERSION:2.0"))