#!/usr/bin/python # # # 7/23/2015 Paul Mattione # # # This script makes the names of the TAGH-channels in the translation table have a consistent format. # Specifically, the ADC channel names are renamed from TAGH-# to TAGH-A-#, in order to match the tdcs which are TAGH-T-# # 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 cur.execute("SELECT * FROM Channel WHERE name='TAGH-1'") Nrows = len( cur.fetchall() ) if Nrows == 0: print 'Fix has already been applied, exiting' sys.exit(-1) for channel in range(1, 234): query = "UPDATE Channel SET name='TAGH-A-%s' WHERE name='TAGH-%s'" % (channel, channel) cur.execute(query) print 'Done'