mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 12:17:08 +00:00
Add function to import raw P1/11.
Based on the analogous import_raw_p190.py code.
This commit is contained in:
62
bin/import_raw_p111.py
Executable file
62
bin/import_raw_p111.py
Executable file
@@ -0,0 +1,62 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
"""
|
||||||
|
Import raw p111.
|
||||||
|
|
||||||
|
For each survey in configuration.surveys(), check for new
|
||||||
|
or modified final P1/11 files and (re-)import them into the
|
||||||
|
database.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
from glob import glob
|
||||||
|
import re
|
||||||
|
import configuration
|
||||||
|
import p111
|
||||||
|
from datastore import Datastore
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
|
||||||
|
print("Reading configuration")
|
||||||
|
surveys = configuration.surveys()
|
||||||
|
|
||||||
|
print("Connecting to database")
|
||||||
|
db = Datastore()
|
||||||
|
db.connect()
|
||||||
|
|
||||||
|
print("Reading surveys")
|
||||||
|
for survey in surveys:
|
||||||
|
print(f'Survey: {survey["id"]} ({survey["schema"]})')
|
||||||
|
|
||||||
|
db.set_survey(survey["schema"])
|
||||||
|
|
||||||
|
raw_p111 = survey["raw"]["p111"]
|
||||||
|
pattern = raw_p111["pattern"]
|
||||||
|
rx = re.compile(pattern["regex"])
|
||||||
|
|
||||||
|
for fileprefix in raw_p111["paths"]:
|
||||||
|
print(f"Path prefix: {fileprefix}")
|
||||||
|
|
||||||
|
for globspec in raw_p111["globs"]:
|
||||||
|
fullglob = os.path.join(fileprefix, globspec)
|
||||||
|
for filepath in glob(fullglob):
|
||||||
|
print(f"Found {filepath}")
|
||||||
|
|
||||||
|
if not db.file_in_db(filepath):
|
||||||
|
print("Importing")
|
||||||
|
|
||||||
|
match = rx.match(os.path.basename(filepath))
|
||||||
|
file_info = dict(zip(pattern["captures"], match.groups()))
|
||||||
|
|
||||||
|
p111_data = p111.from_file(filepath)
|
||||||
|
|
||||||
|
print("Saving")
|
||||||
|
|
||||||
|
p111_records = p111.p111_type("S", p111_data)
|
||||||
|
|
||||||
|
db.save_raw_p111(p111_records, file_info, filepath, survey["epsg"])
|
||||||
|
else:
|
||||||
|
print("Already in DB")
|
||||||
|
|
||||||
|
print("Done")
|
||||||
|
|
||||||
Reference in New Issue
Block a user