#!/usr/bin/python # # # 11/19/2014 David Lawrence # # # This script will modify a tt.db file to fix a problem with # the rocid for the two crates used by the PS. These originally # were set to 0, then "fixed" by the tt_fix_ps.py script to have # rocid's 97 and 98. Only to realize later that the IP addresses # assigned to these were 83 and 84. This script fixes the problem # by changing: # rocid=97 -> rocid=83 # rocid=98 -> rocid=84 # 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 if this has already been updated cur.execute('SELECT * FROM Crate WHERE rocid=97 OR rocid=98') s_rows = cur.fetchall() if len(s_rows) != 2: print 'Did not find exactly 2 crates with rocid==97 or rocid==98.' print 'This file may already updated or may need to have the' print 'tt_fix_ps.py script run on it first.' print 'Exiting now without modifying the file.' sys.exit(0); # Update rocids query = 'UPDATE Crate SET rocid=83 WHERE rocid=97' print query cur.execute(query) query = 'UPDATE Crate SET rocid=84 WHERE rocid=98' print query cur.execute(query) # Now, re-query for the ids and print the updated versions # Get crateid for rocPS1 crate. cur.execute('SELECT * FROM Crate WHERE rocid=83 OR rocid=84') s_rows = cur.fetchall() if len(s_rows) != 2: print 'Did not find exactly 2 crates with rocid==83 or rocid==84' print 'after update! What happened! You\'re going to need to go' print 'in and figure out the mess I left by hand.' else: print 'Operation appears to have succeeded!' print 'Done'