def getDeletedEventsFromLocal(pid, localSource, remoteSource, lastSync, progress): # get all events in the Trash: rows = cwrapper.getAllDeletedEvents(localSource, lastSync) if not rows: update_progress(progress, 1.0) return progress_inc = 1.0 / 3.0 / len(rows) progress_val = 1.0 / 3.0 * 2 for e in rows: progress_val = progress_val + progress_inc update_progress(progress, progress_val) gid = getGoogleIdFromLocalId(e) if not gid: continue try: event = google_api.run_google_action( google_api.gd_client.GetCalendarEventEntry, urllib.quote("/calendar/feeds/" + remoteSource + "/private/full/" + gid)) if event == None: logger.append("Unable to get event to delete!") return google_api.run_google_action(google_api.gd_client.DeleteEvent, event.GetEditLink().href) except ErminigGoogleError, e: error_win.display(e.title(), e.description()) return
def getDeletedEventsFromLocal(pid, localSource, remoteSource, lastSync, progress): # get all events in the Trash: rows = cwrapper.getAllDeletedEvents(localSource, lastSync) if not rows: update_progress(progress, 1.0) return progress_inc = 1.0/3.0/len(rows) progress_val = 1.0/3.0*2 for e in rows: progress_val = progress_val + progress_inc update_progress(progress, progress_val) gid = getGoogleIdFromLocalId(e) if not gid: continue try: event = google_api.run_google_action(google_api.gd_client.GetCalendarEventEntry, urllib.quote("/calendar/feeds/" + remoteSource + "/private/full/" + gid)) if event == None: logger.append("Unable to get event to delete!") return google_api.run_google_action(google_api.gd_client.DeleteEvent, event.GetEditLink().href) except ErminigGoogleError, e: error_win.display(e.title(), e.description()) return
def switch_account(credentials): gd_client.email = credentials[0] gd_client.password = credentials[1] try: gd_client.ProgrammaticLogin() except gdata.service.BadAuthentication, e: logger.append("Invalid username or password!") logger.append(repr(e)) raise ErminigError(consts.INVALID_USER_PWD) return False
def insertNewGoogleEventLocally(event, cid, pid): global localEventsTouched lastId = cwrapper.addLocalCalendarEntry(cid, event) if lastId == None: logger.append("Error when inserting event locally") return dblayer.run("INSERT INTO Xrefs (pid, lid, gid) VALUES (?, ?, ?)", (pid, lastId, event.get_id())) dblayer.commit() localEventsTouched.append(lastId)
def get_all_calendars(): cals = [] feed = run_google_action(gd_client.GetAllCalendarsFeed) for i,cal in enumerate(feed.entry): title = cal.title.text # Get only the last part of the ID (and substitute the %'s): logger.append("raw calendar name:") logger.append(cal.id.text) id = urllib.unquote((cal.id.text.rpartition("/"))[2]) cals.append((id, title)) return cals
def update_remote_data_source(sync_type, google_acct_id): global dialog remote_sources.clear() if sync_type == consts.SYNC_TYPE_CAL: hildon.hildon_gtk_window_set_progress_indicator(dialog, 1) try: if not google_api.switch_account(\ google_accounts.get_account_by_id(\ google_acct_id)): display_google_auth_error(dialog) google_new_btn.set_sensitive(False) google_item_picker.set_sensitive(False) hildon.hildon_gtk_window_set_progress_indicator(dialog, 0) return except ErminigError, e: error_win.display(e.title(), e.description()) return google_new_btn.set_sensitive(True) google_item_picker.set_sensitive(True) for id, title in google_api.get_all_calendars(): logger.append("ID->") logger.append(id) logger.append("title->") logger.append(title) remote_sources.append([id, title]) hildon.hildon_gtk_window_set_progress_indicator(dialog, 0)
def removeCancelledEventLocally(cid, gid): # get local ID from googleId: lid = getLocalIdFromGoogleId(gid) if not lid: return logger.append("Removing local event (Deleted from Google -> %s)" % (gid)) # purge Calendar entry: cwrapper.removeCancelledEventLocally(cid, lid) # purge entry in correspondance table: dblayer.run("DELETE FROM Xrefs WHERE lid=?", (lid, )) dblayer.commit()
def process_recurrence(rstring): logger.append(rstring) rrule = recur_rrule.search(rstring) if not rrule: return None rrule_array = rrule.group(1).split(";") rrule_final_array = [] for rule in rrule_array: if not rule.startswith("DTEND") or not rule.startswith("DTSTART"): rrule_final_array.append(rule) recurrence = {} recurrence['rrule'] = ";".join(rrule_final_array) start = recur_start.search(rstring).group(1) end = recur_end.search(rstring).group(1) start_str = "" end_str = "" if start[0] == ":": start_str = start[1:] else: start_components = start[1:].split(":") start_str = start_components[1] # Shall we do something w/ VTIMEZONES? if end[0] == ":": end_str = end[1:] else: end_components = end[1:].split(":") end_str = end_components[1] recurrence['dtstart'] = convert_date(start_str) recurrence['dtend'] = convert_date(end_str) return recurrence
def get_until(self): if self.rrule == None or self.rrule == "": return -1 rules = self.rrule.split(";") print rules d = "" for r in rules: if r.startswith("UNTIL="): d = r[len("UNTIL="):] break if len(d) == 8: iso_date = d[:4] + "-" + d[4:6] + "-" + d[6:] elif len(d) == 15: iso_date = d[:4] + "-" + d[4:6] + "-" + d[6:11] \ + ":" + d[11:13] + ":" + d[13:] else: logger.append("event %s: strange until value: %s" % (self.title, d)) return -1 # ?? return int(iso8601.parse(iso_date)) + 1
current_fraction = 0.0 for i, e in enumerate(feed.entry): current_fraction = current_fraction + fraction update_progress(progress, current_fraction) title = e.title.text rstring = "" start_time = "" end_time = "" full_day = False alarm = -1 if e.recurrence <> None: recurrence = process_recurrence(e.recurrence.text) if not recurrence: logger.append("Recurrence could not be parsed for") logger.append(title) logger.append("Skipping....") continue rstring = recurrence['rrule'] start_time = iso8601ToTimestamp(recurrence['dtstart']) end_time = iso8601ToTimestamp(recurrence['dtend']) fullday = isEventFullDay(recurrence['dtstart']) if len(e.reminder) > 0: alarm = int(e.reminder[0].minutes) else: start_time = iso8601ToTimestamp(e.when[0].start_time) end_time = iso8601ToTimestamp(e.when[0].end_time) # An event is full-day if it doesn't have any
def run_google_action(func, *args, **kwargs): # XXX Configurable... maxattempts = 4 res = None for i in range(0,maxattempts): try: res = func(*args, **kwargs) break except gdata.service.RequestError, e: if i > maxattempts: logger.append("Maximum number of attempts to for a Google action reached; skipping entry") return None if e[0]['status'] == 302: logger.append("** Received spurious redirect - retrying in 2 seconds (attempt %s of %s)" % (i+1, maxattempts)) time.sleep(2) elif e[0]['status'] == 401: logger.append("Invalid username or password!") logger.append(repr(e)) raise ErminigGoogleError(e) return None elif e[0]['status'] == 403: logger.append("You don't have access to this calendar. Has it been deleted?") logger.append(repr(e)) raise ErminigGoogleError(e) return None else: logger.append(repr(e)) # XXX Temporary return None
return res def switch_account(credentials): gd_client.email = credentials[0] gd_client.password = credentials[1] try: gd_client.ProgrammaticLogin() except gdata.service.BadAuthentication, e: logger.append("Invalid username or password!") logger.append(repr(e)) raise ErminigError(consts.INVALID_USER_PWD) return False except gdata.service.CaptchaRequired, e: logger.append(repr(e)) return False except socket.gaierror, e: logger.append("Unable to connect! Check internet connection") raise ErminigError(consts.NO_INET_CONNECTION) return False return True def get_all_calendars(): cals = [] feed = run_google_action(gd_client.GetAllCalendarsFeed) for i,cal in enumerate(feed.entry): title = cal.title.text
current_fraction = 0.0; for i, e in enumerate(feed.entry): current_fraction = current_fraction + fraction update_progress(progress, current_fraction) title = e.title.text rstring = "" start_time = "" end_time = "" full_day = False alarm = -1 if e.recurrence <> None: recurrence = process_recurrence(e.recurrence.text) if not recurrence: logger.append("Recurrence could not be parsed for") logger.append(title) logger.append("Skipping....") continue rstring = recurrence['rrule'] start_time = iso8601ToTimestamp(recurrence['dtstart']) end_time = iso8601ToTimestamp(recurrence['dtend']) fullday = isEventFullDay(recurrence['dtstart']) if len(e.reminder) > 0: alarm = int(e.reminder[0].minutes) else: start_time = iso8601ToTimestamp(e.when[0].start_time) end_time = iso8601ToTimestamp(e.when[0].end_time) # An event is full-day if it doesn't have any