1.1 --- a/tools/make_freebusy.py Sun Aug 09 23:24:29 2015 +0200
1.2 +++ b/tools/make_freebusy.py Tue Aug 11 23:53:54 2015 +0200
1.3 @@ -21,6 +21,7 @@
1.4 this program. If not, see <http://www.gnu.org/licenses/>.
1.5 """
1.6
1.7 +from bisect import bisect_left
1.8 from codecs import getwriter
1.9 from imiptools.data import get_window_end, Object
1.10 from imiptools.dates import get_default_timezone
1.11 @@ -62,9 +63,23 @@
1.12 store = FileStore()
1.13 publisher = FilePublisher()
1.14
1.15 - # Get identifiers for uncancelled events.
1.16 + # Get identifiers for uncancelled events either from a list of events
1.17 + # providing free/busy periods at the end of the given time window, or from
1.18 + # a list of all events.
1.19 +
1.20 + all_events = store.get_freebusy_providers(user, window_end)
1.21
1.22 - all_events = store.get_active_events(user)
1.23 + if not all_events:
1.24 + all_events = store.get_active_events(user)
1.25 + fb = []
1.26 +
1.27 + # With providers of additional periods, append to the existing collection.
1.28 +
1.29 + else:
1.30 + if user == participant:
1.31 + fb = store.get_freebusy(user)
1.32 + else:
1.33 + fb = store.get_freebusy_for_other(user, participant)
1.34
1.35 # Obtain event objects.
1.36
1.37 @@ -78,16 +93,18 @@
1.38
1.39 # Build a free/busy collection for the given user.
1.40
1.41 - fb = []
1.42 for obj in objs:
1.43 partstat = obj.get_participation_status(participant)
1.44 recurrenceids = not obj.get_recurrenceid() and store.get_recurrences(user, obj.get_uid())
1.45
1.46 if obj.get_participation(partstat, include_needs_action):
1.47 for p in obj.get_active_periods(recurrenceids, tzid, window_end):
1.48 - fb.append(obj.get_freebusy_period(p, partstat == "ORG"))
1.49 -
1.50 - fb.sort()
1.51 + fbp = obj.get_freebusy_period(p, partstat == "ORG")
1.52 + i = bisect_left(fb, fbp)
1.53 + if i == len(fb):
1.54 + fb.append(fbp)
1.55 + elif fb[i] != fbp:
1.56 + fb.insert(i, fbp)
1.57
1.58 # Store and publish the free/busy collection.
1.59