Files
dougal-software/bin/import_survey_config.py
D. Berge 0c7b3146ae Update label definitions when updating survey config.
It will not delete any labels that have been removed
from the configuration, as those may be used, but it
will add new labels and modify existing ones if they
changed.
2020-08-25 17:52:17 +02:00

40 lines
896 B
Python
Executable File

#!/usr/bin/python3
"""
Import survey configuration.
Imports the content of the YAML survey configuration files
into the database (as JSON) so their data is available to
database functions and procedures.
"""
import json
from glob import glob
import configuration
from datastore import Datastore
if __name__ == '__main__':
print("Reading configuration")
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")