Fix NTBP detection.

Fixes #25.
This commit is contained in:
D. Berge
2020-09-08 18:36:30 +02:00
parent 3c4ed6665c
commit 351d2a474b
2 changed files with 34 additions and 4 deletions

View File

@@ -163,6 +163,29 @@ class Datastore:
# we assume that we are in the middle of a transaction # we assume that we are in the middle of a transaction
return res return res
def set_ntbp(self, path, ntbp, cursor = None):
"""
Set or remove a sequence's NTBP flag
"""
if cursor is None:
cur = self.conn.cursor()
else:
cur = cursor
hash = file_hash(path)
qry = """
UPDATE raw_lines rl
SET ntbp = %s
FROM raw_shots rs, files f
WHERE rs.hash = f.hash AND rs.sequence = rl.sequence AND f.hash = %s;
"""
cur.execute(qry, (ntbp, hash))
if cursor is None:
self.maybe_commit()
# We do not commit if we've been passed a cursor, instead
# we assume that we are in the middle of a transaction
def save_preplots(self, lines, path, preplot_class, epsg = 0): def save_preplots(self, lines, path, preplot_class, epsg = 0):
""" """
Save preplot data. Save preplot data.

View File

@@ -51,6 +51,11 @@ if __name__ == '__main__':
filepath = str(filepath) filepath = str(filepath)
print(f"Found {filepath}") print(f"Found {filepath}")
if ntbpRx:
ntbp = ntbpRx.search(filepath) is not None
else:
ntbp = False
if not db.file_in_db(filepath): if not db.file_in_db(filepath):
print("Importing") print("Importing")
@@ -62,10 +67,6 @@ if __name__ == '__main__':
continue continue
file_info = dict(zip(pattern["captures"], match.groups())) file_info = dict(zip(pattern["captures"], match.groups()))
if ntbpRx:
ntbp = ntbpRx.match(filepath) is not None
else:
ntbp = False
p111_data = p111.from_file(filepath) p111_data = p111.from_file(filepath)
@@ -77,5 +78,11 @@ if __name__ == '__main__':
else: else:
print("Already in DB") print("Already in DB")
# Update the NTBP status to whatever the latest is,
# as it might have changed.
db.set_ntbp(filepath, ntbp)
if ntbp:
print("Sequence is NTBP")
print("Done") print("Done")