forked from chaselgrove/sjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sjs_qsub
executable file
·109 lines (89 loc) · 2.94 KB
/
sjs_qsub
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
#!/usr/bin/python
# See file COPYING distributed with sjs for copyright and license.
import sys
import os
import getopt
import sjs
def parse_opts(argv):
"""parse options in the passed list
the qsub command line and the options that can be declared by #$ in the
job script are the same, so we abstract out the parsing here
"""
try:
(opts, args) = getopt.getopt(argv, option_string)
except getopt.error, data:
if argv is sys.argv:
sys.stderr.write('%s: %s\n' % (progname, str(data)))
else:
sys.stderr.write('%s: in script: %s\n' % (progname, str(data)))
return None
for (option, value) in opts:
if option == '-@':
if argv is sys.argv:
cluster.log('qsub: ignoring "-@ %s"' % value)
else:
cluster.log('qsub: ignoring "-@ %s" in script' % value)
if option == '-a':
if argv is sys.argv:
cluster.log('qsub: ignoring "-a %s"' % value)
else:
cluster.log('qsub: ignoring "-a %s" in script' % value)
if option == '-o':
options['stdout'] = value
if option == '-e':
options['stderr'] = value
if option == '-S':
options['shell'] = value
if option == '-V':
if argv is sys.argv:
cluster.log('qsub: ignoring "-V %s"' % value)
else:
cluster.log('qsub: ignoring "-V %s" in script' % value)
return args
progname = os.path.basename(sys.argv.pop(0))
option_string = 'o:e:V@:a:S:'
options = {'stdout': '$HOME/$JOB_NAME.o$JOB_ID',
'stderr': '$HOME/$JOB_NAME.e$JOB_ID',
'shell': '/bin/csh'}
try:
cluster = sjs.Cluster()
except sjs.SJSError, data:
sys.stderr.write('%s: %s\n' % (progname, str(data)))
sys.exit(1)
args = parse_opts(sys.argv)
if args is None:
sys.exit(1)
if not args:
cluster.log('qsub reading from stdin')
job_name = 'STDIN'
script = sys.stdin.read()
script_args = []
else:
cluster.log('qsub reading from %s' % args[0])
job_name = os.path.basename(args[0])
script = open(args[0]).read()
script_args = args[1:]
script_argv = []
for line in script.split('\n'):
line = line.strip()
if not line.startswith('#$'):
continue
script_argv.extend(line[2:].strip().split())
script_opts = parse_opts(script_argv)
if script_opts is None:
sys.exit(1)
if script_opts:
msg = '%s: in script: option %s not recognized\n' % (progname,
script_opts[0])
sys.stderr.write(msg)
sys.exit(1)
job = cluster.submit(job_name,
options['shell'],
script,
script_args,
options['stdout'],
options['stderr'])
print 'Your job %d ("%s") has been submitted' % (job.id, job.name)
cluster.start_runner()
sys.exit(0)
# eof