#! /usr/bin/env python ##@namespace ush.hwrf_datastore # A utility script for dumping or modifying the contents of an HWRF # sqlite3 database file. # # This script can perform one of several operations on an sqlite3 file # generated by the HWRF system. It is called as follows: # @code{.sh} # hwrf_datastore.py OP [ARG] file1.sqlite3 [file2.sqlite3 [...]] # @endcode # # Valid operations (OP) are: # * DUMP --- dump entire database to stdout # * UNFAIL --- mark all failed or running tasks as unstarted # * UNRUN --- mark all tasks as unstarted # * UNRUN_ONE taskname --- unrun the specified task. #Only UNRUN_ONE takes an argument, and that argument is mandatory: the #task to "unrun". The argument is the task id, which is everything in #the id after the %s:: in the output of a call to hwrf_datastore.py DUMP. import logging,sys import produtil.datastore from produtil.datastore import Datastore,TASK_CATEGORY,UNSTARTED,COMPLETED def unfail(ds): """!Marks all tasks as not having failed. @param ds the produtil.datastore.Datastore to modify.""" with ds.transaction() as t: t.mutate("""UPDATE products SET available=? WHERE id LIKE '%s%%' AND NOT available=?"""%(TASK_CATEGORY), (UNSTARTED,COMPLETED)) def unrun(ds): """!Marks all products as unavailable and tasks as unstarted. @param ds the produtil.datastore.Datastore to modify.""" with ds.transaction() as t: t.mutate("UPDATE products SET available=?",(UNSTARTED,)) def unrun_one(ds,did): """!Marks a specific task as unstarted. @param ds the produtil.datastore.Datastore to modify. @param did the taskname""" with ds.transaction() as t: taskid="%s::%s"%(TASK_CATEGORY,str(did)) print('Marking %s as unstarted.'%(taskid,), file=sys.stderr) t.mutate("UPDATE products SET available=? WHERE id=?", (UNSTARTED,taskid)) def dump(ds): """!Dumps the contents of the given Datastore to stdout @param ds the produtil.datastore.Datastore to dump""" ds.dump() def usage(args): """!Sends a program usage message to stderr and exits with status 2 @param args the command-line arguments that were provided.""" print('''FORMAT: hwrf_datastore.py OP [ARG] file1.sqlite3 [file2.sqlite3 [...]] where OP is one of: DUMP - dump entire database to stdout UNFAIL - mark all failed or running tasks as unstarted UNRUN - mark all tasks as unstarted UNRUN_ONE - see below Only UNRUN_ONE takes an argument, and that argument is mandatory: the task to "unrun". The argument is the task id, which is everything in the id after the %s:: in the output of ab hwrf_datastore.py DUMP. '''%(TASK_CATEGORY,), file=sys.stderr) for arg in args: print(arg, file=sys.stderr) sys.exit(2) def main(): """!Main program. Parses arguments and calls other functions in this program to do the real work.""" if len(sys.argv)<3: usage() first_arg=2 opargs=[] readonly=False if sys.argv[1].upper()=='UNFAIL': op=unfail elif sys.argv[1].upper()=='DUMP': op=dump elif sys.argv[1].upper()=='UNRUN': op=unrun elif sys.argv[1].upper()=='UNRUN_ONE': op=unrun_one opargs=[sys.argv[2]] first_arg=3 else: usage('Unrecognized datastore operation %s'%(sys.argv[1],)) if len(sys.argv)