Files
dougal-software/bin/import_preplots.py
D. Berge 700e683022 Import preplot file configuration into database.
We do this so that we can look for the "saillineOffset"
parameter, which we expect to be present in source
preplot imports and allows us to correlate source
and sail lines.

The change to bin/sps.py is necessary to let the JSON
serialisation take place.
2020-10-04 03:42:19 +02:00

47 lines
1.1 KiB
Python
Executable File

#!/usr/bin/python3
"""
Import preplot data.
For each preplot file defined in each survey, check for new
or modified preplots and (re-)import them into the database.
"""
from glob import glob
import sys
import configuration
import preplots
from datastore import Datastore
if __name__ == '__main__':
print("Reading configuration")
surveys = configuration.surveys()
print("Connecting to database")
db = Datastore()
print("Reading surveys")
for survey in surveys:
print(f'Survey: {survey["id"]} ({survey["schema"]})')
db.set_survey(survey["schema"])
for file in survey["preplots"]:
print(f"Preplot: {file['path']}")
if not db.file_in_db(file["path"]):
print("Importing")
try:
preplot = preplots.from_file(file)
except FileNotFoundError:
print(f"File does not exist: {file['path']}", file=sys.stderr)
continue
if type(preplot) is list:
print("Saving to DB")
db.save_preplots(preplot, file["path"], file["class"], survey["epsg"], file)
elif type(preplot) is str:
print(preplot)
else:
print("Already in DB")
print("Done")