-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathbatch.py
More file actions
72 lines (54 loc) · 2.69 KB
/
batch.py
File metadata and controls
72 lines (54 loc) · 2.69 KB
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 os
from supy import sites, whereami
__prefix = "%s/sites/%s" % (whereami(), sites.prefix())
def subScript():
return "%sSub.sh" % __prefix
def jobTemplate():
return "%sJob.sh" % __prefix
def condorTemplate():
return "%sTemplate.condor" % __prefix
def baseDir(fileName=""):
return fileName[:fileName.rfind('/')]
def condored(script):
return script.replace(".sh", ".condor") if os.path.exists(condorTemplate()) else script
def jobScriptFull(base="", tag="", sample="", iSlice=None, **_):
return "/".join([base, tag, sample, "job%d.sh" % iSlice])
def prepareJob(jobCmd, indexDict):
jobScriptFileName = jobScriptFull(**indexDict)
jobScriptDir = baseDir(jobScriptFileName)
if not os.path.isdir(jobScriptDir): os.system("mkdir -p %s"%jobScriptDir)
with open(jobTemplate()) as template:
with open(jobScriptFileName, 'w') as script:
for line in template.readlines():
if "INSERT_BATCH_SETUP" in line:
for item in ["PYTHONPATH", "LD_LIBRARY_PATH"] :
print >>script, "export %s=%s"%(item, os.environ[item])
print >>script, sites.info(key="extractCommand")
print >>script, "cd " + sites.info(key="workingDir")
else: print >>script, line,
print >>script, jobCmd.replace(os.environ["PWD"],sites.info(key="workingDir"))
os.system("chmod +x "+jobScriptFileName)
condorFileName = condored(jobScriptFileName)
if condorFileName != jobScriptFileName:
condorInputSpec = ",".join([os.environ["PWD"]+".tar",])
condorOutputSpec = "/".join([".",
indexDict["analysis"],
indexDict["tag"],
"%s_%d_%d" % (indexDict["sample"],
indexDict["nSlices"],
indexDict["iSlice"],
),
"",
])
pipes = " | ".join(["cat %s" % condorTemplate(),
"sed s@JOBFLAG@%s@g" % jobScriptFileName,
"sed s@INFLAG@%s@g" % condorInputSpec,
"sed s@OUTFLAG@%s@g" % condorOutputSpec,
"sed s@USERFLAG@%s@g" % os.environ["USER"],
])
os.system(" > ".join([pipes, condorFileName]))
def submitJob(jobScript=""):
subCmd = "; ".join(["cd %s" % baseDir(jobScript),
"%s %s" % (subScript(), condored(jobScript)),
])
os.system(subCmd)