mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 09:07:09 +00:00
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.
40 lines
896 B
Python
Executable File
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")
|