def main(): Script.registerSwitch("f:", "File=", "Get output for jobs with IDs from the file") Script.registerSwitch("g:", "JobGroup=", "Get output for jobs in the given group") # Registering arguments will automatically add their description to the help menu Script.registerArgument(["JobID: DIRAC Job ID"], mandatory=False) sws, args = Script.parseCommandLine(ignoreErrors=True) import DIRAC from DIRAC.Interfaces.API.Dirac import Dirac, parseArguments from DIRAC.Core.Utilities.TimeUtilities import toString, day dirac = Dirac() jobs = [] for sw, value in sws: if sw.lower() in ("f", "file"): if os.path.exists(value): jFile = open(value) jobs += jFile.read().split() jFile.close() elif sw.lower() in ("g", "jobgroup"): group = value jobDate = toString(datetime.datetime.utcnow().date() - 30 * day) result = dirac.selectJobs(jobGroup=value, date=jobDate) if not result["OK"]: if "No jobs selected" not in result["Message"]: print("Error:", result["Message"]) DIRAC.exit(-1) else: jobs += result["Value"] for arg in parseArguments(args): jobs.append(arg) if not jobs: print("Warning: no jobs selected") Script.showHelp() DIRAC.exit(0) result = dirac.deleteJob(jobs) if result["OK"]: print("Deleted jobs %s" % ",".join([str(j) for j in result["Value"]])) exitCode = 0 else: print(result["Message"]) exitCode = 2 DIRAC.exit(exitCode)
def main(): Script.registerSwitch("f:", "File=", "Get output for jobs with IDs from the file") Script.registerSwitch("g:", "JobGroup=", "Get output for jobs in the given group") Script.parseCommandLine(ignoreErrors=True) args = Script.getPositionalArgs() import DIRAC from DIRAC.Interfaces.API.Dirac import Dirac, parseArguments from DIRAC.Core.Utilities.Time import toString, date, day dirac = Dirac() jobs = [] for sw, value in Script.getUnprocessedSwitches(): if sw.lower() in ('f', 'file'): if os.path.exists(value): jFile = open(value) jobs += jFile.read().split() jFile.close() elif sw.lower() in ('g', 'jobgroup'): group = value jobDate = toString(date() - 30 * day) result = dirac.selectJobs(jobGroup=value, date=jobDate) if not result['OK']: if "No jobs selected" not in result['Message']: print("Error:", result['Message']) DIRAC.exit(-1) else: jobs += result['Value'] for arg in parseArguments(args): jobs.append(arg) if not jobs: print("Warning: no jobs selected") Script.showHelp() DIRAC.exit(0) result = dirac.deleteJob(jobs) if result['OK']: print('Deleted jobs %s' % ','.join([str(j) for j in result['Value']])) exitCode = 0 else: print(result['Message']) exitCode = 2 DIRAC.exit(exitCode)
jobs += jFile.read().split() jFile.close() elif sw.lower() in ('g', 'jobgroup'): group = value jobDate = toString(date() - 30 * day) result = dirac.selectJobs(jobGroup=value, date=jobDate) if not result['OK']: if "No jobs selected" not in result['Message']: print("Error:", result['Message']) DIRAC.exit(-1) else: jobs += result['Value'] for arg in parseArguments(args): jobs.append(arg) if not jobs: print("Warning: no jobs selected") Script.showHelp() DIRAC.exit(0) result = dirac.deleteJob(jobs) if result['OK']: print('Deleted jobs %s' % ','.join([str(j) for j in result['Value']])) exitCode = 0 else: print(result['Message']) exitCode = 2 DIRAC.exit(exitCode)
# returns a list of tuples. each one contains: # - visit (6 digit string) # - index (int) # - Dirac job ID (int) def readJobList(filename): listfile = open(filename, 'r') lines = listfile.readlines() listfile.close() result = [] for line in lines: line = line.strip() bits = line.split(' ') result.append( (bits[0], int(bits[1]), int(bits[2])) ) return result # start up Dirac first and create an instance dirac = Dirac() # read master job list joblist = readJobList(joblistfile) print "Read", len(joblist), "jobs from job list" # make a list of job IDs so we can cancel them all at once jobidlist = [] for i in joblist: #if i[2] >= 15870062: jobidlist.append(i[2]) dirac.deleteJob(jobidlist)
jobs += jFile.read().split() jFile.close() elif sw.lower() in ( 'g', 'jobgroup' ): group = value jobDate = toString( date() - 30 * day ) result = dirac.selectJobs( jobGroup = value, date = jobDate ) if not result['OK']: if not "No jobs selected" in result['Message']: print "Error:", result['Message'] DIRAC.exit( -1 ) else: jobs += result['Value'] for arg in parseArguments( args ): jobs.append( arg ) if not jobs: print "Warning: no jobs selected" Script.showHelp() DIRAC.exit( 0 ) result = dirac.deleteJob( jobs ) if result['OK']: print 'Deleted jobs %s' % ','.join( [str( j ) for j in result['Value'] ] ) exitCode = 0 else: print result['Message'] exitCode = 2 DIRAC.exit( exitCode )