send.py revision 1381
11689SN/A#!/usr/bin/env python 210333Smitch.hayenga@arm.com# Copyright (c) 2005 The Regents of The University of Michigan 39920Syasuko.eckert@amd.com# All rights reserved. 47944SGiacomo.Gabrielli@arm.com# 57944SGiacomo.Gabrielli@arm.com# Redistribution and use in source and binary forms, with or without 67944SGiacomo.Gabrielli@arm.com# modification, are permitted provided that the following conditions are 77944SGiacomo.Gabrielli@arm.com# met: redistributions of source code must retain the above copyright 87944SGiacomo.Gabrielli@arm.com# notice, this list of conditions and the following disclaimer; 97944SGiacomo.Gabrielli@arm.com# redistributions in binary form must reproduce the above copyright 107944SGiacomo.Gabrielli@arm.com# notice, this list of conditions and the following disclaimer in the 117944SGiacomo.Gabrielli@arm.com# documentation and/or other materials provided with the distribution; 127944SGiacomo.Gabrielli@arm.com# neither the name of the copyright holders nor the names of its 137944SGiacomo.Gabrielli@arm.com# contributors may be used to endorse or promote products derived from 147944SGiacomo.Gabrielli@arm.com# this software without specific prior written permission. 152326SN/A# 161689SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 171689SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 181689SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 191689SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 201689SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 211689SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 221689SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 231689SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 241689SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 251689SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 261689SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 271689SN/A# 281689SN/A# Authors: Ali Saidi 291689SN/A# Nathan Binkert 301689SN/A 311689SN/Aimport os, os.path, re, sys 321689SN/Afrom os import environ as env, listdir 331689SN/Afrom os.path import basename, isdir, isfile, islink, join as joinpath 341689SN/Afrom filecmp import cmp as filecmp 351689SN/Afrom shutil import copyfile 361689SN/A 371689SN/Aprogname = basename(sys.argv[0]) 381689SN/Ausage = """\ 391689SN/AUsage: 402665Ssaidi@eecs.umich.edu %(progname)s [-c] [-e] [-f] [-q queue] [-v] <regexp> 412665Ssaidi@eecs.umich.edu -c clean directory if job can be run 422831Sksewell@umich.edu -e only echo pbs command info, don't actually send the job 431689SN/A -f force the job to run regardless of state 441689SN/A -q <queue> submit job to the named queue 459944Smatt.horsnell@ARM.com -v be verbose 469944Smatt.horsnell@ARM.com 479944Smatt.horsnell@ARM.com %(progname)s -l [-v] <regexp> 482064SN/A -l list job names, don't submit 491060SN/A -v be verbose (list job parameters) 501060SN/A 5113449Sgabeblack@google.com %(progname)s -h 522292SN/A -h display this help 531717SN/A""" % locals() 548232Snate@binkert.org 554762Snate@binkert.orgtry: 566221Snate@binkert.org import getopt 574762Snate@binkert.org opts, args = getopt.getopt(sys.argv[1:], '-cd:efhlq:v') 581060SN/Aexcept getopt.GetoptError: 598737Skoansin.tan@gmail.com sys.exit(usage) 608737Skoansin.tan@gmail.com 618737Skoansin.tan@gmail.comclean = False 625529Snate@binkert.orgonlyecho = False 631061SN/Aexprs = [] 6413429Srekai.gonzalezalberquilla@arm.comforce = False 655606Snate@binkert.orglistonly = False 668581Ssteve.reinhardt@amd.comqueue = '' 678581Ssteve.reinhardt@amd.comverbose = False 681060SN/Arootdir = re.sub(r'^/\.automount/', r'/n/', os.getcwd()) 692292SN/Afor opt,arg in opts: 702292SN/A if opt == '-c': 712292SN/A clean = True 722292SN/A if opt == '-d': 732292SN/A rootdir = arg 742292SN/A if opt == '-e': 752326SN/A onlyecho = True 762292SN/A if opt == '-f': 772292SN/A force = True 782292SN/A if opt == '-h': 792292SN/A print usage 802292SN/A sys.exit(0) 812292SN/A if opt == '-l': 825336Shines@cs.fsu.edu listonly = True 832292SN/A if opt == '-q': 844873Sstever@eecs.umich.edu queue = arg 852292SN/A if opt == '-v': 862292SN/A verbose = True 872292SN/A 884329Sktlim@umich.edubasedir = joinpath(rootdir, 'Base') 895529Snate@binkert.orglinkdir = joinpath(rootdir, 'Link') 904329Sktlim@umich.edu 914329Sktlim@umich.edufor arg in args: 924329Sktlim@umich.edu exprs.append(re.compile(arg)) 932292SN/A 942292SN/Aif not listonly and not onlyecho and isdir(linkdir): 952292SN/A print 'Checking for outdated files in Link directory' 962292SN/A entries = listdir(linkdir) 972292SN/A for entry in entries: 982292SN/A link = joinpath(linkdir, entry) 995529Snate@binkert.org if not islink(link) or not isfile(link): 1001060SN/A continue 1019920Syasuko.eckert@amd.com 10212109SRekai.GonzalezAlberquilla@arm.com base = joinpath(basedir, entry) 1039920Syasuko.eckert@amd.com if not isfile(base) or not filecmp(link, base): 10412109SRekai.GonzalezAlberquilla@arm.com print 'Base/%s is different than Link/%s: copying' % (entry, entry) 10512109SRekai.GonzalezAlberquilla@arm.com copyfile(link, base) 10612109SRekai.GonzalezAlberquilla@arm.com 1071060SN/Aimport job, jobfile, pbs 1081060SN/A 1091060SN/Atest = jobfile.JobFile(joinpath(basedir, 'test.py')) 1102326SN/A 1111060SN/Ajoblist = [] 1121060SN/Afor jobname in test.jobs: 1131060SN/A if not exprs: 1141060SN/A joblist.append(jobname) 1152292SN/A continue 11613453Srekai.gonzalezalberquilla@arm.com 1176221Snate@binkert.org for expr in exprs: 1186221Snate@binkert.org if expr.match(jobname): 1191060SN/A joblist.append(jobname) 1201060SN/A break 1212307SN/A 1222292SN/Aif listonly: 1232980Sgblack@eecs.umich.edu if verbose: 1242292SN/A for jobname in joblist: 1252292SN/A test.printinfo(jobname) 1262292SN/A else: 1272292SN/A for jobname in joblist: 1282292SN/A print jobname 1292292SN/A sys.exit(0) 1302292SN/A 1312292SN/Aif not onlyecho: 1322292SN/A jl = [] 1332292SN/A for jobname in joblist: 1346221Snate@binkert.org if os.path.exists(jobname): 1356221Snate@binkert.org if not force: 1362292SN/A if os.path.isfile(joinpath(jobname, '.success')): 1372292SN/A continue 1382292SN/A 1392292SN/A if os.path.isfile(joinpath(jobname, '.start')) and \ 1402292SN/A not os.path.isfile(joinpath(jobname, '.stop')): 1412292SN/A continue 1422292SN/A 1432292SN/A if not clean: 1442292SN/A sys.exit('job directory not clean!') 1456221Snate@binkert.org 1466221Snate@binkert.org job.cleandir(jobname) 1472292SN/A else: 1482292SN/A os.mkdir(jobname) 1492831Sksewell@umich.edu jl.append(jobname) 1502292SN/A joblist = jl 1512292SN/A 1522292SN/Afor jobname in joblist: 1532292SN/A jobdir = joinpath(rootdir, jobname) 1542292SN/A 1552292SN/A if not onlyecho and not os.path.isdir(jobdir): 1562292SN/A sys.exit('%s is not a directory. Cannot build job' % jobdir) 1572292SN/A 1582292SN/A print >>sys.stderr, 'Job name: %s' % jobname 1596221Snate@binkert.org print >>sys.stderr, 'Job directory: %s' % jobdir 1606221Snate@binkert.org 1612292SN/A qsub = pbs.qsub() 1622292SN/A qsub.pbshost = 'simpool.eecs.umich.edu' 1632831Sksewell@umich.edu qsub.stdout = joinpath(jobdir, 'jobout') 1642292SN/A qsub.name = jobname 1652292SN/A qsub.join = True 16613449Sgabeblack@google.com qsub.node_type = 'FAST' 16713449Sgabeblack@google.com qsub.onlyecho = onlyecho 1682292SN/A qsub.env['ROOTDIR'] = rootdir 16913453Srekai.gonzalezalberquilla@arm.com qsub.verbose = verbose 17013453Srekai.gonzalezalberquilla@arm.com if len(queue): 17113453Srekai.gonzalezalberquilla@arm.com qsub.queue = queue 1722292SN/A 1732292SN/A qsub.do(joinpath(basedir, 'job.py')) 1742292SN/A print >>sys.stderr, '' 1752292SN/A