-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoCONDOR.py
136 lines (91 loc) · 2.82 KB
/
toCONDOR.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import optparse
import os
import sys
import __main__
from datetime import datetime
#################
##- globals -##
#################
# Time:
global time
now = datetime.now()
time = now.strftime("%y%m%d_%H%M%S")
# Global paths:
global workdir # absolute path to THIS script
workdir = os.path.dirname(os.path.abspath(__main__.__file__))
global logpath
logpath = workdir + '/' + 'logs/'
##############
##- Init -##
##############
if not os.path.exists(workdir + '/logs'): os.makedirs(workdir + '/logs')
if not os.path.exists(workdir + '/bashFiles'): os.makedirs(workdir + '/bashFiles')
if not os.path.exists(workdir + '/condorFiles'): os.makedirs(workdir + '/condorFiles')
###################
##- Functions -##
###################
def identifyCMSSW(command):
""" Function to identify release of a given path """
cmsswpart = False
for part in command.split():
if 'CMSSW' in part:
cmsswpart = part
cmsswpath = ''
for level in cmsswpart.split('/'):
cmsswpath += level + '/'
if 'CMSSW' in level:
cmsswpath += 'src'
break
return cmsswpath
def makeBashFile(command):
cmssw = identifyCMSSW(command)
bashTemplate = """#!/bin/bash
pushd {0}
eval `scramv1 runtime -sh`
pushd
""".format(cmssw)
bashTemplate += command
bashpath = workdir + '/bashFiles/' + 'bash_' + time + '.sh'
_f = open(bashpath, 'w')
_f.write(bashTemplate)
_f.close()
return bashpath
def makeCondorFile(queue, bashpath):
condorTemplate = """
universe = vanilla
executable = $(filename)
output = {0}$(ClusterId).$(ProcId).out
error = {0}$(ClusterId).$(ProcId).err
log = {0}$(ClusterId).log
Notify_user = [email protected]
+JobFlavour = "{1}"
queue filename matching {2}
""".format(logpath, queue, bashpath)
condorpath = workdir + '/condorFiles/' + 'condor_' + time + '.sh'
_f = open(condorpath, 'w')
_f.write(condorTemplate)
_f.close()
return condorpath
##############
##- main -##
##############
if __name__ == "__main__":
## -> Exit if there are missed arguments
if not len(sys.argv) > 2:
sys.exit("Usage: toCONDOR [queue] [command to launch]")
## Collect parameters:
queue = sys.argv[1]
command = ''
for i in range(2, len(sys.argv)):
command += sys.argv[i]
if not i == (len(sys.argv) - 1): command += ' '
## Verbose:
print(" > Launching to queue: " + queue)
print(" > Command to launch: " + command)
## Create bash and condor files for submission:
bashFile = makeBashFile(command)
condorFile = makeCondorFile(queue, bashFile)
## Launch job.
os.system('chmod +x ' + bashFile)
os.system('chmod +x ' + condorFile)
os.system('condor_submit ' + condorFile)