2 # Copyright (c) 2005 The Regents of The University of Michigan
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
7 # met: redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer;
9 # redistributions in binary form must reproduce the above copyright
10 # notice, this list of conditions and the following disclaimer in the
11 # documentation and/or other materials provided with the distribution;
12 # neither the name of the copyright holders nor the names of its
13 # contributors may be used to endorse or promote products derived from
14 # this software without specific prior written permission.
16 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 import os
, os
.path
, re
, socket
, sys
32 from os
import environ
as env
, listdir
33 from os
.path
import basename
, isdir
, isfile
, islink
, join
as joinpath
34 from filecmp
import cmp as filecmp
35 from shutil
import copyfile
38 if dir.startswith('/.automount/'):
39 dir = '/n/%s' % dir[12:]
40 elif not dir.startswith('/n/'):
41 dir = '/n/%s%s' % (socket
.gethostname().split('.')[0], dir)
44 progpath
= nfspath(sys
.path
[0])
45 progname
= basename(sys
.argv
[0])
48 %(progname)s [-c] [-e] [-f] [-q queue] [-v] <regexp>
49 -c clean directory if job can be run
50 -e only echo pbs command info, don't actually send the job
51 -f force the job to run regardless of state
52 -q <queue> submit job to the named queue
55 %(progname)s -l [-v] <regexp>
56 -l list job names, don't submit
57 -v be verbose (list job parameters)
65 opts
, args
= getopt
.getopt(sys
.argv
[1:], '-cd:efhlq:v')
66 except getopt
.GetoptError
:
76 rootdir
= nfspath(os
.getcwd())
96 basedir
= joinpath(rootdir
, 'Base')
97 linkdir
= joinpath(rootdir
, 'Link')
100 exprs
.append(re
.compile(arg
))
102 if not listonly
and not onlyecho
and isdir(linkdir
):
104 print 'Checking for outdated files in Link directory'
105 entries
= listdir(linkdir
)
106 for entry
in entries
:
107 link
= joinpath(linkdir
, entry
)
108 if not islink(link
) or not isfile(link
):
111 base
= joinpath(basedir
, entry
)
112 if not isfile(base
) or not filecmp(link
, base
):
113 print 'Base/%s is different than Link/%s: copying' % (entry
, entry
)
116 import job
, jobfile
, pbs
118 test
= jobfile
.JobFile(joinpath(basedir
, 'test.py'))
121 for jobname
in test
.jobs
:
123 joblist
.append(jobname
)
127 if expr
.match(jobname
):
128 joblist
.append(jobname
)
133 for jobname
in joblist
:
134 test
.printinfo(jobname
)
136 for jobname
in joblist
:
142 for jobname
in joblist
:
143 jobdir
= joinpath(rootdir
, jobname
)
144 if os
.path
.exists(jobname
):
146 if os
.path
.isfile(joinpath(jobdir
, '.success')):
149 if os
.path
.isfile(joinpath(jobdir
, '.start')) and \
150 not os
.path
.isfile(joinpath(jobdir
, '.stop')):
154 sys
.exit('job directory not clean!')
162 for jobname
in joblist
:
163 jobdir
= joinpath(rootdir
, jobname
)
165 if not onlyecho
and not os
.path
.isdir(jobdir
):
166 sys
.exit('%s is not a directory. Cannot build job' % jobdir
)
168 print 'Job name: %s' % jobname
169 print 'Job directory: %s' % jobdir
172 qsub
.pbshost
= 'simpool.eecs.umich.edu'
173 qsub
.stdout
= joinpath(jobdir
, 'jobout')
176 qsub
.node_type
= 'FAST'
177 qsub
.env
['ROOTDIR'] = rootdir
180 qsub
.build(joinpath(progpath
, 'job.py'))
183 print 'PBS Command: %s' % qsub
.command
188 print 'PBS Jobid: %s' % qsub
.result