chiark / gitweb /
Bugfix: handle events with no gcal_id link cli
authorMatthew Vernon <mv3@sanger.ac.uk>
Wed, 24 Oct 2018 15:47:22 +0000 (16:47 +0100)
committerMatthew Vernon <mv3@sanger.ac.uk>
Wed, 24 Oct 2018 15:47:22 +0000 (16:47 +0100)
...this is typically where we can't edit the Exchange event (because
we don't own it). We could, as alternatives:

i) try and re-match each time
ii) store the link value in our cache and use that

gooswapper.py

index 406b6f8..41dd807 100644 (file)
@@ -79,6 +79,9 @@ def get_gcal_event_by_eventid(gcal_acct,eventId,gcal_id="primary"):
     return gcal_acct.events().get(calendarId=gcal_id,eventId=eventId).execute()
 
 def get_gcal_recur_instance(gcal_acct,gcal_master,start,gcal_id="primary"):
+    if gcal_master is None:
+        logger.warning("Cannot get recurrences from event with null gcal id")
+        return None
     ans = gcal_acct.events().instances(calendarId=gcal_id,
                                        eventId=gcal_master,
                                        originalStart=start.isoformat(),
@@ -307,6 +310,9 @@ def update_ex_to_gcal(ex_acct,
                       gcal_id="primary"):
     for ev_id in changed:
         event = get_ex_event_by_itemid(ex_acct.calendar,ev_id)
+        if event.gcal_link is None:
+            logger.warning("Cannot apply update where event has no gcal link")
+            continue
         gevent = build_gcal_event_from_ex(event,gcal_tz)
         if event.type=="RecurringMaster":
             rr = rrule_from_ex(event,gcal_tz)
@@ -321,10 +327,14 @@ def update_ex_to_gcal(ex_acct,
             else:
                 logger.warning("Unable to set recurrence for %s" % event.item_id)
                 continue #don't make the gcal event
-        gevent = gcal_acct.events().update(calendarId=gcal_id,
+        try: #may fail if we don't own the event
+            gevent = gcal_acct.events().update(calendarId=gcal_id,
                                                eventId=event.gcal_link,
                                                body=gevent,
                                                sendUpdates="none").execute()
+        except googleapiclient.errors.HttpError as err:
+            if err.resp.status == 403:
+                pass
 
 def match_ex_to_gcal(ex_acct,gcal_acct,gcal_tz,events,gcal_id="primary",ignore_link=True):
     recur = 0