mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 08:17:09 +00:00
Add function to retrieve survey configurations from DB.
As the survey definitions will no longer be stored in files under etc/surveys/ but directly on the database, this function replaces configuration.surveys()
This commit is contained in:
@@ -55,6 +55,10 @@ def files (globspec = None, include_archived = False):
|
|||||||
quickly and temporarily “disabling” a survey configuration by renaming
|
quickly and temporarily “disabling” a survey configuration by renaming
|
||||||
the relevant file.
|
the relevant file.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
print("This method is obsolete")
|
||||||
|
return
|
||||||
|
|
||||||
tuples = []
|
tuples = []
|
||||||
|
|
||||||
if globspec is None:
|
if globspec is None:
|
||||||
|
|||||||
@@ -589,6 +589,36 @@ class Datastore:
|
|||||||
# we assume that we are in the middle of a transaction
|
# we assume that we are in the middle of a transaction
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def surveys (self, include_archived = False):
|
||||||
|
"""
|
||||||
|
Return list of survey definitions.
|
||||||
|
"""
|
||||||
|
|
||||||
|
if self.conn is None:
|
||||||
|
self.connect()
|
||||||
|
|
||||||
|
if include_archived:
|
||||||
|
qry = """
|
||||||
|
SELECT meta
|
||||||
|
FROM public.projects;
|
||||||
|
"""
|
||||||
|
else:
|
||||||
|
qry = """
|
||||||
|
SELECT meta
|
||||||
|
FROM public.projects
|
||||||
|
WHERE NOT (meta->'archived')::boolean IS true
|
||||||
|
"""
|
||||||
|
|
||||||
|
with self.conn:
|
||||||
|
with self.conn.cursor() as cursor:
|
||||||
|
|
||||||
|
cursor.execute(qry)
|
||||||
|
results = cursor.fetchall()
|
||||||
|
return [r[0] for r in results if r[0]]
|
||||||
|
|
||||||
|
|
||||||
|
# TODO Does this need tweaking on account of #246?
|
||||||
def apply_survey_configuration(self, cursor = None):
|
def apply_survey_configuration(self, cursor = None):
|
||||||
if cursor is None:
|
if cursor is None:
|
||||||
cur = self.conn.cursor()
|
cur = self.conn.cursor()
|
||||||
|
|||||||
@@ -51,12 +51,11 @@ def del_pending_remark(db, sequence):
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
print("Reading configuration")
|
print("Reading configuration")
|
||||||
surveys = configuration.surveys()
|
|
||||||
file_min_age = configuration.read().get('imports', {}).get('file_min_age', 10)
|
file_min_age = configuration.read().get('imports', {}).get('file_min_age', 10)
|
||||||
|
|
||||||
print("Connecting to database")
|
print("Connecting to database")
|
||||||
db = Datastore()
|
db = Datastore()
|
||||||
db.connect()
|
surveys = db.surveys()
|
||||||
|
|
||||||
print("Reading surveys")
|
print("Reading surveys")
|
||||||
for survey in surveys:
|
for survey in surveys:
|
||||||
|
|||||||
@@ -17,12 +17,12 @@ from datastore import Datastore
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
print("Reading configuration")
|
|
||||||
surveys = configuration.surveys()
|
|
||||||
file_min_age = configuration.read().get('imports', {}).get('file_min_age', 10)
|
|
||||||
|
|
||||||
print("Connecting to database")
|
print("Connecting to database")
|
||||||
db = Datastore()
|
db = Datastore()
|
||||||
|
surveys = db.surveys()
|
||||||
|
|
||||||
|
print("Reading configuration")
|
||||||
|
file_min_age = configuration.read().get('imports', {}).get('file_min_age', 10)
|
||||||
|
|
||||||
print("Reading surveys")
|
print("Reading surveys")
|
||||||
for survey in surveys:
|
for survey in surveys:
|
||||||
|
|||||||
@@ -20,12 +20,11 @@ from datastore import Datastore
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
print("Reading configuration")
|
print("Reading configuration")
|
||||||
surveys = configuration.surveys()
|
|
||||||
file_min_age = configuration.read().get('imports', {}).get('file_min_age', 10)
|
file_min_age = configuration.read().get('imports', {}).get('file_min_age', 10)
|
||||||
|
|
||||||
print("Connecting to database")
|
print("Connecting to database")
|
||||||
db = Datastore()
|
db = Datastore()
|
||||||
db.connect()
|
surveys = db.surveys()
|
||||||
|
|
||||||
print("Reading surveys")
|
print("Reading surveys")
|
||||||
for survey in surveys:
|
for survey in surveys:
|
||||||
|
|||||||
@@ -20,12 +20,11 @@ from datastore import Datastore
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
print("Reading configuration")
|
print("Reading configuration")
|
||||||
surveys = configuration.surveys()
|
|
||||||
file_min_age = configuration.read().get('imports', {}).get('file_min_age', 10)
|
file_min_age = configuration.read().get('imports', {}).get('file_min_age', 10)
|
||||||
|
|
||||||
print("Connecting to database")
|
print("Connecting to database")
|
||||||
db = Datastore()
|
db = Datastore()
|
||||||
db.connect()
|
surveys = db.surveys()
|
||||||
|
|
||||||
print("Reading surveys")
|
print("Reading surveys")
|
||||||
for survey in surveys:
|
for survey in surveys:
|
||||||
|
|||||||
@@ -15,25 +15,4 @@ from datastore import Datastore
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
print("Reading configuration")
|
print("This function is obsolete. Returning with no action")
|
||||||
configs = configuration.files(include_archived = True)
|
|
||||||
|
|
||||||
print("Connecting to database")
|
|
||||||
db = Datastore()
|
|
||||||
#db.connect()
|
|
||||||
|
|
||||||
print("Reading surveys")
|
|
||||||
for config in configs:
|
|
||||||
filepath = config[0]
|
|
||||||
survey = config[1]
|
|
||||||
print(f'Survey: {survey["id"]} ({filepath})')
|
|
||||||
db.set_survey(survey["schema"])
|
|
||||||
if not db.file_in_db(filepath):
|
|
||||||
print("Saving to DB")
|
|
||||||
db.save_file_data(filepath, json.dumps(survey))
|
|
||||||
print("Applying survey configuration")
|
|
||||||
db.apply_survey_configuration()
|
|
||||||
else:
|
|
||||||
print("Already in DB")
|
|
||||||
|
|
||||||
print("Done")
|
|
||||||
|
|||||||
@@ -13,12 +13,12 @@ from datastore import Datastore
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
print("Reading configuration")
|
|
||||||
surveys = configuration.surveys()
|
|
||||||
|
|
||||||
print("Connecting to database")
|
print("Connecting to database")
|
||||||
db = Datastore()
|
db = Datastore()
|
||||||
|
|
||||||
|
print("Reading configuration")
|
||||||
|
surveys = db.surveys()
|
||||||
|
|
||||||
print("Reading surveys")
|
print("Reading surveys")
|
||||||
for survey in surveys:
|
for survey in surveys:
|
||||||
print(f'Survey: {survey["id"]} ({survey["schema"]})')
|
print(f'Survey: {survey["id"]} ({survey["schema"]})')
|
||||||
|
|||||||
Reference in New Issue
Block a user