# HG changeset patch # User Paul Boddie # Date 1454945611 -3600 # Node ID 1d9c0c8cf99ccf3cf97e029c1092fa9c04383180 # Parent 865aaba26b244702ab64e95f55dc47f19f1ee16c Return removed periods from various functions and methods for wider re-use of those functions and methods. diff -r 865aaba26b24 -r 1d9c0c8cf99c imiptools/client.py --- a/imiptools/client.py Mon Feb 08 01:20:23 2016 +0100 +++ b/imiptools/client.py Mon Feb 08 16:33:31 2016 +0100 @@ -993,8 +993,11 @@ "Remove this event from the given 'freebusy' collection." - if not remove_event_periods(freebusy, self.uid, self.recurrenceid) and self.recurrenceid: - remove_affected_period(freebusy, self.uid, self.get_recurrence_start_point(self.recurrenceid)) + removed = remove_event_periods(freebusy, self.uid, self.recurrenceid) + if not removed and self.recurrenceid: + return remove_affected_period(freebusy, self.uid, self.get_recurrence_start_point(self.recurrenceid)) + else: + return removed def remove_freebusy_for_recurrences(self, freebusy, recurrenceids=None): diff -r 865aaba26b24 -r 1d9c0c8cf99c imiptools/period.py --- a/imiptools/period.py Mon Feb 08 01:20:23 2016 +0100 +++ b/imiptools/period.py Mon Feb 08 16:33:31 2016 +0100 @@ -3,7 +3,7 @@ """ Managing and presenting periods of time. -Copyright (C) 2014, 2015 Paul Boddie +Copyright (C) 2014, 2015, 2016 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -539,8 +539,11 @@ If 'recurrenceids' is specified, remove all periods associated with 'uid' that do not have a recurrence identifier in the given list. + + Return the removed periods. """ + removed = [] i = 0 while i < len(freebusy): fb = freebusy[i] @@ -548,10 +551,13 @@ recurrenceids is None or recurrenceids is not None and fb.recurrenceid not in recurrenceids ): + removed.append(freebusy[i]) del freebusy[i] else: i += 1 + return removed + def remove_affected_period(freebusy, uid, start): """ @@ -560,8 +566,12 @@ identifier, converted to a datetime). A recurrence identifier is used to provide an alternative time period whilst also acting as a reference to the originally-defined occurrence. + + Return any removed period in a list. """ + removed = [] + search = Period(start, start) found = bisect_left(freebusy, search) @@ -571,11 +581,12 @@ # Stop looking if the start no longer matches the recurrence identifier. if fb.get_start_point() != search.get_start_point(): - return + break # If the period belongs to the parent object, remove it and return. if not fb.recurrenceid and uid == fb.uid: + removed.append(freebusy[found]) del freebusy[found] break @@ -583,6 +594,8 @@ found += 1 + return removed + def periods_from(freebusy, period): "Return the entries in 'freebusy' at or after 'period'."