Do not import gun data if sequence has no shots.

Doing otherwise will result in the gun data file
appearing has having been read, but no data will
have been saved as there was nowhere to save to.

Fixes #29.
This commit is contained in:
D. Berge
2020-10-03 00:44:55 +02:00
parent 39256a4917
commit a101542bc2

View File

@@ -483,6 +483,21 @@ class Datastore:
#self.del_hash("*online*", cursor) #self.del_hash("*online*", cursor)
# The shots should already exist, e.g., from a P1 import # The shots should already exist, e.g., from a P1 import
# …but what about if the SMSRC file gets read *before* the P1?
# We need to check
qry = "SELECT count(*) FROM raw_shots WHERE sequence = %s;"
values = (fileinfo["sequence"],)
cursor.execute(qry, values)
shotcount = cursor.fetchone()[0]
if shotcount == 0:
# No shots yet or not all imported, so we do *not*
# save the gun data. It will eventually get picked
# up in the next run.
# Let's remove the file from the file list and bail
# out.
print("No raw shots for sequence", fileinfo["sequence"])
self.conn.rollback()
return
values = [ (json.dumps(record), fileinfo["sequence"], record["shot"]) for record in records ] values = [ (json.dumps(record), fileinfo["sequence"], record["shot"]) for record in records ]