1.1 --- a/tools/make_freebusy.py Sat Mar 07 00:13:41 2015 +0100
1.2 +++ b/tools/make_freebusy.py Sun Mar 08 01:35:43 2015 +0100
1.3 @@ -6,24 +6,36 @@
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 +def get_periods(fb, obj, tzid, window_end, only_organiser, recurrenceids):
1.9
1.10 # Update free/busy details with the actual periods associated with the event.
1.11
1.12 + recurrenceid = format_datetime(obj.get_utc_datetime("RECURRENCE-ID")) or ""
1.13 +
1.14 for start, end in obj.get_periods_for_freebusy(tzid, window_end):
1.15 - fb.append((start, end,
1.16 - obj.get_value("UID"),
1.17 - only_organiser and "ORG" or obj.get_value("TRANSP") or "OPAQUE",
1.18 - format_datetime(obj.get_utc_datetime("RECURRENCE-ID")) or "",
1.19 - ))
1.20 + if recurrenceid or start not in recurrenceids:
1.21 + fb.append((
1.22 + start, end,
1.23 + obj.get_value("UID"),
1.24 + only_organiser and "ORG" or obj.get_value("TRANSP") or "OPAQUE",
1.25 + recurrenceid,
1.26 + obj.get_value("SUMMARY"),
1.27 + obj.get_value("ORGANIZER")
1.28 + ))
1.29
1.30 # Main program.
1.31
1.32 try:
1.33 user = sys.argv[1]
1.34 - store_and_publish = "-s" in sys.argv[2:]
1.35 + args = sys.argv[2:]
1.36 + participant = args and args[0] not in ("-n", "-s") and args[0] or user
1.37 + store_and_publish = "-s" in args
1.38 + include_needs_action = "-n" in args
1.39 except IndexError:
1.40 - print >>sys.stderr, "Need a user, along with the -s option if updating the store."
1.41 + print >>sys.stderr, """\
1.42 +Need a user and an optional participant (if different from the user),
1.43 +along with the -s option if updating the store and the published details.
1.44 +"""
1.45 sys.exit(1)
1.46
1.47 preferences = Preferences(user)
1.48 @@ -69,30 +81,39 @@
1.49 for obj in objs:
1.50 attendees = obj.get_value_map("ATTENDEE")
1.51 organiser = obj.get_value("ORGANIZER")
1.52 + recurrenceids = store.get_recurrences(user, obj.get_value("UID"))
1.53
1.54 for attendee, attendee_attr in attendees.items():
1.55
1.56 - # Only consider events where this user actually attends.
1.57 + # Only consider events where the stated participant actually attends.
1.58 +
1.59 + if attendee == participant:
1.60 + partstat = attendee_attr.get("PARTSTAT", "NEEDS-ACTION")
1.61
1.62 - if attendee == user:
1.63 - if attendee_attr.get("PARTSTAT", "NEEDS-ACTION") not in ("DECLINED", "DELEGATED", "NEEDS-ACTION"):
1.64 - get_periods(fb, obj, tzid, window_end, False)
1.65 + if partstat not in ("DECLINED", "DELEGATED", "NEEDS-ACTION") or \
1.66 + include_needs_action and partstat == "NEEDS-ACTION":
1.67 +
1.68 + get_periods(fb, obj, tzid, window_end, False, recurrenceids)
1.69 +
1.70 break
1.71
1.72 # Where not attending, retain the affected periods and mark them as
1.73 # organising periods.
1.74
1.75 else:
1.76 - if organiser == user:
1.77 - get_periods(fb, obj, tzid, window_end, True)
1.78 + if organiser == participant:
1.79 + get_periods(fb, obj, tzid, window_end, True, recurrenceids)
1.80
1.81 fb.sort()
1.82
1.83 # Store and publish the free/busy collection.
1.84
1.85 if store_and_publish:
1.86 - store.set_freebusy(user, fb)
1.87 - publisher.set_freebusy(user, fb)
1.88 + if user == participant:
1.89 + store.set_freebusy(user, fb)
1.90 + publisher.set_freebusy(user, fb)
1.91 + else:
1.92 + store.set_freebusy_for_other(user, fb, participant)
1.93 else:
1.94 for item in fb:
1.95 print "\t".join(item)