[CalendarServer-changes] [12241] CalendarServer/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Wed Mar 12 11:20:37 PDT 2014
Revision: 12241
http://trac.calendarserver.org//changeset/12241
Author: cdaboo at apple.com
Date: 2014-01-06 13:40:02 -0800 (Mon, 06 Jan 2014)
Log Message:
-----------
Allow event splitting at arbitrary recurrence-ids in the future. Add a calverify command to support a manual
split of a specific event.
Modified Paths:
--------------
CalendarServer/trunk/calendarserver/tools/calverify.py
CalendarServer/trunk/calendarserver/tools/test/test_calverify.py
CalendarServer/trunk/twistedcaldav/ical.py
CalendarServer/trunk/txdav/caldav/datastore/scheduling/icalsplitter.py
CalendarServer/trunk/txdav/caldav/datastore/scheduling/test/test_icalsplitter.py
CalendarServer/trunk/txdav/caldav/datastore/sql.py
Modified: CalendarServer/trunk/calendarserver/tools/calverify.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/calverify.py 2014-01-06 21:15:27 UTC (rev 12240)
+++ CalendarServer/trunk/calendarserver/tools/calverify.py 2014-01-06 21:40:02 UTC (rev 12241)
@@ -72,6 +72,9 @@
from twistedcaldav.util import normalizationLookup
from txdav.caldav.icalendarstore import ComponentUpdateState
+from txdav.caldav.datastore.scheduling.icalsplitter import iCalSplitter
+from txdav.caldav.datastore.scheduling.implicit import ImplicitScheduler
+from txdav.caldav.datastore.sql import CalendarStoreFeatures
from txdav.common.datastore.sql_tables import schema, _BIND_MODE_OWN
from txdav.common.icommondatastore import InternalDataStoreError
@@ -206,7 +209,7 @@
if not hasattr(Component, "maxAlarmCounts"):
Component.hasDuplicateAlarms = new_hasDuplicateAlarms
-VERSION = "10"
+VERSION = "11"
def printusage(e=None):
if e:
@@ -240,6 +243,7 @@
with either --ical or --mismatch.
--double : detect double-bookings.
--dark-purge : purge room/resource events with invalid organizer
+--split : split recurring event
--nuke PATH|RID : remove specific calendar resources - can
only be used by itself. PATH is the full
@@ -275,6 +279,10 @@
--summary : report only which GUIDs have double-bookings - no details.
--days : number of days ahead to scan [DEFAULT: 365]
+Options for --double:
+If none of (--no-organizer, --invalid-organizer, --disabled-organizer) is present, it
+will default to (--invalid-organizer, --disabled-organizer).
+
Options for --dark-purge:
--uuid : only scan specified calendar homes. Can be a partial GUID
@@ -285,9 +293,12 @@
--invalid-organizer : only detect events with an organizer not in the directory
--disabled-organizer : only detect events with an organizer disabled for calendaring
-If none of (--no-organizer, --invalid-organizer, --disabled-organizer) is present, it
-will default to (--invalid-organizer, --disabled-organizer).
+Options for --split:
+--path : URI path to resource to split.
+--rid : UTC date-time where split occurs (YYYYMMDDTHHMMSSZ).
+--summary : only print a list of recurrences in the resource - no splitting.
+
CHANGES
v8: Detects ORGANIZER or ATTENDEE properties with mailto: calendar user
addresses for users that have valid directory records. Fix is to
@@ -295,6 +306,10 @@
v9: Detects double-bookings.
+v10: Purges data for invalid users.
+
+v11: Allows manual splitting of recurring events.
+
""" % (VERSION,)
@@ -319,10 +334,11 @@
['missing', 'm', "Show 'orphaned' homes."],
['double', 'd', "Detect double-bookings."],
['dark-purge', 'p', "Purge room/resource events with invalid organizer."],
+ ['split', 'l', "Split an event."],
['fix', 'x', "Fix problems."],
['verbose', 'v', "Verbose logging."],
['details', 'V', "Detailed logging."],
- ['summary', 'S', "Summary of double-bookings."],
+ ['summary', 'S', "Summary of double-bookings/split."],
['tzid', 't', "Timezone to adjust displayed times to."],
['no-organizer', '', "Detect dark events without an organizer"],
@@ -335,7 +351,9 @@
['uuid', 'u', "", "Only check this user."],
['uid', 'U', "", "Only this event UID."],
['nuke', 'e', "", "Remove event given its path."],
- ['days', 'T', "365", "Number of days for scanning events into the future."]
+ ['days', 'T', "365", "Number of days for scanning events into the future."],
+ ['path', '', "", "Split event given its path."],
+ ['rid', '', "", "Split date-time."],
]
@@ -2670,6 +2688,122 @@
+class EventSplitService(CalVerifyService):
+ """
+ Service which splits a recurring event at a specific date-time value.
+ """
+
+ def title(self):
+ return "Event Split Service"
+
+
+ @inlineCallbacks
+ def doAction(self):
+ """
+ Split a resource using either its path or resource id.
+ """
+
+ self.txn = self.store.newTransaction()
+
+ path = self.options["path"]
+ if path.startswith("/calendars/__uids__/"):
+ try:
+ pathbits = path.split("/")
+ except TypeError:
+ printusage("Not a valid calendar object resource path: %s" % (path,))
+ if len(pathbits) != 6:
+ printusage("Not a valid calendar object resource path: %s" % (path,))
+ homeName = pathbits[3]
+ calendarName = pathbits[4]
+ resourceName = pathbits[5]
+
+ resid = yield self.getResourceID(homeName, calendarName, resourceName)
+ if resid is None:
+ yield self.txn.commit()
+ self.txn = None
+ self.output.write("\n")
+ self.output.write("Path does not exist. Nothing split.\n")
+ returnValue(None)
+ resid = int(resid)
+ else:
+ try:
+ resid = int(path)
+ except ValueError:
+ printusage("path argument must be a calendar object path or an SQL resource-id")
+
+ calendarObj = yield CalendarStoreFeatures(self.txn._store).calendarObjectWithID(self.txn, resid)
+ ical = yield calendarObj.component()
+
+ # Must be the ORGANIZER's copy
+ organizer = ical.getOrganizer()
+ if organizer is None:
+ printusage("Calendar object has no ORGANIZER property - cannot split")
+
+ # Only allow organizers to split
+ scheduler = ImplicitScheduler()
+ is_attendee = (yield scheduler.testAttendeeEvent(calendarObj.calendar(), calendarObj, ical,))
+ if is_attendee:
+ printusage("Calendar object is not owned by the ORGANIZER - cannot split")
+
+ if self.options["summary"]:
+ result = self.doSummary(ical)
+ else:
+ result = yield self.doSplit(resid, calendarObj, ical)
+
+ returnValue(result)
+
+
+ def doSummary(self, ical):
+ """
+ Print a summary of the recurrence instances of the specified event.
+
+ @param ical: calendar to process
+ @type ical: L{Component}
+ """
+ self.output.write("\n---- Calendar resource instances ----\n")
+
+ # Find the instance RECURRENCE-ID where a split is going to happen
+ now = DateTime.getNowUTC()
+ now.offsetDay(1)
+ instances = ical.cacheExpandedTimeRanges(now)
+ instances = sorted(instances.instances.values(), key=lambda x: x.start)
+ for instance in instances:
+ self.output.write(instance.rid.getText() + (" *\n" if instance.overridden else "\n"))
+
+
+ @inlineCallbacks
+ def doSplit(self, resid, calendarObj, ical):
+ rid = self.options["rid"]
+ try:
+ if rid[-1] != "Z":
+ raise ValueError
+ rid = DateTime.parseText(rid)
+ except ValueError:
+ printusage("rid must be a valid UTC date-time value: 'YYYYMMDDTHHMMSSZ'")
+
+ self.output.write("\n---- Splitting calendar resource ----\n")
+
+ # Find actual RECURRENCE-ID of split
+ splitter = iCalSplitter(1024, 14)
+ rid = splitter.whereSplit(ical, break_point=rid, allow_past_the_end=False)
+ if rid is None:
+ printusage("rid is not a valid recurrence instance")
+
+ self.output.write("\n")
+ self.output.write("Actual RECURRENCE-ID: %s.\n" % (rid,))
+
+ oldUID = yield calendarObj.split(rid=rid)
+
+ self.output.write("\n")
+ self.output.write("Split Resource: %s at %s, old UID: %s.\n" % (resid, rid, oldUID,))
+
+ yield self.txn.commit()
+ self.txn = None
+
+ returnValue(oldUID)
+
+
+
def main(argv=sys.argv, stderr=sys.stderr, reactor=None):
if reactor is None:
@@ -2702,6 +2836,8 @@
return DoubleBookingService(store, options, output, reactor, config)
elif options["dark-purge"]:
return DarkPurgeService(store, options, output, reactor, config)
+ elif options["split"]:
+ return EventSplitService(store, options, output, reactor, config)
else:
printusage("Invalid operation")
sys.exit(1)
Modified: CalendarServer/trunk/calendarserver/tools/test/test_calverify.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/test/test_calverify.py 2014-01-06 21:15:27 UTC (rev 12240)
+++ CalendarServer/trunk/calendarserver/tools/test/test_calverify.py 2014-01-06 21:40:02 UTC (rev 12241)
@@ -20,7 +20,8 @@
"""
from calendarserver.tools.calverify import BadDataService, \
- SchedulingMismatchService, DoubleBookingService, DarkPurgeService
+ SchedulingMismatchService, DoubleBookingService, DarkPurgeService, \
+ EventSplitService
from pycalendar.datetime import DateTime
@@ -28,6 +29,7 @@
from twisted.internet.defer import inlineCallbacks
from twistedcaldav.config import config
+from twistedcaldav.ical import normalize_iCalStr
from twistedcaldav.test.util import StoreTestCase
from txdav.common.datastore.test.util import populateCalendarsFrom
@@ -2806,3 +2808,322 @@
self.assertEqual(len(calverify.results["Dark Events"]), 0)
self.assertTrue("Fix dark events" not in calverify.results)
self.assertTrue("Fix remove" not in calverify.results)
+
+
+
+class CalVerifyEventPurge(CalVerifyMismatchTestsBase):
+ """
+ Tests calverify for events.
+ """
+
+ # No organizer
+ NO_ORGANIZER_ICS = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//Apple Inc.//iCal 4.0.1//EN
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+CREATED:20100303T181216Z
+UID:INVITE_NO_ORGANIZER_ICS
+TRANSP:OPAQUE
+SUMMARY:INVITE_NO_ORGANIZER_ICS
+DTSTART:%(now_fwd10)s
+DURATION:PT1H
+DTSTAMP:20100303T181220Z
+SEQUENCE:2
+END:VEVENT
+END:VCALENDAR
+""".replace("\n", "\r\n")
+
+ # Valid organizer
+ VALID_ORGANIZER_ICS = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//Apple Inc.//iCal 4.0.1//EN
+BEGIN:VEVENT
+UID:INVITE_VALID_ORGANIZER_ICS
+DTSTART:%(now)s
+DURATION:PT1H
+ATTENDEE:urn:uuid:%(uuid1)s
+ATTENDEE:urn:uuid:%(uuid2)s
+ORGANIZER:urn:uuid:%(uuid1)s
+RRULE:FREQ=DAILY
+SUMMARY:INVITE_VALID_ORGANIZER_ICS
+END:VEVENT
+END:VCALENDAR
+""".replace("\n", "\r\n")
+
+ # Valid attendee
+ VALID_ATTENDEE_ICS = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//Apple Inc.//iCal 4.0.1//EN
+BEGIN:VEVENT
+UID:INVITE_VALID_ORGANIZER_ICS
+DTSTART:%(now)s
+DURATION:PT1H
+ATTENDEE:urn:uuid:%(uuid1)s
+ATTENDEE:urn:uuid:%(uuid2)s
+ORGANIZER:urn:uuid:%(uuid1)s
+RRULE:FREQ=DAILY
+SUMMARY:INVITE_VALID_ORGANIZER_ICS
+END:VEVENT
+END:VCALENDAR
+""".replace("\n", "\r\n")
+
+ # Valid organizer
+ VALID_ORGANIZER_FUTURE_ICS = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//Apple Inc.//iCal 4.0.1//EN
+BEGIN:VEVENT
+UID:INVITE_VALID_ORGANIZER_ICS
+DTSTART:%(now_fwd11)s
+DURATION:PT1H
+ATTENDEE:urn:uuid:%(uuid1)s
+ATTENDEE:urn:uuid:%(uuid2)s
+ORGANIZER:urn:uuid:%(uuid1)s
+RELATED-TO;RELTYPE=X-CALENDARSERVER-RECURRENCE-SET:%(relID)s
+RRULE:FREQ=DAILY
+SEQUENCE:1
+SUMMARY:INVITE_VALID_ORGANIZER_ICS
+END:VEVENT
+END:VCALENDAR
+""".replace("\n", "\r\n")
+
+ # Valid attendee
+ VALID_ATTENDEE_FUTURE_ICS = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//Apple Inc.//iCal 4.0.1//EN
+BEGIN:VEVENT
+UID:INVITE_VALID_ORGANIZER_ICS
+DTSTART:%(now_fwd11)s
+DURATION:PT1H
+ATTENDEE:urn:uuid:%(uuid1)s
+ATTENDEE:urn:uuid:%(uuid2)s
+ORGANIZER:urn:uuid:%(uuid1)s
+RELATED-TO;RELTYPE=X-CALENDARSERVER-RECURRENCE-SET:%(relID)s
+RRULE:FREQ=DAILY
+SEQUENCE:1
+SUMMARY:INVITE_VALID_ORGANIZER_ICS
+END:VEVENT
+END:VCALENDAR
+""".replace("\n", "\r\n")
+
+ # Valid organizer
+ VALID_ORGANIZER_PAST_ICS = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//Apple Inc.//iCal 4.0.1//EN
+BEGIN:VEVENT
+UID:%(relID)s
+DTSTART:%(now)s
+DURATION:PT1H
+ATTENDEE:urn:uuid:%(uuid1)s
+ATTENDEE:urn:uuid:%(uuid2)s
+ORGANIZER:urn:uuid:%(uuid1)s
+RELATED-TO;RELTYPE=X-CALENDARSERVER-RECURRENCE-SET:%(relID)s
+RRULE:FREQ=DAILY;UNTIL=%(now_fwd11_1)s
+SEQUENCE:1
+SUMMARY:INVITE_VALID_ORGANIZER_ICS
+END:VEVENT
+END:VCALENDAR
+""".replace("\n", "\r\n")
+
+ # Valid attendee
+ VALID_ATTENDEE_PAST_ICS = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//Apple Inc.//iCal 4.0.1//EN
+BEGIN:VEVENT
+UID:%(relID)s
+DTSTART:%(now)s
+DURATION:PT1H
+ATTENDEE:urn:uuid:%(uuid1)s
+ATTENDEE:urn:uuid:%(uuid2)s
+ORGANIZER:urn:uuid:%(uuid1)s
+RELATED-TO;RELTYPE=X-CALENDARSERVER-RECURRENCE-SET:%(relID)s
+RRULE:FREQ=DAILY;UNTIL=%(now_fwd11_1)s
+SEQUENCE:1
+SUMMARY:INVITE_VALID_ORGANIZER_ICS
+END:VEVENT
+END:VCALENDAR
+""".replace("\n", "\r\n")
+
+ # Valid organizer
+ VALID_ORGANIZER_OVERRIDE_ICS = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//Apple Inc.//iCal 4.0.1//EN
+BEGIN:VEVENT
+UID:VALID_ORGANIZER_OVERRIDE_ICS
+DTSTART:%(now)s
+DURATION:PT1H
+ATTENDEE:urn:uuid:%(uuid1)s
+ATTENDEE:urn:uuid:%(uuid2)s
+ORGANIZER:urn:uuid:%(uuid1)s
+RRULE:FREQ=DAILY
+SUMMARY:INVITE_VALID_ORGANIZER_ICS
+END:VEVENT
+BEGIN:VEVENT
+UID:VALID_ORGANIZER_OVERRIDE_ICS
+RECURRENCE-ID:%(now_fwd11)s
+DTSTART:%(now_fwd11)s
+DURATION:PT2H
+ATTENDEE:urn:uuid:%(uuid1)s
+ATTENDEE:urn:uuid:%(uuid2)s
+ORGANIZER:urn:uuid:%(uuid1)s
+RRULE:FREQ=DAILY
+SUMMARY:INVITE_VALID_ORGANIZER_ICS
+END:VEVENT
+END:VCALENDAR
+""".replace("\n", "\r\n")
+
+ @inlineCallbacks
+ def setUp(self):
+
+ self.subs = {
+ "uuid1" : CalVerifyMismatchTestsBase.uuid1,
+ "uuid2" : CalVerifyMismatchTestsBase.uuid2,
+ }
+
+ self.now = DateTime.getNowUTC()
+ self.now.setHHMMSS(0, 0, 0)
+
+ self.subs["now"] = self.now
+
+ for i in range(30):
+ attrname = "now_back%s" % (i + 1,)
+ setattr(self, attrname, self.now.duplicate())
+ getattr(self, attrname).offsetDay(-(i + 1))
+ self.subs[attrname] = getattr(self, attrname)
+
+ attrname_12h = "now_back%s_12h" % (i + 1,)
+ setattr(self, attrname_12h, getattr(self, attrname).duplicate())
+ getattr(self, attrname_12h).offsetHours(12)
+ self.subs[attrname_12h] = getattr(self, attrname_12h)
+
+ attrname_1 = "now_back%s_1" % (i + 1,)
+ setattr(self, attrname_1, getattr(self, attrname).duplicate())
+ getattr(self, attrname_1).offsetSeconds(-1)
+ self.subs[attrname_1] = getattr(self, attrname_1)
+
+ for i in range(30):
+ attrname = "now_fwd%s" % (i + 1,)
+ setattr(self, attrname, self.now.duplicate())
+ getattr(self, attrname).offsetDay(i + 1)
+ self.subs[attrname] = getattr(self, attrname)
+
+ attrname_12h = "now_fwd%s_12h" % (i + 1,)
+ setattr(self, attrname_12h, getattr(self, attrname).duplicate())
+ getattr(self, attrname_12h).offsetHours(12)
+ self.subs[attrname_12h] = getattr(self, attrname_12h)
+
+ attrname_1 = "now_fwd%s_1" % (i + 1,)
+ setattr(self, attrname_1, getattr(self, attrname).duplicate())
+ getattr(self, attrname_1).offsetSeconds(-1)
+ self.subs[attrname_1] = getattr(self, attrname_1)
+
+ self.requirements = {
+ CalVerifyMismatchTestsBase.uuid1 : {
+ "calendar" : {
+ "invite1.ics" : (self.NO_ORGANIZER_ICS % self.subs, CalVerifyMismatchTestsBase.metadata,),
+ "invite2.ics" : (self.VALID_ORGANIZER_ICS % self.subs, CalVerifyMismatchTestsBase.metadata,),
+ "invite3.ics" : (self.VALID_ORGANIZER_OVERRIDE_ICS % self.subs, CalVerifyMismatchTestsBase.metadata,),
+ },
+ "inbox" : {},
+ },
+ CalVerifyMismatchTestsBase.uuid2 : {
+ "calendar" : {
+ "invite2a.ics" : (self.VALID_ATTENDEE_ICS % self.subs, CalVerifyMismatchTestsBase.metadata,),
+ },
+ "inbox" : {},
+ },
+ CalVerifyMismatchTestsBase.uuid3 : {
+ "calendar" : {},
+ "inbox" : {},
+ },
+ CalVerifyMismatchTestsBase.uuidl1 : {
+ "calendar" : {},
+ "inbox" : {},
+ },
+ }
+
+ yield super(CalVerifyEventPurge, self).setUp()
+
+
+ @inlineCallbacks
+ def test_validSplit(self):
+ """
+ CalVerifyService.doScan without fix for dark events. Make sure it detects
+ as much as it can. Make sure sync-token is not changed.
+ """
+
+ options = {
+ "nuke": False,
+ "missing": False,
+ "ical": False,
+ "mismatch": False,
+ "double": True,
+ "dark-purge": False,
+ "split": True,
+ "path": "/calendars/__uids__/%(uuid1)s/calendar/invite2.ics" % self.subs,
+ "rid": "%(now_fwd11)s" % self.subs,
+ "summary": False,
+ }
+ output = StringIO()
+ calverify = EventSplitService(self._sqlCalendarStore, options, output, reactor, config)
+ oldUID = yield calverify.doAction()
+
+ relsubs = dict(self.subs)
+ relsubs["relID"] = oldUID
+
+ calendar = yield self.calendarUnderTest(home=CalVerifyMismatchTestsBase.uuid1, name="calendar")
+ objs = yield calendar.listObjectResources()
+ self.assertEqual(len(objs), 4)
+ self.assertTrue("invite2.ics" in objs)
+ oldName = filter(lambda x: not x.startswith("invite"), objs)[0]
+
+ obj1 = yield calendar.objectResourceWithName("invite2.ics")
+ ical1 = yield obj1.component()
+ self.assertEqual(normalize_iCalStr(ical1), self.VALID_ORGANIZER_FUTURE_ICS % relsubs)
+
+ obj2 = yield calendar.objectResourceWithName(oldName)
+ ical2 = yield obj2.component()
+ self.assertEqual(normalize_iCalStr(ical2), self.VALID_ORGANIZER_PAST_ICS % relsubs)
+
+ calendar = yield self.calendarUnderTest(home=CalVerifyMismatchTestsBase.uuid2, name="calendar")
+ objs = yield calendar.listObjectResources()
+ self.assertEqual(len(objs), 2)
+ self.assertTrue("invite2a.ics" in objs)
+ oldName = filter(lambda x: not x.startswith("invite"), objs)[0]
+
+ obj1 = yield calendar.objectResourceWithName("invite2a.ics")
+ ical1 = yield obj1.component()
+ self.assertEqual(normalize_iCalStr(ical1), self.VALID_ATTENDEE_FUTURE_ICS % relsubs)
+
+ obj2 = yield calendar.objectResourceWithName(oldName)
+ ical2 = yield obj2.component()
+ self.assertEqual(normalize_iCalStr(ical2), self.VALID_ATTENDEE_PAST_ICS % relsubs)
+
+
+ @inlineCallbacks
+ def test_summary(self):
+ """
+ CalVerifyService.doScan without fix for dark events. Make sure it detects
+ as much as it can. Make sure sync-token is not changed.
+ """
+
+ options = {
+ "nuke": False,
+ "missing": False,
+ "ical": False,
+ "mismatch": False,
+ "double": True,
+ "dark-purge": False,
+ "split": True,
+ "path": "/calendars/__uids__/%(uuid1)s/calendar/invite3.ics" % self.subs,
+ "rid": "%(now_fwd11)s" % self.subs,
+ "summary": True,
+ }
+ output = StringIO()
+ calverify = EventSplitService(self._sqlCalendarStore, options, output, reactor, config)
+ yield calverify.doAction()
+ result = output.getvalue().splitlines()
+ self.assertTrue("%(now)s" % self.subs in result)
+ self.assertTrue("%(now_fwd10)s" % self.subs in result)
+ self.assertTrue("%(now_fwd11)s *" % self.subs in result)
+ self.assertTrue("%(now_fwd12)s" % self.subs in result)
Modified: CalendarServer/trunk/twistedcaldav/ical.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/ical.py 2014-01-06 21:15:27 UTC (rev 12240)
+++ CalendarServer/trunk/twistedcaldav/ical.py 2014-01-06 21:40:02 UTC (rev 12241)
@@ -3645,7 +3645,7 @@
icalstr = str(icalstr).replace("\r\n ", "")
icalstr = icalstr.replace("\n ", "")
icalstr = "\r\n".join([line for line in icalstr.splitlines() if not line.startswith("DTSTAMP")])
- return icalstr
+ return icalstr + "\r\n"
Modified: CalendarServer/trunk/txdav/caldav/datastore/scheduling/icalsplitter.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/scheduling/icalsplitter.py 2014-01-06 21:15:27 UTC (rev 12240)
+++ CalendarServer/trunk/txdav/caldav/datastore/scheduling/icalsplitter.py 2014-01-06 21:40:02 UTC (rev 12241)
@@ -83,17 +83,21 @@
return len(str(ical)) > self.threshold
- def whereSplit(self, ical):
+ def whereSplit(self, ical, break_point=None, allow_past_the_end=True):
"""
Determine where a split is going to happen - i.e., the RECURRENCE-ID.
@param ical: the iCalendar object to test
@type ical: L{Component}
+ @param break_point: the date-time where the break should occur
+ @type break_point: L{DateTime}
@return: recurrence-id of the split
@rtype: L{DateTime}
"""
+ break_point = self.past if break_point is None else break_point
+
# Find the instance RECURRENCE-ID where a split is going to happen
now = self.now.duplicate()
now.offsetDay(1)
@@ -102,13 +106,13 @@
rid = instances[0].rid
for instance in instances:
rid = instance.rid
- if instance.start >= self.past:
+ if instance.start >= break_point:
break
else:
- # We can get here when splitting and event for overrides only in the past,
+ # We can get here when splitting an event for overrides only in the past,
# which happens when splitting an Attendee's copy of an Organizer event
# where the Organizer event has L{willSplit} == C{True}
- rid = self.past
+ rid = break_point if allow_past_the_end else None
return rid
Modified: CalendarServer/trunk/txdav/caldav/datastore/scheduling/test/test_icalsplitter.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/scheduling/test/test_icalsplitter.py 2014-01-06 21:15:27 UTC (rev 12240)
+++ CalendarServer/trunk/txdav/caldav/datastore/scheduling/test/test_icalsplitter.py 2014-01-06 21:40:02 UTC (rev 12241)
@@ -63,6 +63,11 @@
getattr(self, attrname_12h).offsetHours(12)
self.subs[attrname_12h] = getattr(self, attrname_12h)
+ attrname_1 = "now_fwd%s_1" % (i + 1,)
+ setattr(self, attrname_1, getattr(self, attrname).duplicate())
+ getattr(self, attrname_1).offsetSeconds(-1)
+ self.subs[attrname_1] = getattr(self, attrname_1)
+
self.patch(config, "MaxAllowedInstances", 500)
@@ -2018,3 +2023,188 @@
# Make sure new items won't split again
self.assertFalse(splitter.willSplit(icalNew), "Failed future will split: %s" % (title,))
self.assertFalse(splitter.willSplit(icalOld), "Failed past will split: %s" % (title,))
+
+
+ def test_future_split(self):
+
+ data = (
+ (
+ "1.1 - RRULE with override",
+ """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTART:%(now)s
+DURATION:PT1H
+ATTENDEE:mailto:user1 at example.com
+ATTENDEE:mailto:user2 at example.com
+ATTENDEE:mailto:user3 at example.com
+ATTENDEE:mailto:user4 at example.com
+ATTENDEE:mailto:user5 at example.com
+ATTENDEE:mailto:user6 at example.com
+ATTENDEE:mailto:user7 at example.com
+ATTENDEE:mailto:user8 at example.com
+ATTENDEE:mailto:user9 at example.com
+ATTENDEE:mailto:user10 at example.com
+ATTENDEE:mailto:user11 at example.com
+ATTENDEE:mailto:user12 at example.com
+ATTENDEE:mailto:user13 at example.com
+ATTENDEE:mailto:user14 at example.com
+ATTENDEE:mailto:user15 at example.com
+ATTENDEE:mailto:user16 at example.com
+ATTENDEE:mailto:user17 at example.com
+ATTENDEE:mailto:user18 at example.com
+ATTENDEE:mailto:user19 at example.com
+ATTENDEE:mailto:user20 at example.com
+ATTENDEE:mailto:user21 at example.com
+ATTENDEE:mailto:user22 at example.com
+ATTENDEE:mailto:user23 at example.com
+ATTENDEE:mailto:user24 at example.com
+ATTENDEE:mailto:user25 at example.com
+ORGANIZER:mailto:user1 at example.com
+RRULE:FREQ=DAILY
+END:VEVENT
+BEGIN:VEVENT
+UID:12345-67890
+RECURRENCE-ID:%(now_fwd10)s
+DTSTART:%(now_fwd10)s
+DURATION:PT1H
+ATTENDEE:mailto:user1 at example.com
+ATTENDEE:mailto:user2 at example.com
+ORGANIZER:mailto:user1 at example.com
+END:VEVENT
+BEGIN:VEVENT
+UID:12345-67890
+RECURRENCE-ID:%(now_fwd11)s
+DTSTART:%(now_fwd11)s
+DURATION:PT1H
+ATTENDEE:mailto:user1 at example.com
+ATTENDEE:mailto:user2 at example.com
+ORGANIZER:mailto:user1 at example.com
+END:VEVENT
+END:VCALENDAR
+""",
+ """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTART:%(now_fwd11)s
+DURATION:PT1H
+ATTENDEE:mailto:user1 at example.com
+ATTENDEE:mailto:user2 at example.com
+ATTENDEE:mailto:user3 at example.com
+ATTENDEE:mailto:user4 at example.com
+ATTENDEE:mailto:user5 at example.com
+ATTENDEE:mailto:user6 at example.com
+ATTENDEE:mailto:user7 at example.com
+ATTENDEE:mailto:user8 at example.com
+ATTENDEE:mailto:user9 at example.com
+ATTENDEE:mailto:user10 at example.com
+ATTENDEE:mailto:user11 at example.com
+ATTENDEE:mailto:user12 at example.com
+ATTENDEE:mailto:user13 at example.com
+ATTENDEE:mailto:user14 at example.com
+ATTENDEE:mailto:user15 at example.com
+ATTENDEE:mailto:user16 at example.com
+ATTENDEE:mailto:user17 at example.com
+ATTENDEE:mailto:user18 at example.com
+ATTENDEE:mailto:user19 at example.com
+ATTENDEE:mailto:user20 at example.com
+ATTENDEE:mailto:user21 at example.com
+ATTENDEE:mailto:user22 at example.com
+ATTENDEE:mailto:user23 at example.com
+ATTENDEE:mailto:user24 at example.com
+ATTENDEE:mailto:user25 at example.com
+ORGANIZER:mailto:user1 at example.com
+RELATED-TO;RELTYPE=X-CALENDARSERVER-RECURRENCE-SET:%(relID)s
+RRULE:FREQ=DAILY
+END:VEVENT
+BEGIN:VEVENT
+UID:12345-67890
+RECURRENCE-ID:%(now_fwd11)s
+DTSTART:%(now_fwd11)s
+DURATION:PT1H
+ATTENDEE:mailto:user1 at example.com
+ATTENDEE:mailto:user2 at example.com
+ORGANIZER:mailto:user1 at example.com
+RELATED-TO;RELTYPE=X-CALENDARSERVER-RECURRENCE-SET:%(relID)s
+END:VEVENT
+END:VCALENDAR
+""",
+ """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:%(relID)s
+DTSTART:%(now)s
+DURATION:PT1H
+ATTENDEE:mailto:user1 at example.com
+ATTENDEE:mailto:user2 at example.com
+ATTENDEE:mailto:user3 at example.com
+ATTENDEE:mailto:user4 at example.com
+ATTENDEE:mailto:user5 at example.com
+ATTENDEE:mailto:user6 at example.com
+ATTENDEE:mailto:user7 at example.com
+ATTENDEE:mailto:user8 at example.com
+ATTENDEE:mailto:user9 at example.com
+ATTENDEE:mailto:user10 at example.com
+ATTENDEE:mailto:user11 at example.com
+ATTENDEE:mailto:user12 at example.com
+ATTENDEE:mailto:user13 at example.com
+ATTENDEE:mailto:user14 at example.com
+ATTENDEE:mailto:user15 at example.com
+ATTENDEE:mailto:user16 at example.com
+ATTENDEE:mailto:user17 at example.com
+ATTENDEE:mailto:user18 at example.com
+ATTENDEE:mailto:user19 at example.com
+ATTENDEE:mailto:user20 at example.com
+ATTENDEE:mailto:user21 at example.com
+ATTENDEE:mailto:user22 at example.com
+ATTENDEE:mailto:user23 at example.com
+ATTENDEE:mailto:user24 at example.com
+ATTENDEE:mailto:user25 at example.com
+ORGANIZER:mailto:user1 at example.com
+RELATED-TO;RELTYPE=X-CALENDARSERVER-RECURRENCE-SET:%(relID)s
+RRULE:FREQ=DAILY;UNTIL=%(now_fwd11_1)s
+END:VEVENT
+BEGIN:VEVENT
+UID:%(relID)s
+RECURRENCE-ID:%(now_fwd10)s
+DTSTART:%(now_fwd10)s
+DURATION:PT1H
+ATTENDEE:mailto:user1 at example.com
+ATTENDEE:mailto:user2 at example.com
+ORGANIZER:mailto:user1 at example.com
+RELATED-TO;RELTYPE=X-CALENDARSERVER-RECURRENCE-SET:%(relID)s
+END:VEVENT
+END:VCALENDAR
+""",
+ ),
+ )
+
+ for title, calendar, split_future, split_past in data:
+ ical = Component.fromString(calendar % self.subs)
+ splitter = iCalSplitter(1024, 14)
+ icalOld, icalNew = splitter.split(ical, rid=DateTime.parseText("%(now_fwd11)s" % self.subs))
+ relsubs = dict(self.subs)
+ relsubs["relID"] = icalOld.resourceUID()
+ self.assertEqual(str(icalNew).replace("\r\n ", ""), split_future.replace("\n", "\r\n") % relsubs, "Failed future: %s" % (title,))
+ self.assertEqual(str(icalOld).replace("\r\n ", ""), split_past.replace("\n", "\r\n") % relsubs, "Failed past: %s" % (title,))
+
+ # Make sure new items won't split again
+ self.assertFalse(splitter.willSplit(icalNew), "Failed future will split: %s" % (title,))
+ self.assertFalse(splitter.willSplit(icalOld), "Failed past will split: %s" % (title,))
+
+ ical = Component.fromString(calendar % self.subs)
+ splitter = iCalSplitter(1024, 14)
+ icalOld, icalNew = splitter.split(ical, rid=splitter.whereSplit(ical, break_point=DateTime.parseText("%(now_fwd10_12h)s" % self.subs)))
+ relsubs = dict(self.subs)
+ relsubs["relID"] = icalOld.resourceUID()
+ self.assertEqual(str(icalNew).replace("\r\n ", ""), split_future.replace("\n", "\r\n") % relsubs, "Failed future: %s" % (title,))
+ self.assertEqual(str(icalOld).replace("\r\n ", ""), split_past.replace("\n", "\r\n") % relsubs, "Failed past: %s" % (title,))
+
+ # Make sure new items won't split again
+ self.assertFalse(splitter.willSplit(icalNew), "Failed future will split: %s" % (title,))
+ self.assertFalse(splitter.willSplit(icalOld), "Failed past will split: %s" % (title,))
Modified: CalendarServer/trunk/txdav/caldav/datastore/sql.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/sql.py 2014-01-06 21:15:27 UTC (rev 12240)
+++ CalendarServer/trunk/txdav/caldav/datastore/sql.py 2014-01-06 21:40:02 UTC (rev 12241)
@@ -366,7 +366,7 @@
@inlineCallbacks
def calendarObjectWithID(self, txn, rid):
"""
- Return all child object resources with the specified UID. Only "owned" resources are returned,
+ Return all child object resources with the specified resource id. Only "owned" resources are returned,
no shared resources.
@param txn: transaction to use
@@ -378,7 +378,7 @@
@rtype: L{CalendarObject} or C{None}
"""
- # First find the resource-ids of the (home, parent, object) for each object matching the UID.
+ # First find the resource-ids of the (home, parent, object) for each object matching the resource id.
obj = CalendarHome._objectSchema
bind = CalendarHome._bindSchema
rows = (yield Select(
@@ -3684,6 +3684,8 @@
if will:
notBefore = datetime.datetime.utcnow() + datetime.timedelta(seconds=config.Scheduling.Options.Splitting.Delay)
work = (yield self._txn.enqueue(CalendarObject.CalendarObjectSplitterWork, resourceID=self._resourceID, notBefore=notBefore))
+
+ # _workItems is used during unit testing only, to track the created work
if not hasattr(self, "_workItems"):
self._workItems = []
self._workItems.append(work)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/dc7c68d7/attachment.html>
More information about the calendarserver-changes
mailing list