Ejemplo n.º 1
0
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()
Ejemplo n.º 2
0
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()
Ejemplo n.º 3
0
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()
Ejemplo n.º 4
0
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()
Ejemplo n.º 5
0
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()
Ejemplo n.º 6
0
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()
Ejemplo n.º 7
0
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)
Ejemplo n.º 8
0
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)
Ejemplo n.º 9
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()
Ejemplo n.º 10
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()
Ejemplo n.º 11
0
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
Ejemplo n.º 12
0
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']}
Ejemplo n.º 13
0
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
Ejemplo n.º 14
0
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
Ejemplo n.º 15
0
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
Ejemplo n.º 16
0
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
Ejemplo n.º 17
0
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
Ejemplo n.º 18
0
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
Ejemplo n.º 19
0
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
Ejemplo n.º 20
0
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']
    }
Ejemplo n.º 21
0
def auto_sync_get_syncid():
    cur = dblayer.run("SELECT value FROM Prefs where name='auto_sync_id'")
    count = dblayer.getValue(cur, "value")
    return count
Ejemplo n.º 22
0
def eventExistsLocally(id):
	cur = dblayer.run("SELECT lid FROM Xrefs WHERE gid=?", (id,))
	if cur:
		return dblayer.getValue(cur, 'lid')
	else:
		return None
Ejemplo n.º 23
0
def getLocalIdFromGoogleId(gid):
    cur = dblayer.run("SELECT lid FROM Xrefs WHERE gid=?", (gid, ))
    if cur:
        return dblayer.getValue(cur, 'lid')
    else:
        return None
Ejemplo n.º 24
0
def eventExistsLocally(id):
    cur = dblayer.run("SELECT lid FROM Xrefs WHERE gid=?", (id, ))
    if cur:
        return dblayer.getValue(cur, 'lid')
    else:
        return None
Ejemplo n.º 25
0
def getLocalIdFromGoogleId(gid):
	cur = dblayer.run("SELECT lid FROM Xrefs WHERE gid=?", (gid,))
	if cur:
		return dblayer.getValue(cur, 'lid')
	else:
		return None
Ejemplo n.º 26
0
def register_new_account(username, password):
	dblayer.run("INSERT INTO GoogleAccounts (username, password) VALUES "\
			"(?, ?)", (username, password))
	dblayer.commit()
Ejemplo n.º 27
0
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'])
Ejemplo n.º 28
0
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()
Ejemplo n.º 29
0
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()
Ejemplo n.º 30
0
def auto_sync_get_syncid():
	cur = dblayer.run("SELECT value FROM Prefs where name='auto_sync_id'")
	count = dblayer.getValue(cur, "value")
	return count
Ejemplo n.º 31
0
def update_profile(profile):
    dblayer.run("UPDATE Profiles SET type=?, datasource=?, localSource=?, "\
      "localSourceTitle=?, remoteAccountId=?, remoteSource=?, "\
      "remoteSourceTitle=?, enabled=?, direction=? WHERE "\
      "id=?", profile)
    dblayer.commit()
Ejemplo n.º 32
0
def remove_by_id(id):
	dblayer.run("DELETE FROM Profiles WHERE id=?", (id,))
	dblayer.run("DELETE FROM Xrefs WHERE pid=?", (id,))
	dblayer.commit()
Ejemplo n.º 33
0
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)
Ejemplo n.º 34
0
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()
Ejemplo n.º 35
0
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'])
Ejemplo n.º 36
0
		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)
Ejemplo n.º 37
0
def remove_by_id(id):
    dblayer.run("DELETE FROM Profiles WHERE id=?", (id, ))
    dblayer.run("DELETE FROM Xrefs WHERE pid=?", (id, ))
    dblayer.commit()
Ejemplo n.º 38
0
def update_profile(profile):
	dblayer.run("UPDATE Profiles SET type=?, datasource=?, localSource=?, "\
			"localSourceTitle=?, remoteAccountId=?, remoteSource=?, "\
			"remoteSourceTitle=?, enabled=?, direction=? WHERE "\
			"id=?", profile)
	dblayer.commit()
Ejemplo n.º 39
0
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)
Ejemplo n.º 40
0
def delete_account_by_id(id):
    dblayer.run("DELETE FROM GoogleAccounts WHERE id=?", (id, ))
    dblayer.run("DELETE FROM Profiles WHERE remoteAccountId=?", (id, ))
    dblayer.commit()
Ejemplo n.º 41
0
def get_registered_accounts_count():
	cur = dblayer.run("SELECT COUNT(id) AS X FROM GoogleAccounts")
	count = dblayer.getValue(cur, "X")
	return count
Ejemplo n.º 42
0
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()
Ejemplo n.º 43
0
def update_account(username, password, id):
	dblayer.run("UPDATE GoogleAccounts SET username=?, password=? WHERE "\
			"id=?", (username, password, id))
	dblayer.commit()
Ejemplo n.º 44
0
def get_registered_accounts_count():
    cur = dblayer.run("SELECT COUNT(id) AS X FROM GoogleAccounts")
    count = dblayer.getValue(cur, "X")
    return count
Ejemplo n.º 45
0
def register_new_account(username, password):
    dblayer.run("INSERT INTO GoogleAccounts (username, password) VALUES "\
      "(?, ?)", (username, password))
    dblayer.commit()
Ejemplo n.º 46
0
def update_account(username, password, id):
    dblayer.run("UPDATE GoogleAccounts SET username=?, password=? WHERE "\
      "id=?", (username, password, id))
    dblayer.commit()
Ejemplo n.º 47
0
def delete_account_by_id(id):
	dblayer.run("DELETE FROM GoogleAccounts WHERE id=?", (id,))
	dblayer.run("DELETE FROM Profiles WHERE remoteAccountId=?", (id,))
	dblayer.commit()
Ejemplo n.º 48
0
    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)