Beispiel #1
0
def save_image(imagedata):
	"""Save/update given image

	The given image needs to be the same structure that is given 
	from the "DropboxAPIFacade" when downloading app folder images.
	
	"""

	(db_session, engine) = database.get_session()

	filename = basename(imagedata["path"])

	image_query = db_session.query(DropboxImage).filter_by(filename = filename)
	db_image = image_query.first()	
	
	if db_image is None:
		db_image = DropboxImage(imagedata["revision"], filename, time.time())
	else:
		db_image.revision = imagedata["revision"]
		db_image.downloaded_at = time.time()

	db_session.add(db_image)

	db_session.commit()
	db_session.close()
Beispiel #2
0
def get_amount():
	"""Counts all local images"""

	(db_session, engine) = database.get_session()
	amount = db_session.query(DropboxImage).count()
	db_session.close()

	return amount
Beispiel #3
0
def get_all_images():
	"""Retrieves a list of all local images"""

	(db_session, engine) = database.get_session()
	images = db_session.query(DropboxImage).all()
	db_session.close()

	return images
Beispiel #4
0
def set_latest_sync():
	"""Sets the latest sync time to current time"""

	(db_session, engine) = database.get_session()

	status = retrieve_status()	
	status.latest_sync = int(time.time())

	db_session.add(status)
	db_session.commit()
	db_session.close()
Beispiel #5
0
def get_request_token():
	"""Retrieves the current request token for Dropbox API usage"""

	(db_session, engine) = database.get_session()
	token = db_session.query(DropboxRequest).get(1)
	db_session.close()

	if token is None:
		return (None, None)

	return (token.key, token.secret)
Beispiel #6
0
def get_access_token():
	"""Retrieves the current access token"""

	(db_session, engine) = database.get_session()
	token = db_session.query(DropboxAccess).get(1)
	db_session.close()

	if token is None:
		return (None, None)

	return (token.key, token.secret)
Beispiel #7
0
def retrieve_config():
	"""Retrieves the static system config"""

	(db_session, engine) = database.get_session()
	config = db_session.query(SystemConfig).get(1)
	db_session.close()

	if config is None:
		raise AssertionError("The crucial system config was not found in the database")

	return config
Beispiel #8
0
def set_current_job(job_id):
	"""Sets the current job to given job id"""

	(db_session, engine) = database.get_session()

	status = retrieve_status()	
	status.current_background_job = job_id

	db_session.add(status)
	db_session.commit()
	db_session.close()
Beispiel #9
0
def set_uptime_start():
	"""Sets uptime to the current time"""

	(db_session, engine) = database.get_session()

	status = retrieve_status()	
	status.uptime_start = int(time.time())

	db_session.add(status)
	db_session.commit()
	db_session.close()
Beispiel #10
0
def set_dropbox_connection(was_connected):
	"""Sets the column dropbox_connection in the current system status"""

	(db_session, engine) = database.get_session()

	status = retrieve_status()
	status.dropbox_connection = was_connected

	db_session.add(status)
	db_session.commit()
	db_session.close()
Beispiel #11
0
def retrieve_status():
	"""Retrieves the current system status"""

	(db_session, engine) = database.get_session()
	status = db_session.query(SystemStatus).get(1)
	db_session.close()

	if status is None:
		raise AssertionError("The crucial system status was not found in the database")

	return status
Beispiel #12
0
def delete_access_token():
	"""Deletes the current access token"""

	(db_session, engine) = database.get_session()
	token = db_session.query(DropboxAccess).get(1)

	if token is None:
		return

	db_session.delete(token)
	db_session.commit()
	db_session.close()
Beispiel #13
0
def save_images(dropbox_images):
	"""Save/update all images in the given list

	The given image list needs to be the same structure that is given 
	from the "DropboxAPIFacade" when downloading app folder images.
	
	"""

	(db_session, engine) = database.get_session()

	for imagedata in dropbox_images:
		save_image(imagedata)
Beispiel #14
0
def save_request_token(key, secret):
	"""Creates/saves the current request token for Dropbox API usage"""

	(db_session, engine) = database.get_session()
	token = db_session.query(DropboxRequest).get(1)
	
	if token is None:
		token = DropboxRequest(key, secret)
	else:
		token.key = key
		token.secret = secret

	db_session.add(token)
	db_session.commit()
	db_session.close()
Beispiel #15
0
def save_access_token(key, secret):
	"""Saves/updates a new access token"""

	(db_session, engine) = database.get_session()
	token = db_session.query(DropboxAccess).get(1)

	if token is None:
		token = DropboxAccess(key, secret)
	else:
		token.key = key
		token.secret = secret	

	db_session.add(token)
	db_session.commit()
	db_session.close()
Beispiel #16
0
def setup_database(echo = True):
    (db_session, db_engine) = database.get_session()

    db_engine.echo = echo
    Base.metadata.drop_all(bind = db_engine)
    Base.metadata.create_all(bind = db_engine)

    for d in get_default_data():
        if echo is True:
            print d

        db_session.add(d)

    db_session.commit()
    db_engine.echo = False
    db_session.close()
Beispiel #17
0
def delete_images(dropbox_images):
	"""Deletes all images in the given list by their filenam

	The given image list needs to be the same structure that is given 
	from the "DropboxAPIFacade" when downloading app folder images.

	Image filename is a unique column, so using filename as filter is ok.
	
	"""

	(db_session, engine) = database.get_session()

	for imagedata in dropbox_images:
		filename = basename(imagedata["path"])

		image_query = db_session.query(DropboxImage).filter_by(filename = filename)
		db_image = image_query.first()

		if db_image is not None: 
			db_session.delete(db_image)

	db_session.commit()
	db_session.close()
	def setUp(self):
		(self.db_session, self.db_engine) = database.get_session()