mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 10:37:07 +00:00
Add get_file_data() function to datastore
This commit is contained in:
@@ -589,7 +589,33 @@ class Datastore:
|
|||||||
# We do not commit if we've been passed a cursor, instead
|
# We do not commit if we've been passed a cursor, instead
|
||||||
# we assume that we are in the middle of a transaction
|
# we assume that we are in the middle of a transaction
|
||||||
|
|
||||||
|
def get_file_data(self, path, cursor = None):
|
||||||
|
"""
|
||||||
|
Retrieve arbitrary data associated with a file.
|
||||||
|
"""
|
||||||
|
|
||||||
|
if cursor is None:
|
||||||
|
cur = self.conn.cursor()
|
||||||
|
else:
|
||||||
|
cur = cursor
|
||||||
|
|
||||||
|
realpath = configuration.translate_path(path)
|
||||||
|
hash = file_hash(realpath)
|
||||||
|
|
||||||
|
qry = """
|
||||||
|
SELECT data
|
||||||
|
FROM file_data
|
||||||
|
WHERE hash = %s;
|
||||||
|
"""
|
||||||
|
|
||||||
|
cur.execute(qry, (hash,))
|
||||||
|
res = cur.fetchone()
|
||||||
|
|
||||||
|
if cursor is None:
|
||||||
|
self.maybe_commit()
|
||||||
|
# We do not commit if we've been passed a cursor, instead
|
||||||
|
# we assume that we are in the middle of a transaction
|
||||||
|
return res[0]
|
||||||
|
|
||||||
def surveys (self, include_archived = False):
|
def surveys (self, include_archived = False):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user