#!/usr/bin/python # # # 12/13/2019 Justin Stevens # # This script fixes TAGM row=21 col=0 in tt.db for RunPeriod-2019-01+ # import sqlite3 as lite import sys import os import re import datetime if len(sys.argv) != 2: print "You must supply a SQLite DB file to modify!" sys.exit(0); # Connect to SQLite DB file db_filename = sys.argv[1] print "" print "opening SQLite DB file: %s" % db_filename print "---------------------------------------------" con = lite.connect(db_filename) with con: # Specify that next cursor should be "dictionary" # (i.e. python's hash map) so columns can be indexed # by name con.row_factory = lite.Row # Create Cursor cur = con.cursor() # Check that this TT file has not already been updated adc_chanid = -1 try: cur.execute("SELECT chanid FROM Channel WHERE name='TAGM-T-21' and channel=26") (adc_chanid,) = cur.fetchone() except: pass # Do nothing here if adc_chanid >= 0: print 'Fix has already been applied, exiting' sys.exit(-1) cur.execute("INSERT INTO Channel Values (619, 45, 'TAGM-T-21', 26, 'TAGM', 'tdc_chanid', 1, 29)") cur.execute("INSERT INTO Channel Values (491, 40, 'TAGM-T-21', 11, 'TAGM', 'disc_chanid', 1, 29)") # Revert old channel back to SPARE cur.execute("INSERT INTO Channel Values (520, 42, 'SPARE', 23, '', 'tdc_chanid', 1, 29)") cur.execute("INSERT INTO Channel Values (392, 34, 'SPARE', 8, '', 'disc_chanid', 1, 29)") print 'Done'