Пример #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()
Пример #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()
Пример #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()
Пример #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()
Пример #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()
Пример #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()
Пример #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)
Пример #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)
Пример #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()
Пример #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()
Пример #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
Пример #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']}
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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']
    }
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #26
0
def register_new_account(username, password):
	dblayer.run("INSERT INTO GoogleAccounts (username, password) VALUES "\
			"(?, ?)", (username, password))
	dblayer.commit()
Пример #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'])
Пример #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()
Пример #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()
Пример #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
Пример #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()
Пример #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()
Пример #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)
Пример #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()
Пример #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'])
Пример #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)
Пример #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()
Пример #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()
Пример #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)
Пример #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()
Пример #41
0
def get_registered_accounts_count():
	cur = dblayer.run("SELECT COUNT(id) AS X FROM GoogleAccounts")
	count = dblayer.getValue(cur, "X")
	return count
Пример #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()
Пример #43
0
def update_account(username, password, id):
	dblayer.run("UPDATE GoogleAccounts SET username=?, password=? WHERE "\
			"id=?", (username, password, id))
	dblayer.commit()
Пример #44
0
def get_registered_accounts_count():
    cur = dblayer.run("SELECT COUNT(id) AS X FROM GoogleAccounts")
    count = dblayer.getValue(cur, "X")
    return count
Пример #45
0
def register_new_account(username, password):
    dblayer.run("INSERT INTO GoogleAccounts (username, password) VALUES "\
      "(?, ?)", (username, password))
    dblayer.commit()
Пример #46
0
def update_account(username, password, id):
    dblayer.run("UPDATE GoogleAccounts SET username=?, password=? WHERE "\
      "id=?", (username, password, id))
    dblayer.commit()
Пример #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()
Пример #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)