1.1 --- a/tools/make_freebusy.py Thu Aug 06 20:02:14 2015 +0200
1.2 +++ b/tools/make_freebusy.py Thu Aug 06 22:00:11 2015 +0200
1.3 @@ -23,32 +23,10 @@
1.4
1.5 from imiptools.data import get_window_end, Object
1.6 from imiptools.dates import get_default_timezone
1.7 -from imiptools.period import FreeBusyPeriod, is_replaced
1.8 from imiptools.profile import Preferences
1.9 from imip_store import FileStore, FilePublisher
1.10 import sys
1.11
1.12 -def get_periods(fb, obj, tzid, window_end, only_organiser, recurrenceids):
1.13 -
1.14 - """
1.15 - Update free/busy details 'fb' with the actual periods associated with the
1.16 - event 'obj'.
1.17 - """
1.18 -
1.19 - recurrenceid = obj.get_recurrenceid()
1.20 -
1.21 - for p in obj.get_periods(tzid, window_end):
1.22 - if recurrenceid or not is_replaced(p, recurrenceids, tzid):
1.23 - fb.append(FreeBusyPeriod(
1.24 - p.get_start_point(),
1.25 - p.get_end_point(),
1.26 - obj.get_value("UID"),
1.27 - only_organiser and "ORG" or obj.get_value("TRANSP") or "OPAQUE",
1.28 - recurrenceid,
1.29 - obj.get_value("SUMMARY"),
1.30 - obj.get_value("ORGANIZER")
1.31 - ))
1.32 -
1.33 # Main program.
1.34
1.35 if __name__ == "__main__":
1.36 @@ -83,19 +61,9 @@
1.37 store = FileStore()
1.38 publisher = FilePublisher()
1.39
1.40 - # Get all identifiers for events.
1.41 -
1.42 - uids = store.get_events(user)
1.43 + # Get identifiers for uncancelled events.
1.44
1.45 - all_events = set()
1.46 - for uid in uids:
1.47 - all_events.add((uid, None))
1.48 - all_events.update([(uid, recurrenceid) for recurrenceid in store.get_recurrences(user, uid)])
1.49 -
1.50 - # Filter out cancelled events.
1.51 -
1.52 - cancelled = store.get_cancellations(user) or []
1.53 - all_events.difference_update(cancelled)
1.54 + all_events = store.get_active_events(user)
1.55
1.56 # Obtain event objects.
1.57
1.58 @@ -111,30 +79,12 @@
1.59
1.60 fb = []
1.61 for obj in objs:
1.62 - attendees = obj.get_value_map("ATTENDEE")
1.63 - organiser = obj.get_value("ORGANIZER")
1.64 - recurrenceids = store.get_recurrences(user, obj.get_value("UID"))
1.65 -
1.66 - for attendee, attendee_attr in attendees.items():
1.67 -
1.68 - # Only consider events where the stated participant actually attends.
1.69 -
1.70 - if attendee == participant:
1.71 - partstat = attendee_attr.get("PARTSTAT", "NEEDS-ACTION")
1.72 + partstat = obj.get_participation_status(participant)
1.73 + recurrenceids = not obj.get_recurrenceid() and store.get_recurrences(user, obj.get_uid())
1.74
1.75 - if partstat not in ("DECLINED", "DELEGATED", "NEEDS-ACTION") or \
1.76 - include_needs_action and partstat == "NEEDS-ACTION":
1.77 -
1.78 - get_periods(fb, obj, tzid, window_end, False, recurrenceids)
1.79 -
1.80 - break
1.81 -
1.82 - # Where not attending, retain the affected periods and mark them as
1.83 - # organising periods.
1.84 -
1.85 - else:
1.86 - if organiser == participant:
1.87 - get_periods(fb, obj, tzid, window_end, True, recurrenceids)
1.88 + if obj.get_participation(partstat, include_needs_action):
1.89 + for p in obj.get_active_periods(recurrenceids, tzid, window_end):
1.90 + fb.append(obj.get_freebusy_period(p, partstat == "ORG"))
1.91
1.92 fb.sort()
1.93