[CalendarServer-changes] [1837]
CalendarServer/branches/users/cdaboo/better-itip-1835/twistedcaldav/
itip.py
source_changes at macosforge.org
source_changes at macosforge.org
Fri Aug 31 20:27:50 PDT 2007
Revision: 1837
http://trac.macosforge.org/projects/calendarserver/changeset/1837
Author: cdaboo at apple.com
Date: 2007-08-31 20:27:49 -0700 (Fri, 31 Aug 2007)
Log Message:
-----------
Refactor a bunch of code that is common to REQUEST and CANCEL processing.
Modified Paths:
--------------
CalendarServer/branches/users/cdaboo/better-itip-1835/twistedcaldav/itip.py
Modified: CalendarServer/branches/users/cdaboo/better-itip-1835/twistedcaldav/itip.py
===================================================================
--- CalendarServer/branches/users/cdaboo/better-itip-1835/twistedcaldav/itip.py 2007-09-01 01:13:20 UTC (rev 1836)
+++ CalendarServer/branches/users/cdaboo/better-itip-1835/twistedcaldav/itip.py 2007-09-01 03:27:49 UTC (rev 1837)
@@ -131,58 +131,20 @@
if not has_rid:
# Compare the new one with each existing one.
- delete_child = False
- for i in info:
- # For any that are older, delete them.
- if compareSyncInfo(i, newinfo) < 0:
- try:
- d = waitForDeferred(deleteResource(inbox, i[0]))
- yield d
- d.getResult()
- logging.info("[ITIP]: deleted iTIP message %s in Inbox that was older than the new one." % (i[0],))
- except:
- log.err("Error while auto-processing iTIP: %s" % (failure.Failure(),))
- raise iTipException
- else:
- # For any that are newer or the same, mark the new one to be deleted.
- delete_child = True
+ d = waitForDeferred(processOthersInInbox(info, newinfo, inbox, child))
+ yield d
+ delete_child = d.getResult()
- # Delete the new one if so marked.
if delete_child:
- try:
- d = waitForDeferred(deleteResource(inbox, child.fp.basename()))
- yield d
- d.getResult()
- logging.info("[ITIP]: deleted new iTIP message %s in Inbox because it was older than existing ones." % (child.fp.basename(),))
- except:
- log.err("Error while auto-processing iTIP: %s" % (failure.Failure(),))
- raise iTipException
yield None
return
# Next we want to try and find a match to any components on existing calendars listed as contributing
# to free-busy as we will need to update those with the new one.
+ d = waitForDeferred(findCalendarMatch(request, principal, calendar))
+ yield d
+ calmatch, updatecal, calURL = d.getResult()
- # Find the current recipients calendar-free-busy-set
- fbset = waitForDeferred(principal.calendarFreeBusyURIs(request))
- yield fbset
- fbset = fbset.getResult()
-
- # Find the first calendar in the list with a component matching the one we are processing
- calmatch = None
- for calURL in fbset:
- updatecal = waitForDeferred(request.locateResource(calURL))
- yield updatecal
- updatecal = updatecal.getResult()
- if updatecal is None or not updatecal.exists() or not isCalendarCollectionResource(updatecal):
- # We will ignore missing calendars. If the recipient has failed to
- # properly manage the free busy set that should not prevent us from working.
- continue
- calmatch = matchComponentInCalendar(updatecal, calendar, None)
- if calmatch:
- logging.info("[ITIP]: found calendar component %s matching new iTIP message in %s." % (calmatch[0], calURL))
- break
-
# If we have a match then we need to check whether we are updating etc
d = waitForDeferred(checkForReply(request, principal, calendar))
yield d
@@ -223,8 +185,7 @@
return
else:
# Write new resource into first calendar in f-b-set
- if len(fbset) != 0 and accepted:
- calURL = fbset[0]
+ if calURL and accepted:
updatecal = waitForDeferred(request.locateResource(calURL))
yield updatecal
updatecal = updatecal.getResult()
@@ -333,58 +294,20 @@
if not has_rid:
# Compare the new one with each existing one.
- delete_child = False
- for i in info:
- # For any that are older, delete them.
- if compareSyncInfo(i, newinfo) < 0:
- try:
- d = waitForDeferred(deleteResource(inbox, i[0]))
- yield d
- d.getResult()
- logging.info("[ITIP]: deleted iTIP message %s in Inbox that was older than the new one." % (i[0],))
- except:
- log.err("Error while auto-processing iTIP: %s" % (failure.Failure(),))
- raise iTipException
- else:
- # For any that are newer or the same, mark the new one to be deleted.
- delete_child = True
+ d = waitForDeferred(processOthersInInbox(info, newinfo, inbox, child))
+ yield d
+ delete_child = d.getResult()
- # Delete the new one if so marked.
if delete_child:
- try:
- d = waitForDeferred(deleteResource(inbox, child.fp.basename()))
- yield d
- d.getResult()
- logging.info("[ITIP]: deleted new iTIP message %s in Inbox because it was older than existing ones." % (child.fp.basename(),))
- except:
- log.err("Error while auto-processing iTIP: %s" % (failure.Failure(),))
- raise iTipException
yield None
return
# Next we want to try and find a match to any components on existing calendars listed as contributing
# to free-busy as we will need to update those with the new one.
+ d = waitForDeferred(findCalendarMatch(request, principal, calendar))
+ yield d
+ calmatch, updatecal, calURL = d.getResult()
- # Find the current recipients calendar-free-busy-set
- fbset = waitForDeferred(principal.calendarFreeBusyURIs(request))
- yield fbset
- fbset = fbset.getResult()
-
- # Find the first calendar in the list with a component matching the one we are processing
- calmatch = None
- for calURL in fbset:
- updatecal = waitForDeferred(request.locateResource(calURL))
- yield updatecal
- updatecal = updatecal.getResult()
- if updatecal is None or not updatecal.exists() or not isCalendarCollectionResource(updatecal):
- # We will ignore missing calendars. If the recipient has failed to
- # properly manage the free busy set that should not prevent us from working.
- continue
- calmatch = matchComponentInCalendar(updatecal, calendar, None)
- if calmatch:
- logging.info("[ITIP]: found calendar component %s matching new iTIP message in %s." % (calmatch[0], calURL))
- break
-
# If we have a match then we need to check whether we are updating etc
if calmatch:
# See whether the current component is older than any existing ones and throw it away if so
@@ -415,21 +338,22 @@
else:
# Nothing to do
pass
-
- # Remove the now processed incoming request.
- try:
- d = waitForDeferred(deleteResource(inbox, child.fp.basename()))
- yield d
- d.getResult()
- logging.info("[ITIP]: deleted new iTIP message %s in Inbox because it has been processed." % (child.fp.basename(),))
- except:
- log.err("Error while auto-processing iTIP: %s" % (failure.Failure(),))
- raise iTipException
- yield None
- return
else:
raise NotImplementedError
+
+ # Remove the now processed incoming request.
+ try:
+ d = waitForDeferred(deleteResource(inbox, child.fp.basename()))
+ yield d
+ d.getResult()
+ logging.info("[ITIP]: deleted new iTIP message %s in Inbox because it has been processed." % (child.fp.basename(),))
+ except:
+ log.err("Error while auto-processing iTIP: %s" % (failure.Failure(),))
+ raise iTipException
+ yield None
+ return
+
processCancel = deferredGenerator(processCancel)
def checkForReply(request, principal, calendar):
@@ -701,6 +625,72 @@
return True
+def processOthersInInbox(info, newinfo, inbox, child):
+ # Compare the new one with each existing one.
+ delete_child = False
+ for i in info:
+ # For any that are older, delete them.
+ if compareSyncInfo(i, newinfo) < 0:
+ try:
+ d = waitForDeferred(deleteResource(inbox, i[0]))
+ yield d
+ d.getResult()
+ logging.info("[ITIP]: deleted iTIP message %s in Inbox that was older than the new one." % (i[0],))
+ except:
+ log.err("Error while auto-processing iTIP: %s" % (failure.Failure(),))
+ raise iTipException
+ else:
+ # For any that are newer or the same, mark the new one to be deleted.
+ delete_child = True
+
+ # Delete the new one if so marked.
+ if delete_child:
+ try:
+ d = waitForDeferred(deleteResource(inbox, child.fp.basename()))
+ yield d
+ d.getResult()
+ logging.info("[ITIP]: deleted new iTIP message %s in Inbox because it was older than existing ones." % (child.fp.basename(),))
+ except:
+ log.err("Error while auto-processing iTIP: %s" % (failure.Failure(),))
+ raise iTipException
+
+ yield delete_child
+
+processOthersInInbox = deferredGenerator(processOthersInInbox)
+
+def findCalendarMatch(request, principal, calendar):
+ # Try and find a match to any components on existing calendars listed as contributing
+ # to free-busy as we will need to update those with the new one.
+
+ # Find the current recipients calendar-free-busy-set
+ fbset = waitForDeferred(principal.calendarFreeBusyURIs(request))
+ yield fbset
+ fbset = fbset.getResult()
+
+ # Find the first calendar in the list with a component matching the one we are processing
+ calmatch = None
+ updatecal = None
+ calURL = None
+ for calURL in fbset:
+ updatecal = waitForDeferred(request.locateResource(calURL))
+ yield updatecal
+ updatecal = updatecal.getResult()
+ if updatecal is None or not updatecal.exists() or not isCalendarCollectionResource(updatecal):
+ # We will ignore missing calendars. If the recipient has failed to
+ # properly manage the free busy set that should not prevent us from working.
+ continue
+ calmatch = matchComponentInCalendar(updatecal, calendar, None)
+ if calmatch:
+ logging.info("[ITIP]: found calendar component %s matching new iTIP message in %s." % (calmatch[0], calURL))
+ break
+
+ if not calmatch and len(fbset):
+ calURL = fbset[0]
+
+ yield calmatch, updatecal, calURL
+
+findCalendarMatch = deferredGenerator(findCalendarMatch)
+
def matchComponentInCalendar(collection, calendar, ignore):
"""
See if the component in the provided iTIP calendar object matches any in the specified calendar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20070831/83ed632b/attachment.html
More information about the calendarserver-changes
mailing list