[CalendarServer-changes] [4401] CalendarServer/branches/users/sagen/pending-invites-4389/ twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Tue Jun 30 15:51:53 PDT 2009


Revision: 4401
          http://trac.macosforge.org/projects/calendarserver/changeset/4401
Author:   sagen at apple.com
Date:     2009-06-30 15:51:53 -0700 (Tue, 30 Jun 2009)
Log Message:
-----------
Invites are now being delivered, although I'm seeing a 2nd one in the inbox

Modified Paths:
--------------
    CalendarServer/branches/users/sagen/pending-invites-4389/twistedcaldav/test/test_upgrade.py
    CalendarServer/branches/users/sagen/pending-invites-4389/twistedcaldav/test/util.py
    CalendarServer/branches/users/sagen/pending-invites-4389/twistedcaldav/upgrade.py

Modified: CalendarServer/branches/users/sagen/pending-invites-4389/twistedcaldav/test/test_upgrade.py
===================================================================
--- CalendarServer/branches/users/sagen/pending-invites-4389/twistedcaldav/test/test_upgrade.py	2009-06-30 18:48:39 UTC (rev 4400)
+++ CalendarServer/branches/users/sagen/pending-invites-4389/twistedcaldav/test/test_upgrade.py	2009-06-30 22:51:53 UTC (rev 4401)
@@ -31,6 +31,8 @@
 freeBusyAttr = "WebDAV:{urn:ietf:params:xml:ns:caldav}calendar-free-busy-set"
 cTagAttr = "WebDAV:{http:%2F%2Fcalendarserver.org%2Fns%2F}getctag"
 md5Attr = "WebDAV:{http:%2F%2Ftwistedmatrix.com%2Fxml_namespace%2Fdav%2F}getcontentmd5"
+resourceTypeAttr = "WebDAV:{DAV:}resourcetype"
+defaultCalendarAttr = "WebDAV:{urn:ietf:params:xml:ns:caldav}schedule-default-calendar-URL"
 
 
 class ProxyDBUpgradeTests(TestCase):
@@ -842,7 +844,12 @@
                             "6423F94A-6B76-4A3A-815B-D52CFD77935D" :
                             {
                                 "calendar" :
-                                { },
+                                {
+                                    "@xattrs" :
+                                    {
+                                        resourceTypeAttr : zlib.compress("<?xml version='1.0' encoding='UTF-8'?><resourcetype xmlns='DAV:'><collection/><calendar xmlns='urn:ietf:params:xml:ns:caldav'/></resourcetype>\r\n"),
+                                    },
+                                },
                                 "inbox" :
                                 {
                                     "b12d602b9f43b53fa4de27d3dea86fcd.ics" :
@@ -859,6 +866,10 @@
                             {
                                 "calendar" :
                                 {
+                                    "@xattrs" :
+                                    {
+                                        resourceTypeAttr : zlib.compress("<?xml version='1.0' encoding='UTF-8'?><resourcetype xmlns='DAV:'><collection/><calendar xmlns='urn:ietf:params:xml:ns:caldav'/></resourcetype>\r\n"),
+                                    },
                                     "F18BA9DA-B1BA-4C94-9CB7-7E5BB7E30AE6.ics" :
                                     {
                                         "@contents" : event03_orig,
@@ -884,6 +895,10 @@
 
 
         after = {
+            ".calendarserver_version" :
+            {
+                "@contents" : "1",
+            },
             "calendars" :
             {
                 "__uids__" :
@@ -892,14 +907,18 @@
                     {
                         "23" :
                         {
-                            "6423F94A-6B76-4A3A-815B-D52CFD77935E" :
+                            "6423F94A-6B76-4A3A-815B-D52CFD77935D" :
                             {
                                 "calendar" :
                                 {
-                                    "F18BA9DA-B1BA-4C94-9CB7-7E5BB7E30AE6.ics" :
+                                    "*.ics" :
                                     {
-                                        "@contents" : event03_orig,
+                                        "@contents" : None,
                                     },
+                                    ".db.sqlite" :
+                                    {
+                                        "@contents" : None,
+                                    },
                                 },
                                 "inbox" :
                                 {
@@ -910,7 +929,17 @@
                                     "@xattrs" :
                                     {
                                         freeBusyAttr : zlib.compress("<?xml version='1.0' encoding='UTF-8'?>\r\n<calendar-free-busy-set xmlns='urn:ietf:params:xml:ns:caldav'>\r\n  <href xmlns='DAV:'>/calendars/__uids__/6423F94A-6B76-4A3A-815B-D52CFD77935D/calendar/</href>\r\n</calendar-free-busy-set>\r\n"),
+                                        cTagAttr : "*",
+                                        defaultCalendarAttr : "*",
                                     },
+                                    ".db.sqlite" :
+                                    {
+                                        "@contents" : None,
+                                    },
+                                    "*.ics" :
+                                    {
+                                        "@contents" : None,
+                                    },
                                 },
                             },
                             "64230DAD-0BDE-4508-8C77-15F0CA5C8DD1" :
@@ -954,8 +983,10 @@
         config.DocumentRoot = root
         config.DataRoot = root
 
+        # import pdb; pdb.set_trace()
         yield upgradeData(config)
 
+        # import pdb; pdb.set_trace()
         self.assertTrue(self.verifyHierarchy(root, after))
 
 

Modified: CalendarServer/branches/users/sagen/pending-invites-4389/twistedcaldav/test/util.py
===================================================================
--- CalendarServer/branches/users/sagen/pending-invites-4389/twistedcaldav/test/util.py	2009-06-30 18:48:39 UTC (rev 4400)
+++ CalendarServer/branches/users/sagen/pending-invites-4389/twistedcaldav/test/util.py	2009-06-30 22:51:53 UTC (rev 4401)
@@ -79,12 +79,17 @@
         def verifyChildren(parent, subStructure):
 
             actual = set([child for child in os.listdir(parent)])
+            wildcards = []
 
             for childName, childStructure in subStructure.iteritems():
 
                 if childName.startswith("@"):
                     continue
 
+                if childName.startswith("*"):
+                    wildcards.append((childName[1:], childStructure))
+                    continue
+
                 if childName in actual:
                     actual.remove(childName)
 
@@ -116,6 +121,9 @@
                     xattrs = childStructure["@xattrs"]
                     for attr, value in xattrs.iteritems():
                         if isinstance(value, str):
+                            if value == "*":
+                                continue
+
                             try:
                                 if xattr.getxattr(childPath, attr) != value:
                                     print "Xattr mismatch:", childPath, attr
@@ -132,6 +140,26 @@
                             return False
 
             if actual:
+                for childName in list(actual):
+                    childPath = os.path.join(parent, childName)
+                    for extension, childStructure in wildcards:
+                        if childName.endswith(extension):
+                            actual.remove(childName)
+                            if childStructure.has_key("@contents"):
+                                # This is a file
+                                if childStructure["@contents"] is None:
+                                    # We don't care about the contents
+                                    pass
+                                else:
+                                    with open(childPath) as child:
+                                        contents = child.read()
+                                        if contents != childStructure["@contents"]:
+                                            print "Contents mismatch:", childPath
+                                            print "Expected:\n%s\n\nActual:\n%s\n" % (childStructure["@contents"], contents)
+                                            return False
+
+
+            if actual:
                 # There are unexpected children
                 print "Unexpected:", actual
                 return False

Modified: CalendarServer/branches/users/sagen/pending-invites-4389/twistedcaldav/upgrade.py
===================================================================
--- CalendarServer/branches/users/sagen/pending-invites-4389/twistedcaldav/upgrade.py	2009-06-30 18:48:39 UTC (rev 4400)
+++ CalendarServer/branches/users/sagen/pending-invites-4389/twistedcaldav/upgrade.py	2009-06-30 22:51:53 UTC (rev 4401)
@@ -18,6 +18,8 @@
 
 from twisted.web2.dav.fileop import rmdir
 from twisted.web2.dav import davxml
+from twisted.web2.server import NoURLForResourceError
+from twisted.web2.http_headers import Headers
 from twisted.internet.defer import inlineCallbacks, returnValue, succeed
 from twistedcaldav.directory.directory import DirectoryService
 from twistedcaldav.directory.calendaruserproxy import CalendarUserProxyDatabase
@@ -28,7 +30,7 @@
 from twistedcaldav import caldavxml
 from twistedcaldav.scheduling.cuaddress import LocalCalendarUser
 from twistedcaldav.scheduling.scheduler import DirectScheduler
-from twistedcaldav.static import CalDAVFile
+from twistedcaldav.static import ScheduleInboxFile, CalendarHomeUIDProvisioningFile, CalendarHomeProvisioningFile, CalendarHomeFile
 from calendarserver.tools.util import getDirectory
 import xattr, os, zlib, hashlib, datetime, pwd, grp
 from zlib import compress
@@ -204,51 +206,81 @@
 
     class FakeRequest(object):
 
-        def __init__(self, root):
+        def __init__(self, calendarRootFile, root):
+            self.calendarRootFile = calendarRootFile
             self.root = root
+            self._resourcesByURL = {}
+            self._urlsByResource = {}
+            self.headers = Headers()
 
+
+        @inlineCallbacks
+        def _getChild(self, resource, segments):
+            if not segments:
+                returnValue(resource)
+
+            child, remaining = (yield resource.locateChild(self, segments))
+            returnValue((yield self._getChild(child, remaining)))
+
+        @inlineCallbacks
         def locateResource(self, url):
             url = url.strip("/")
-            return succeed(CalDAVFile(os.path.join(self.root, url)))
+            segments = url.split("/")
+            if segments[0] == "calendars":
+                resource = self.calendarRootFile
+                child = (yield self._getChild(resource, segments[1:]))
+                resource = child
+            else:
+                resource = None
 
+            if resource:
+                self._rememberResource(resource, url)
+            returnValue(resource)
+
         def _rememberResource(self, resource, url):
-            pass
+            self._resourcesByURL[url] = resource
+            self._urlsByResource[resource] = url
+            return resource
 
         def urlForResource(self, resource):
-            return resource.url()
+            url = self._urlsByResource.get(resource, None)
+            if url is None:
+                raise NoURLForResourceError(resource)
+            return url
 
+
     @inlineCallbacks
-    def processInbox(inboxPath, uuid, directory):
+    def processInbox(uidDir, homeFile, inboxFile, uuid, directory):
 
-        for ics in os.listdir(inboxPath):
+        for name in inboxFile.listChildren():
+            icsFile = inboxFile.getChild(name)
 
             cua = "urn:uuid:%s" % (uuid,)
             ownerPrincipal = directory.principalForCalendarUserAddress(cua)
             owner = LocalCalendarUser(cua, ownerPrincipal,
-                CalDAVFile(inboxPath), ownerPrincipal.scheduleInboxURL())
+                inboxFile, ownerPrincipal.scheduleInboxURL())
 
-            icsPath = os.path.join(inboxPath, ics)
-            log.debug("Processing inbox item: %s" % (icsPath,))
-            with open(icsPath) as icsFile:
-                data = icsFile.read()
-                calendar = Component.fromString(data)
+            # icsPath = os.path.join(inboxPath, ics)
+            # log.debug("Processing inbox item: %s" % (icsPath,))
+            data = icsFile.iCalendarText()
+            calendar = Component.fromString(data)
+            try:
+                method = calendar.propertyValue("METHOD")
+            except ValueError:
+                returnValue(None)
 
-                try:
-                    method = calendar.propertyValue("METHOD")
-                except ValueError:
-                    returnValue(None)
+            if method == "REPLY":
+                # originator is attendee sending reply
+                originator = calendar.getAttendees()
+            else:
+                # originator is the organizer
+                originator = calendar.getOrganizer()
+            originatorPrincipal = directory.principalForCalendarUserAddress(originator)
+            originator = LocalCalendarUser(originator, originatorPrincipal)
 
-                if method == "REPLY":
-                    # originator is attendee sending reply
-                    originator = calendar.getAttendees()
-                else:
-                    # originator is the organizer
-                    originator = calendar.getOrganizer()
-
             recipients = (owner,)
-            resource = CalDAVFile(icsPath)
-            scheduler = DirectScheduler(FakeRequest(config.DocumentRoot),
-                resource)
+            scheduler = DirectScheduler(FakeRequest(uidDir.parent, config.DocumentRoot),
+                icsFile)
             result = (yield scheduler.doSchedulingViaPUT(originator, recipients,
                 calendar, internal_request=False))
 
@@ -449,21 +481,34 @@
 
 
             # Process pending invitations
+            uidDir = CalendarHomeUIDProvisioningFile(uidHomes,
+                CalendarHomeProvisioningFile(calRoot, directory, "/calendars/"))
+
             for first in os.listdir(uidHomes):
                 if len(first) == 2:
                     firstPath = os.path.join(uidHomes, first)
+
                     for second in os.listdir(firstPath):
                         if len(second) == 2:
                             secondPath = os.path.join(firstPath, second)
-                            for home in os.listdir(secondPath):
-                                homePath = os.path.join(secondPath, home)
-                                inboxPath = os.path.join(homePath, "inbox")
-                                if os.path.exists(inboxPath):
-                                    yield processInbox(inboxPath,
-                                        home, directory)
 
+                            for uuid in os.listdir(secondPath):
+                                record = directory.recordWithUID(uuid)
+                                if not record:
+                                    continue
 
+                                homePath = os.path.join(secondPath, uuid)
+                                homeFile = CalendarHomeFile(homePath, uidDir,
+                                    record)
+                                inboxFile = homeFile.getChild("inbox")
+                                if inboxFile:
+                                    # inboxPath = os.path.join(homePath, "inbox")
+                                    # if os.path.exists(inboxPath):
+                                    yield processInbox(uidDir, homeFile, inboxFile, uuid,
+                                        directory)
 
+
+
     migrateResourceInfo(config, directory, uid, gid)
     createMailTokensDatabase(config, uid, gid)
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20090630/5665cc5d/attachment-0001.html>


More information about the calendarserver-changes mailing list