mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 07:37:08 +00:00
@@ -15,6 +15,7 @@ import re
|
|||||||
import time
|
import time
|
||||||
import configuration
|
import configuration
|
||||||
import smsrc
|
import smsrc
|
||||||
|
import fwr
|
||||||
from datastore import Datastore
|
from datastore import Datastore
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
@@ -33,17 +34,21 @@ if __name__ == '__main__':
|
|||||||
db.set_survey(survey["schema"])
|
db.set_survey(survey["schema"])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
raw_smsrc = survey["raw"]["smsrc"]
|
raw_smsrc = survey["raw"]["source"]["smsrc"]["header"]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
print("No SmartSource data configuration")
|
print("No SmartSource data configuration")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
flags = 0
|
# NOTE I've no idea what this is 🤔
|
||||||
if "flags" in raw_smsrc:
|
# flags = 0
|
||||||
configuration.rxflags(raw_smsrc["flags"])
|
# if "flags" in raw_smsrc:
|
||||||
|
# configuration.rxflags(raw_smsrc["flags"])
|
||||||
|
|
||||||
pattern = raw_smsrc["pattern"]
|
lineNameInfo = raw_smsrc.get("lineNameInfo")
|
||||||
rx = re.compile(pattern["regex"], flags)
|
pattern = raw_smsrc.get("pattern")
|
||||||
|
rx = None
|
||||||
|
if pattern and pattern.get("regex"):
|
||||||
|
rx = re.compile(pattern["regex"])
|
||||||
|
|
||||||
for fileprefix in raw_smsrc["paths"]:
|
for fileprefix in raw_smsrc["paths"]:
|
||||||
realprefix = configuration.translate_path(fileprefix)
|
realprefix = configuration.translate_path(fileprefix)
|
||||||
@@ -64,14 +69,39 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
print("Importing")
|
print("Importing")
|
||||||
|
|
||||||
match = rx.match(os.path.basename(logical_filepath))
|
if rx:
|
||||||
if not match:
|
match = rx.match(os.path.basename(logical_filepath))
|
||||||
error_message = f"File path not matching the expected format! ({logical_filepath} ~ {pattern['regex']})"
|
if not match:
|
||||||
print(error_message, file=sys.stderr)
|
error_message = f"File path not matching the expected format! ({logical_filepath} ~ {pattern['regex']})"
|
||||||
print("This file will be ignored!")
|
print(error_message, file=sys.stderr)
|
||||||
continue
|
print("This file will be ignored!")
|
||||||
|
continue
|
||||||
|
|
||||||
file_info = dict(zip(pattern["captures"], match.groups()))
|
file_info = dict(zip(pattern["captures"], match.groups()))
|
||||||
|
file_info["meta"] = {}
|
||||||
|
|
||||||
|
|
||||||
|
if lineNameInfo:
|
||||||
|
basename = os.path.basename(physical_filepath)
|
||||||
|
fields = lineNameInfo.get("fields", {})
|
||||||
|
fixed = lineNameInfo.get("fixed")
|
||||||
|
try:
|
||||||
|
parsed_line = fwr.parse_line(basename, fields, fixed)
|
||||||
|
except ValueError as err:
|
||||||
|
parsed_line = "Line format error: " + str(err)
|
||||||
|
if type(parsed_line) == str:
|
||||||
|
print(parsed_line, file=sys.stderr)
|
||||||
|
print("This file will be ignored!")
|
||||||
|
continue
|
||||||
|
|
||||||
|
file_info = {}
|
||||||
|
file_info["sequence"] = parsed_line["sequence"]
|
||||||
|
file_info["line"] = parsed_line["line"]
|
||||||
|
del(parsed_line["sequence"])
|
||||||
|
del(parsed_line["line"])
|
||||||
|
file_info["meta"] = {
|
||||||
|
"fileInfo": parsed_line
|
||||||
|
}
|
||||||
|
|
||||||
smsrc_records = smsrc.from_file(physical_filepath)
|
smsrc_records = smsrc.from_file(physical_filepath)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user