[CalendarServer-changes] [667] CalendarServer/trunk/twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Mon Dec 4 21:20:13 PST 2006


Revision: 667
          http://trac.macosforge.org/projects/calendarserver/changeset/667
Author:   wsanchez at apple.com
Date:     2006-12-04 21:20:13 -0800 (Mon, 04 Dec 2006)

Log Message:
-----------
More provisioning cleanup

Modified Paths:
--------------
    CalendarServer/trunk/twistedcaldav/directory/principal.py
    CalendarServer/trunk/twistedcaldav/static.py

Modified: CalendarServer/trunk/twistedcaldav/directory/principal.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/principal.py	2006-12-05 05:19:45 UTC (rev 666)
+++ CalendarServer/trunk/twistedcaldav/directory/principal.py	2006-12-05 05:20:13 UTC (rev 667)
@@ -38,6 +38,7 @@
 
 from twistedcaldav.extensions import ReadOnlyResourceMixIn, DAVFile
 from twistedcaldav.resource import CalendarPrincipalCollectionResource, CalendarPrincipalResource
+from twistedcaldav.static import provisionFile
 from twistedcaldav.directory.idirectory import IDirectoryService
 
 # FIXME: These should not be tied to DAVFile
@@ -72,17 +73,14 @@
         # FIXME: Smells like a hack
         directory.principalCollection = self
 
-        self._provision()
+        self.provision()
 
         # Create children
         for recordType in self.directory.recordTypes():
             self.putChild(recordType, DirectoryPrincipalTypeResource(self.fp.child(recordType).path, self, recordType))
 
-    def _provision(self):
-        self.fp.restat(False)
-        if not self.fp.exists():
-            self.fp.makedirs()
-            self.fp.restat(False)
+    def provision(self):
+        provisionFile(self)
 
     def principalForUser(self, user):
         return self.getChild("user").getChild(user)
@@ -101,7 +99,7 @@
         raise HTTPError(responsecode.NOT_FOUND)
 
     def getChild(self, name):
-        self._provision()
+        self.provision()
         return self.putChildren.get(name, None)
 
     def listChildren(self):
@@ -131,15 +129,10 @@
         self.recordType = recordType
         self._parent = parent
 
-        self._provision()
+        self.provision()
 
-    def _provision(self):
-        self.fp.restat(False)
-        if not self.fp.exists():
-            assert self._parent.exists()
-            assert self._parent.isCollection()
-            self.fp.makedirs()
-            self.fp.restat(False)
+    def provision(self):
+        provisionFile(self, self._parent)
 
     def principalForUser(self, user):
         return self._parent.principalForUser(user)
@@ -155,7 +148,7 @@
         raise HTTPError(responsecode.NOT_FOUND)
 
     def getChild(self, name, record=None):
-        self._provision()
+        self.provision()
 
         if name == "":
             return self
@@ -196,15 +189,10 @@
         self._parent = parent
         self._url = joinURL(parent.principalCollectionURL(), record.shortName)
 
-        self._provision()
+        self.provision()
 
-    def _provision(self):
-        self.fp.restat(False)
-        if not self.fp.exists():
-            assert self._parent.exists()
-            assert self._parent.isCollection()
-            self.fp.open("w").close()
-            self.fp.restat(False)
+    def provision(self):
+        provisionFile(self, self._parent, True)
 
     ##
     # HTTP
@@ -339,6 +327,10 @@
         else:
             return None
 
+##
+# Utilities
+##
+
 authReadACL = davxml.ACL(
     # Read access for authenticated users.
     davxml.ACE(

Modified: CalendarServer/trunk/twistedcaldav/static.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/static.py	2006-12-05 05:19:45 UTC (rev 666)
+++ CalendarServer/trunk/twistedcaldav/static.py	2006-12-05 05:20:13 UTC (rev 667)
@@ -364,7 +364,7 @@
         self._parent = parent
 
     def provision(self):
-        provisionDirectory(self, self._parent)
+        provisionFile(self, self._parent)
 
     def locateChild(self, path, segments):
         self.provision()
@@ -403,7 +403,7 @@
     Calendar scheduling inbox collection resource.
     """
     def provision(self):
-        if provisionDirectory(self, self._parent):
+        if provisionFile(self, self._parent):
             # FIXME: This should probably be a directory record option that
             # maps to the property value directly without the need to store one.
             if self._parent.record.recordType == "resource":
@@ -456,7 +456,7 @@
         directory.calendarHomesCollection = self
 
     def provision(self):
-        provisionDirectory(self)
+        provisionFile(self)
 
         if not self.putChildren:
             # Create children
@@ -526,7 +526,7 @@
         self._parent = parent
 
     def provision(self):
-        provisionDirectory(self, self._parent)
+        provisionFile(self, self._parent)
 
     def url(self):
         return joinURL(self._parent.url(), self.recordType)
@@ -595,7 +595,7 @@
             self.putChild(name, cls(self.fp.child(name).path, self))
 
     def provision(self):
-        if not provisionDirectory(self, self._parent):
+        if not provisionFile(self, self._parent):
             return succeed(None)
 
         # Create a calendar collection
@@ -711,17 +711,23 @@
 # Utilities
 ##
 
-def provisionDirectory(resource, parent=None):
-    resource.fp.restat(False)
-    if resource.fp.exists():
+def provisionFile(resource, parent=None, isFile=False):
+    fp = resource.fp
+
+    fp.restat(False)
+    if fp.exists():
         return False
 
     if parent is not None:
         assert parent.exists()
         assert parent.isCollection()
 
-    resource.fp.makedirs()
-    resource.fp.restat(False)
+    if isFile:
+        fp.open("w").close()
+        fp.restat(False)
+    else:
+        fp.makedirs()
+        fp.restat(False)
 
     return True
 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20061204/0ab713ac/attachment.html


More information about the calendarserver-changes mailing list