From b71489cee1532299fa9256f8057f4ff3a14b2a3a Mon Sep 17 00:00:00 2001 From: "D. Berge" Date: Tue, 12 Sep 2023 11:04:37 +0200 Subject: [PATCH] Add get_file_data() function to datastore --- bin/datastore.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/bin/datastore.py b/bin/datastore.py index e6441d0..2b787b2 100644 --- a/bin/datastore.py +++ b/bin/datastore.py @@ -589,7 +589,33 @@ class Datastore: # We do not commit if we've been passed a cursor, instead # 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): """