1.1 --- a/tools/make_freebusy.py Wed Mar 04 17:06:11 2015 +0100
1.2 +++ b/tools/make_freebusy.py Wed Mar 04 17:13:56 2015 +0100
1.3 @@ -6,6 +6,19 @@
1.4 from imip_store import FileStore, FilePublisher
1.5 import sys
1.6
1.7 +def get_periods(fb, obj, tzid, window_end, only_organiser):
1.8 +
1.9 + # Update free/busy details with the actual periods associated with the event.
1.10 +
1.11 + for start, end in obj.get_periods_for_freebusy(tzid, window_end):
1.12 + fb.append((start, end,
1.13 + obj.get_value("UID"),
1.14 + only_organiser and "ORG" or obj.get_value("TRANSP") or "OPAQUE",
1.15 + format_datetime(obj.get_utc_datetime("RECURRENCE-ID")) or "",
1.16 + ))
1.17 +
1.18 +# Main program.
1.19 +
1.20 try:
1.21 user = sys.argv[1]
1.22 store_and_publish = "-s" in sys.argv[2:]
1.23 @@ -54,26 +67,24 @@
1.24
1.25 fb = []
1.26 for obj in objs:
1.27 - participants = {}
1.28 - participants.update(obj.get_value_map("ATTENDEE"))
1.29 - participants.update(obj.get_value_map("ORGANIZER"))
1.30 + attendees = obj.get_value_map("ATTENDEE")
1.31 + organiser = obj.get_value("ORGANIZER")
1.32
1.33 - for participant, participant_attr in participants.items():
1.34 + for attendee, attendee_attr in attendees.items():
1.35
1.36 - # Only consider events where this user actually participates.
1.37 + # Only consider events where this user actually attends.
1.38
1.39 - if participant == user:
1.40 - if participant_attr.get("PARTSTAT", "NEEDS-ACTION") not in ("DECLINED", "DELEGATED", "NEEDS-ACTION"):
1.41 -
1.42 - # Obtain the actual periods associated with the event.
1.43 + if attendee == user:
1.44 + if attendee_attr.get("PARTSTAT", "NEEDS-ACTION") not in ("DECLINED", "DELEGATED", "NEEDS-ACTION"):
1.45 + get_periods(fb, obj, tzid, window_end, False)
1.46 + break
1.47
1.48 - for start, end in obj.get_periods_for_freebusy(tzid, window_end):
1.49 - fb.append((start, end,
1.50 - obj.get_value("UID"),
1.51 - obj.get_value("TRANSP") or "OPAQUE",
1.52 - format_datetime(obj.get_utc_datetime("RECURRENCE-ID")) or "",
1.53 - ))
1.54 - break
1.55 + # Where not attending, retain the affected periods and mark them as
1.56 + # organising periods.
1.57 +
1.58 + else:
1.59 + if organiser == user:
1.60 + get_periods(fb, obj, tzid, window_end, True)
1.61
1.62 fb.sort()
1.63