-
Notifications
You must be signed in to change notification settings - Fork 1
/
jobsub.py
72 lines (68 loc) · 2.98 KB
/
jobsub.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import msg
import os, re, subprocess
class Jobsub:
# handle jobsub command for runGENIE.sh in dag file
# TODO - need to get more clever with lifetimes for jobs...
def __init__ (self, args, lifetime='23h'):
"""
init a proper jobsub command for dag
"""
# -n option is mandatory for jobsub (otherwise jobs will be run twice...)
self.basecmd = "jobsub -n --OS=%s --resource-provides=usage_model=%s -G %s --expected-lifetime=%s file://%s -p %s -v %s -d %s" % \
(args.os, args.resource, args.group, lifetime, args.run, args.builds+"/"+args.buildNameGE, args.builds+"/"+args.buildNameCmp, args.debug)
# create dag file
self.dagFile = args.paths['top'] + "/GENIE_CI_Validation-" + args.tag + \
"-" + args.build_date + ".dag"
self.root_version = args.root_version.replace("Root","")
# remove is the file exists
try:
os.remove (self.dagFile)
except OSError:
pass
# open dag file tp write
self.dag = open (self.dagFile, 'w')
# prepare submit commands
self.setup = "source /cvmfs/fermilab.opensciencegrid.org/products/common/etc/setups.sh; setup jobsub_client; "
self.subdag = "jobsub_submit_dag -G " + args.group + " file://" + self.dagFile
def submit(self):
"""
close and submit dag
"""
self.dag.close()
msg.info ("Done with dag file. Ready to submit.\n")
# check if run is not empty
if os.stat(self.dagFile).st_size == 0:
msg.warning ("Dag file: " + self.dagFile + " is empty. " + msg.RED + msg.BOLD + "NO JOBS TO RUN!!!\n")
exit (0)
# submit dag
msg.info ("Submitting: " + self.dagFile + "\n")
subprocess.Popen (self.setup + self.subdag, shell=True, executable="/bin/bash")
def addJob (self, inputs, output, logfile, cmd, regre):
"""
print given command with given options to dag file (input files to
copy, path for output, logfilename, command)
"""
# not-so-temporary solution as workaround for jobsub quotes issue (as
# in, we can't have quotes in the command string)
cmd = re.sub (' ', "SPACE", cmd)
inputs = re.sub (' ', "SPACE", inputs)
# write full jobsub command to dag file
if regre is None:
print >>self.dag, self.basecmd + \
" -R " + self.root_version + \
" -i " + inputs + \
" -o " + output + \
" -l " + logfile + \
" -c " + cmd
else:
regre = re.sub (" ", "SPACE", regre )
print >>self.dag, self.basecmd + \
" -R " + self.root_version + \
" -i " + inputs + \
" -o " + output + \
" -l " + logfile + \
" -r " + regre + \
" -c " + cmd
# print custom text to dag
def add (self, text):
print >>self.dag, text