From 537d6b6fd2347c88fd2b1a9062642566b956e9c6 Mon Sep 17 00:00:00 2001 From: Lukasz Langa Date: Wed, 1 Jun 2011 18:22:26 +0200 Subject: [PATCH] Create the directory structure if none found. --- radicale/ical.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/radicale/ical.py b/radicale/ical.py index a20f044..6caf5af 100644 --- a/radicale/ical.py +++ b/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"))