def auto_sync_toggled(auto_button, time_button): active = auto_button.get_active() if active: (hours, minutes) = time_button.get_time() event = alarm.Event() event.appid = "erminig" event.title = "Synchronization with erminig" #event.flags |= alarm.EVENT_RUN_DELAYED action = event.add_actions(1)[0] action.flags |= alarm.ACTION_WHEN_TRIGGERED | alarm.ACTION_WHEN_DELAYED | alarm.ACTION_TYPE_EXEC action.command = os.path.abspath(sys.argv[0]) + " -a -d" recur = event.add_recurrences(1)[0] # let's see what this does... recur.mask_min = 1 << minutes recur.mask_hour = 1 << hours # initialize alarm time to somewhere in the future event.alarm_time = time.time() + 5 # lt = time.localtime(time.time() + 5) # tz = time.tzname[lt.tm_isdst] # event.alarm_time = time.mktime(recur.next(lt, tz)) event.recurrences_left = -1 sync_id=alarm.add_event(event) auto_sync_update_syncid(sync_id) auto_sync_update_synctime(hours, minutes) else: alarm.delete_event(int(auto_sync_get_syncid())) dblayer.run("DELETE FROM Prefs where name='auto_sync_id'") dblayer.commit()
def add_profile(profile): dblayer.run("INSERT INTO Profiles (type, datasource, localSource, "\ "localSourceTitle, remoteAccountId, remoteSource, "\ "remoteSourceTitle, enabled, direction, "\ "lastUpdate, lastLocalUpdate) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, 0, 0)", \ profile) dblayer.commit()
def auto_sync_toggled(auto_button, time_button): active = auto_button.get_active() if active: (hours, minutes) = time_button.get_time() event = alarm.Event() event.appid = "erminig" event.title = "Synchronization with erminig" #event.flags |= alarm.EVENT_RUN_DELAYED action = event.add_actions(1)[0] action.flags |= alarm.ACTION_WHEN_TRIGGERED | alarm.ACTION_WHEN_DELAYED | alarm.ACTION_TYPE_EXEC action.command = os.path.abspath(sys.argv[0]) + " -a -d" recur = event.add_recurrences(1)[0] # let's see what this does... recur.mask_min = 1 << minutes recur.mask_hour = 1 << hours # initialize alarm time to somewhere in the future event.alarm_time = time.time() + 5 # lt = time.localtime(time.time() + 5) # tz = time.tzname[lt.tm_isdst] # event.alarm_time = time.mktime(recur.next(lt, tz)) event.recurrences_left = -1 sync_id = alarm.add_event(event) auto_sync_update_syncid(sync_id) auto_sync_update_synctime(hours, minutes) else: alarm.delete_event(int(auto_sync_get_syncid())) dblayer.run("DELETE FROM Prefs where name='auto_sync_id'") dblayer.commit()
def auto_sync_update_syncid(sync_id): if auto_sync_get_syncid() is None: dblayer.run( "INSERT INTO Prefs (name, value) values ('auto_sync_id', '%d')" % sync_id) else: dblayer.run("UPDATE Prefs SET value='%d' where name='auto_sync_id'" % sync_id) dblayer.commit()
def auto_sync_update_synctime(sync_hour, sync_min): if auto_sync_get_synctime() is None: dblayer.run( "INSERT INTO Prefs (name, value) values ('auto_sync_time', '%d:%d')" % (sync_hour, sync_min)) else: dblayer.run( "UPDATE Prefs SET value='%d:%d' where name='auto_sync_time'" % (sync_hour, sync_min)) dblayer.commit()
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 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 auto_sync_get_synctime(): cur = dblayer.run("SELECT value FROM Prefs where name='auto_sync_time'") time = dblayer.getValue(cur, "value") if not time is None: return time.split(':') else: return None
def get_profile_by_id(id): cur = dblayer.run("SELECT * FROM Profiles WHERE id=?", (id,)) rows = dblayer.getRows(cur) if len(rows) == 0: return None return {'localSource': rows[0]['localSource'], 'localSourceTitle': rows[0]['localSourceTitle'], 'remoteAccountId': rows[0]['remoteAccountId'], 'remoteSource': rows[0]['remoteSource'], 'remoteSourceTitle': rows[0]['remoteSourceTitle'], 'enabled': rows[0]['enabled'], 'direction': rows[0]['direction'], 'lastUpdate': rows[0]['lastUpdate'], 'id': rows[0]['id'], 'lastLocalUpdate': rows[0]['lastLocalUpdate']}
def get_all(): cur = dblayer.run("SELECT * FROM Profiles") rows = dblayer.getRows(cur) profiles = [] for i in rows: profiles.append([i['id'], i['type'], i['localSource'], i['localSourceTitle'], i['remoteSource'], i['remoteSourceTitle'], i['enabled'], i['direction'], i['lastUpdate'], i['lastLocalUpdate']]) return profiles
def get_registered_accounts(): cur = dblayer.run("SELECT id, username FROM GoogleAccounts") rows = dblayer.getRows(cur) accts = [] for i in rows: accts.append([i['id'], i['username']]) return accts
def check_username_existence(username): cur = dblayer.run("SELECT COUNT(id) AS X FROM GoogleAccounts WHERE "\ "username = ?", (username,)) count = dblayer.getValue(cur, "X") if count > 0: return True else: return False
def get_all(): cur = dblayer.run("SELECT * FROM Profiles") rows = dblayer.getRows(cur) profiles = [] for i in rows: profiles.append([ i['id'], i['type'], i['localSource'], i['localSourceTitle'], i['remoteSource'], i['remoteSourceTitle'], i['enabled'], i['direction'], i['lastUpdate'], i['lastLocalUpdate'] ]) return profiles
def get_profile_by_id(id): cur = dblayer.run("SELECT * FROM Profiles WHERE id=?", (id, )) rows = dblayer.getRows(cur) if len(rows) == 0: return None return { 'localSource': rows[0]['localSource'], 'localSourceTitle': rows[0]['localSourceTitle'], 'remoteAccountId': rows[0]['remoteAccountId'], 'remoteSource': rows[0]['remoteSource'], 'remoteSourceTitle': rows[0]['remoteSourceTitle'], 'enabled': rows[0]['enabled'], 'direction': rows[0]['direction'], 'lastUpdate': rows[0]['lastUpdate'], 'id': rows[0]['id'], 'lastLocalUpdate': rows[0]['lastLocalUpdate'] }
def auto_sync_get_syncid(): cur = dblayer.run("SELECT value FROM Prefs where name='auto_sync_id'") count = dblayer.getValue(cur, "value") return count
def eventExistsLocally(id): cur = dblayer.run("SELECT lid FROM Xrefs WHERE gid=?", (id,)) if cur: return dblayer.getValue(cur, 'lid') else: return None
def getLocalIdFromGoogleId(gid): cur = dblayer.run("SELECT lid FROM Xrefs WHERE gid=?", (gid, )) if cur: return dblayer.getValue(cur, 'lid') else: return None
def eventExistsLocally(id): cur = dblayer.run("SELECT lid FROM Xrefs WHERE gid=?", (id, )) if cur: return dblayer.getValue(cur, 'lid') else: return None
def getLocalIdFromGoogleId(gid): cur = dblayer.run("SELECT lid FROM Xrefs WHERE gid=?", (gid,)) if cur: return dblayer.getValue(cur, 'lid') else: return None
def register_new_account(username, password): dblayer.run("INSERT INTO GoogleAccounts (username, password) VALUES "\ "(?, ?)", (username, password)) dblayer.commit()
def get_titles_by_id(id): cur = dblayer.run("SELECT localSourceTitle, remoteSourceTitle FROM "\ "Profiles WHERE id=?", (id,)) rows = dblayer.getRows(cur) return (rows[0]['localSourceTitle'], rows[0]['remoteSourceTitle'])
def set_last_sync(pid, t, t2): dblayer.run("UPDATE Profiles SET lastUpdate=? WHERE id=?", (t, pid)) dblayer.run("UPDATE Profiles SET lastLocalUpdate=? WHERE id=?", (t2, pid)) dblayer.commit()
def auto_sync_update_syncid(sync_id): if auto_sync_get_syncid() is None: dblayer.run("INSERT INTO Prefs (name, value) values ('auto_sync_id', '%d')" % sync_id) else: dblayer.run("UPDATE Prefs SET value='%d' where name='auto_sync_id'" % sync_id) dblayer.commit()
def update_profile(profile): dblayer.run("UPDATE Profiles SET type=?, datasource=?, localSource=?, "\ "localSourceTitle=?, remoteAccountId=?, remoteSource=?, "\ "remoteSourceTitle=?, enabled=?, direction=? WHERE "\ "id=?", profile) dblayer.commit()
def remove_by_id(id): dblayer.run("DELETE FROM Profiles WHERE id=?", (id,)) dblayer.run("DELETE FROM Xrefs WHERE pid=?", (id,)) dblayer.commit()
def get_account_by_id(id): cur = dblayer.run("SELECT username, password FROM GoogleAccounts "\ "WHERE id = ?", (id,)) row = dblayer.getRows(cur)[0] return (row['username'], row['password'], id)
event.when[0].reminder.append(gdata.calendar.Reminder(minutes=evt.get_alarm())); new_event = None try: new_event = google_api.run_google_action(google_api.gd_client.InsertEvent, event, urllib.quote('/calendar/feeds/' + googleid + '/private/full')) except ErminigGoogleError, e: error_win.display(e.title(), e.description()) return if new_event == None: logger.append("Got a None event....skipping") return gid = (new_event.id.text.rpartition("/"))[2] # insert correspondance table entry: dblayer.run("INSERT INTO Xrefs (pid, lid, gid) VALUES (?, ?, ?)", \ (pid, evt.get_id(), gid)) dblayer.commit() def getNewEventsFromLocal(pid, localSource, remoteSource, lastSync, progress): # Those are new events to create in Google: evts = queryNewLocalEvents(lastSync, localSource) if not evts: update_progress(progress, 1.0/3) return progress_inc = 1.0/3.0/len(evts) progress_val = 0.0 for e in evts: progress_val = progress_val + progress_inc update_progress(progress, progress_val)
def remove_by_id(id): dblayer.run("DELETE FROM Profiles WHERE id=?", (id, )) dblayer.run("DELETE FROM Xrefs WHERE pid=?", (id, )) dblayer.commit()
def delete_account_by_id(id): dblayer.run("DELETE FROM GoogleAccounts WHERE id=?", (id, )) dblayer.run("DELETE FROM Profiles WHERE remoteAccountId=?", (id, )) dblayer.commit()
def get_registered_accounts_count(): cur = dblayer.run("SELECT COUNT(id) AS X FROM GoogleAccounts") count = dblayer.getValue(cur, "X") return count
def auto_sync_update_synctime(sync_hour, sync_min): if auto_sync_get_synctime() is None: dblayer.run("INSERT INTO Prefs (name, value) values ('auto_sync_time', '%d:%d')" % (sync_hour,sync_min)) else: dblayer.run("UPDATE Prefs SET value='%d:%d' where name='auto_sync_time'" % (sync_hour,sync_min)) dblayer.commit()
def update_account(username, password, id): dblayer.run("UPDATE GoogleAccounts SET username=?, password=? WHERE "\ "id=?", (username, password, id)) dblayer.commit()
def delete_account_by_id(id): dblayer.run("DELETE FROM GoogleAccounts WHERE id=?", (id,)) dblayer.run("DELETE FROM Profiles WHERE remoteAccountId=?", (id,)) dblayer.commit()
new_event = None try: new_event = google_api.run_google_action( google_api.gd_client.InsertEvent, event, urllib.quote('/calendar/feeds/' + googleid + '/private/full')) except ErminigGoogleError, e: error_win.display(e.title(), e.description()) return if new_event == None: logger.append("Got a None event....skipping") return gid = (new_event.id.text.rpartition("/"))[2] # insert correspondance table entry: dblayer.run("INSERT INTO Xrefs (pid, lid, gid) VALUES (?, ?, ?)", \ (pid, evt.get_id(), gid)) dblayer.commit() def getNewEventsFromLocal(pid, localSource, remoteSource, lastSync, progress): # Those are new events to create in Google: evts = queryNewLocalEvents(lastSync, localSource) if not evts: update_progress(progress, 1.0 / 3) return progress_inc = 1.0 / 3.0 / len(evts) progress_val = 0.0 for e in evts: progress_val = progress_val + progress_inc update_progress(progress, progress_val)