#!/usr/bin/python # # # 8/10/2015 Paul Mattione # # ##### Fixes the FCAL names # # Before this fix, the FCAL names contained spaces and commas, which where difficult to deal with # # Replace them and the parentheses with colons (and just remove the space) # 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='FCAL (-24,-1)'") Nrows = len( cur.fetchall() ) if Nrows == 0: print 'Fix has already been applied, exiting' sys.exit(-1) cur.execute("SELECT name FROM Channel WHERE system='FCAL' and col_name='adc_chanid'") for name in cur.fetchall() : new_name = name["name"] new_name = new_name.replace(" ", "") new_name = new_name.replace("(", ":") new_name = new_name.replace(",", ":") new_name = new_name.replace(")", "") #print "Replace ", name[0], " with ", new_name, "\n" query = "UPDATE Channel SET name='%s' WHERE name='%s'" % (new_name, name[0]) cur.execute(query) print 'Done'