#!/usr/bin/env python ################################################################################ #\defgroup difxjobstatus DiFXJobStatus # #\brief Obtain the "status" of job(s) on the DiFX server using the .input file(s) # path. # #Usage: DiFXJobStatus [options] path # # DiFXJobStatus can be used to display the most recent "status" of a job # or list of jobs on the DiFX server. The status information is contained in # the .difxlog file associated with each job. If a job has been run with logging # facilities turned on, the .difxlog file will contain information about it - # DiFXJobStatus simply picks up the latest "STATUS" item and reports it. # The status will be something like "completed", "failed", or "running". If # the .difxlog file does not exit, DiFXJobStatus will report that, too. # # Jobs are specified by their .input file # paths - wildcards can be used for a list of jobs. # # DiFXJobStatus can be set to run in a "monitor" mode where it will # repeatedly ask for the status of a job. This provides a simple way of watching # a job or group of jobs as they run and determining when they are finished. # #

Command Line Arguments

# # #
-D, --difx VERSION
Run using a specific DiFX version. If not specified # the value of the DIFX_VERSION environment variable will # be used. Failing that, \"DIFX-DEVEL\" will be used. #
-h, --help
Print help information and quit. #
-H, --hostname NAME
Use NAME as the host of the difxServer program. # Default is to use DIFX_CONTROL_HOST environment variable. #
-P, --port PORT
Use PORT as the TCP port to communicated with the difxServer. # Default is to use DIFX_CONTROL_PORT environment variable. #
-l, --long
Provide a \"long\" job status, which includes job run history. # Currently not implemented. #
-r, --repeat SEC
Repeat the job status command after a delay of SEC seconds. # By default there is no repeat. #
-s, --short
Provide only the final job state as the status (much faster # and easier to deal with if you have lots of jobs). This is the # default. #
-t, --time
Turn off the time stamp in the short output. By default a # time stamp is displayed with each status. #
################################################################################ program = 'DiFXJobStatus' version = '0.1' author = 'John Spitzak' verdate = '20150909' import os import sys import time import DiFXControl #=============================================================================== # MAIN #=============================================================================== host = None port = None # Locate a "default" DiFX Version from environment variables. User may change this # with command line arguments. try: DiFXVersion = os.environ["DIFX_VERSION"] except: DiFXVersion = "DIFX-DEVEL" try: i = 1 pathStr = None repeat = False repeatSeconds = 0 shortStatus = True displayTime = True while i < len( sys.argv ): # Check against legal argument types. The final argument must be a path to # .input file(s). if sys.argv[i] in [ "-h", "--help" ]: print '\n%s ver %s %s %s' % (program, version, author, verdate) print "Obtain the status of jobs on the DiFX software correlator." print "Usage: %s [options] " % ( sys.argv[0] ) print "" print "Options can include:" print "" print " --difx VERSION" print " -D VERSION Run using a specific DiFX version. If not specified" print " the value of the DIFX_VERSION environment variable will" print " be used. Failing that, \"DIFX-DEVEL\" will be used." print "" print " --help" print " -h Print this help information and quit." print "" print " --hostname NAME" print " -H NAME Use NAME as the host of the difxServer program." print " Default is to use DIFX_CONTROL_HOST environment variable." print "" print " --port PORT" print " -P PORT Use PORT as the TCP port to communicated with the difxServer." print " Default is to use DIFX_CONTROL_PORT environment variable." print "" print " --long" print " -l Provide a \"long\" job status, which includes job run history." print " Currently not implemented." print "" print " --repeat SEC" print " -r SEC Repeat the job status command after a delay of SEC seconds." print " By default there is no repeat." print "" print " --short" print " -s Provide only the final job state as the status (much faster" print " and easier to deal with if you have lots of jobs). This is the" print " default." print "" print " --time" print " -t Turn off the time stamp in the short output. By default a" print " time stamp is displayed with each status." print "" print "" exit( 0 ) elif sys.argv[i] in [ "-H", "--hostname" ]: host = sys.argv[i+1] i = i + 1 elif sys.argv[i] in [ "-D", "--difx" ]: DiFXVersion = sys.argv[i+1] i = i + 1 elif sys.argv[i] in [ "-P", "--port" ]: port = int( sys.argv[i+1] ) i = i + 1 elif sys.argv[i] in [ "-r", "--repeat" ]: repeatSeconds = int( sys.argv[i+1] ) repeat = True i = i + 1 elif sys.argv[i] in [ "-s", "--short" ]: shortStatus = True elif sys.argv[i] in [ "-t", "--time" ]: displayTime = False else: pathStr = sys.argv[i] i = i + 1 except RuntimeError: print "Usage: %s [options] " % ( sys.argv[0] ) exit( 0 ) keepGoing = True # Open a new connection to the difxServer... difx = DiFXControl.Client() difx.connect( host, port ) if difx.socketOK: difx.monitor() difx.version( DiFXVersion ) while difx.socketOK and keepGoing: statusInfo = difx.jobStatus( pathStr, shortStatus ) # How we interpret the status information is dependent on what we asked # for...shortStatus includes only a time stamp and one line of data for # each .input file. if shortStatus: statusTime = statusInfo[0] statusList = statusInfo[1] if statusList == None: print "No .input files found." else: if repeat: os.system( 'cls' if os.name == 'nt' else 'clear' ) if statusTime != None and displayTime: print statusTime maxLen1 = 0 maxLen2 = 0 for item in statusList: if len( item[0] ) > maxLen1: maxLen1 = len( item[0] ) if displayTime and len( item[1][1] ) > maxLen2: maxLen2 = len( item[1][1] ) if displayTime: maxLen2 = maxLen2 + 5 for item in statusList: outStr = item[0] while len( outStr ) < maxLen1 + 5: outStr += " " outStr += item[1][1] if displayTime: while len( outStr ) < maxLen1 + maxLen2 + 5: outStr += " " outStr += item[1][0] print outStr if repeat: try: time.sleep( repeatSeconds ) except KeyboardInterrupt: keepGoing = False else: keepGoing = False difx.close()