[CalendarServer-changes] [14523] CalendarServer/branches/users/sagen/trashcan-5/txdav/caldav/ datastore
source_changes at macosforge.org
source_changes at macosforge.org
Fri Mar 6 14:00:19 PST 2015
Revision: 14523
http://trac.calendarserver.org//changeset/14523
Author: sagen at apple.com
Date: 2015-03-06 14:00:19 -0800 (Fri, 06 Mar 2015)
Log Message:
-----------
willSplit now also returns an 'is fully in future' flag
Modified Paths:
--------------
CalendarServer/branches/users/sagen/trashcan-5/txdav/caldav/datastore/scheduling/icalsplitter.py
CalendarServer/branches/users/sagen/trashcan-5/txdav/caldav/datastore/scheduling/test/test_icalsplitter.py
CalendarServer/branches/users/sagen/trashcan-5/txdav/caldav/datastore/sql.py
Modified: CalendarServer/branches/users/sagen/trashcan-5/txdav/caldav/datastore/scheduling/icalsplitter.py
===================================================================
--- CalendarServer/branches/users/sagen/trashcan-5/txdav/caldav/datastore/scheduling/icalsplitter.py 2015-03-06 21:42:49 UTC (rev 14522)
+++ CalendarServer/branches/users/sagen/trashcan-5/txdav/caldav/datastore/scheduling/icalsplitter.py 2015-03-06 22:00:19 UTC (rev 14523)
@@ -54,13 +54,19 @@
@param ical: the iCalendar object to examine
@type ical: L{Component}
- @return: C{True} if a split is require, C{False} otherwise
- @rtype: C{bool}
+ @return: A tuple of two booleans:
+ C{True} if a split is required
+ C{True} if event is fully in future
+ The second boolean's value is undefined if the first is True or
+ the event is not recurring, or threshold != -1
+ @rtype: C{tuple} of two C{bool}
"""
+ fullyInFuture = False
+
# Must be recurring
if not ical.isRecurring():
- return False
+ return (False, False)
# Look for past/future (cacheExpandedTimeRanges will go one year in the future by default)
now = self.now.duplicate()
@@ -68,7 +74,13 @@
instances = ical.cacheExpandedTimeRanges(now)
instances = sorted(instances.instances.values(), key=lambda x: x.start)
if len(instances) <= 1 or instances[0].start >= self.past or instances[-1].start < self.now:
- return False
+ # Event is either fully in past or in future
+ if len(instances) == 0 or instances[0].start >= now:
+ # fully in future
+ fullyInFuture = True
+ else:
+ fullyInFuture = False
+ return (False, fullyInFuture)
if self.threshold != -1:
# Make sure there are some overridden components in the past - as splitting only makes sense when
@@ -82,13 +94,13 @@
# Only split when there is more than one past override to split off
if past_count < 2:
- return False
+ return (False, False)
# Now see if overall size exceeds our threshold
- return len(str(ical)) > self.threshold
+ return (len(str(ical)) > self.threshold, False)
else:
- return True
+ return (True, False)
def whereSplit(self, ical, break_point=None, allow_past_the_end=True):
Modified: CalendarServer/branches/users/sagen/trashcan-5/txdav/caldav/datastore/scheduling/test/test_icalsplitter.py
===================================================================
--- CalendarServer/branches/users/sagen/trashcan-5/txdav/caldav/datastore/scheduling/test/test_icalsplitter.py 2015-03-06 21:42:49 UTC (rev 14522)
+++ CalendarServer/branches/users/sagen/trashcan-5/txdav/caldav/datastore/scheduling/test/test_icalsplitter.py 2015-03-06 22:00:19 UTC (rev 14523)
@@ -95,7 +95,7 @@
END:VEVENT
END:VCALENDAR
""",
- False,
+ (False, False),
),
(
"#1.2 Large, old, non-recurring component",
@@ -135,7 +135,7 @@
END:VEVENT
END:VCALENDAR
""",
- False,
+ (False, False),
),
(
"#2.1 Small, old, simple recurring component",
@@ -153,7 +153,7 @@
END:VEVENT
END:VCALENDAR
""",
- False,
+ (False, False),
),
(
"#2.2 Large, old, simple recurring component",
@@ -194,7 +194,7 @@
END:VEVENT
END:VCALENDAR
""",
- False,
+ (False, False),
),
(
"#2.3 Small, more than a year in the future, simple recurring component",
@@ -212,7 +212,7 @@
END:VEVENT
END:VCALENDAR
""",
- False,
+ (False, True),
),
(
"#2.4 Small, all cancelled, simple recurring component",
@@ -232,7 +232,7 @@
END:VEVENT
END:VCALENDAR
""",
- False,
+ (False, True),
),
(
"#3.1 Small, old, recurring with future override",
@@ -259,7 +259,7 @@
END:VEVENT
END:VCALENDAR
""",
- False,
+ (False, False),
),
(
"#3.2 Large, old, recurring component with future override",
@@ -309,7 +309,7 @@
END:VEVENT
END:VCALENDAR
""",
- False,
+ (False, False),
),
(
"#4.1 Small, old, recurring with past override",
@@ -336,7 +336,7 @@
END:VEVENT
END:VCALENDAR
""",
- False,
+ (False, False),
),
(
"#4.2 Large, old, recurring component with one past override",
@@ -386,7 +386,7 @@
END:VEVENT
END:VCALENDAR
""",
- False,
+ (False, False),
),
(
"#4.2 Large, old, recurring component with two past overrides",
@@ -445,7 +445,7 @@
END:VEVENT
END:VCALENDAR
""",
- True,
+ (True, False),
),
(
"#5.1 Small, old, limited recurring with past override",
@@ -472,7 +472,7 @@
END:VEVENT
END:VCALENDAR
""",
- False,
+ (False, False),
),
(
"#5.2 Large, old, limited recurring component with past override",
@@ -522,7 +522,7 @@
END:VEVENT
END:VCALENDAR
""",
- False,
+ (False, False),
),
(
"#6.1 Small, old, limited future recurring with past override",
@@ -549,7 +549,7 @@
END:VEVENT
END:VCALENDAR
""",
- False,
+ (False, False),
),
(
"#6.2 Large, old, limited future recurring component with two past overrides",
@@ -608,7 +608,7 @@
END:VEVENT
END:VCALENDAR
""",
- True,
+ (True, False),
),
)
@@ -616,8 +616,8 @@
ical = Component.fromString(calendar % self.subs)
splitter = iCalSplitter(1024, 14)
- will_split = splitter.willSplit(ical)
- self.assertEqual(will_split, result, msg="Failed: %s" % (description,))
+ willSplitResult = splitter.willSplit(ical)
+ self.assertEqual(willSplitResult, result, msg="Failed: %s" % (description,))
def test_split(self):
@@ -2211,7 +2211,7 @@
ical = Component.fromString(calendar % self.subs)
splitter = iCalSplitter(1024, 14)
if title[0] == "1":
- self.assertTrue(splitter.willSplit(ical), "Failed will split: %s" % (title,))
+ self.assertTrue(splitter.willSplit(ical)[0], "Failed will split: %s" % (title,))
icalOld, icalNew = splitter.split(ical)
relsubs = dict(self.subs)
relsubs["uid"] = icalOld.resourceUID()
@@ -2220,8 +2220,8 @@
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,))
+ self.assertFalse(splitter.willSplit(icalNew)[0], "Failed future will split: %s" % (title,))
+ self.assertFalse(splitter.willSplit(icalOld)[0], "Failed past will split: %s" % (title,))
def test_split_negative_count(self):
@@ -2318,7 +2318,7 @@
ical = Component.fromString(calendar % self.subs)
splitter = iCalSplitter(100, 0)
if title[0] == "1":
- self.assertTrue(splitter.willSplit(ical), "Failed will split: %s" % (title,))
+ self.assertTrue(splitter.willSplit(ical)[0], "Failed will split: %s" % (title,))
icalOld, icalNew = splitter.split(ical)
relsubs = dict(self.subs)
relsubs["uid"] = icalOld.resourceUID()
@@ -2497,8 +2497,8 @@
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,))
+ self.assertFalse(splitter.willSplit(icalNew)[0], "Failed future will split: %s" % (title,))
+ self.assertFalse(splitter.willSplit(icalOld)[0], "Failed past will split: %s" % (title,))
ical = Component.fromString(calendar % self.subs)
splitter = iCalSplitter(1024, 14)
@@ -2510,5 +2510,5 @@
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,))
+ self.assertFalse(splitter.willSplit(icalNew)[0], "Failed future will split: %s" % (title,))
+ self.assertFalse(splitter.willSplit(icalOld)[0], "Failed past will split: %s" % (title,))
Modified: CalendarServer/branches/users/sagen/trashcan-5/txdav/caldav/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/sagen/trashcan-5/txdav/caldav/datastore/sql.py 2015-03-06 21:42:49 UTC (rev 14522)
+++ CalendarServer/branches/users/sagen/trashcan-5/txdav/caldav/datastore/sql.py 2015-03-06 22:00:19 UTC (rev 14523)
@@ -4690,7 +4690,7 @@
splitter = iCalSplitter(config.Scheduling.Options.Splitting.Size, config.Scheduling.Options.Splitting.PastDays)
ical = (yield self.component())
- will_split = splitter.willSplit(ical)
+ will_split, fullyInFuture = splitter.willSplit(ical)
returnValue(will_split)
@@ -4925,7 +4925,7 @@
if organizerAddress.record.uid == uid:
# If the ORGANIZER is moving the event from trash
splitter = iCalSplitter()
- willSplit = splitter.willSplit(caldata)
+ willSplit, fullyInFuture = splitter.willSplit(caldata)
if willSplit:
log.debug("Splitting scheduled event being recovered by organizer from trash")
yield self.split(
@@ -4941,12 +4941,7 @@
self,
)
else:
- now = DateTime.getNowUTC()
- now.setHHMMSS(0, 0, 0)
- instances = caldata.cacheExpandedTimeRanges(now)
- instances = sorted(instances.instances.values(), key=lambda x: x.start)
- if instances[0].start >= now:
- # future
+ if fullyInFuture:
log.debug("Scheduled event being recovered by organizer from trash, fully in the future")
newdata = caldata.duplicate()
newdata.bumpiTIPInfo(doSequence=True)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20150306/54f5f1ab/attachment-0001.html>
More information about the calendarserver-changes
mailing list