jobfile.py revision 1428
12292SN/A# Copyright (c) 2005 The Regents of The University of Michigan 27597Sminkyu.jeong@arm.com# All rights reserved. 37597Sminkyu.jeong@arm.com# 47597Sminkyu.jeong@arm.com# Redistribution and use in source and binary forms, with or without 57597Sminkyu.jeong@arm.com# modification, are permitted provided that the following conditions are 67597Sminkyu.jeong@arm.com# met: redistributions of source code must retain the above copyright 77597Sminkyu.jeong@arm.com# notice, this list of conditions and the following disclaimer; 87597Sminkyu.jeong@arm.com# redistributions in binary form must reproduce the above copyright 97597Sminkyu.jeong@arm.com# notice, this list of conditions and the following disclaimer in the 107597Sminkyu.jeong@arm.com# documentation and/or other materials provided with the distribution; 117597Sminkyu.jeong@arm.com# neither the name of the copyright holders nor the names of its 127597Sminkyu.jeong@arm.com# contributors may be used to endorse or promote products derived from 137597Sminkyu.jeong@arm.com# this software without specific prior written permission. 142292SN/A# 152292SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 162292SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 172292SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 182292SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 192292SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 202292SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 212292SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 222292SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 232292SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 242292SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 252292SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 262292SN/A# 272292SN/A# Authors: Nathan Binkert 282292SN/A 292292SN/Afrom os.path import expanduser, isfile, join as joinpath 302292SN/Aimport sys 312292SN/A 322292SN/Adef crossproduct(options): 332292SN/A number = len(options) 342292SN/A indexes = [ 0 ] * number 352292SN/A maxes = [ len(opt) for opt in options ] 362292SN/A def next(): 372292SN/A for i in xrange(number - 1, -1, -1): 382292SN/A indexes[i] += 1 392689Sktlim@umich.edu if indexes[i] < maxes[i]: 402689Sktlim@umich.edu return False 412689Sktlim@umich.edu 422292SN/A indexes[i] = 0 432292SN/A return True 443326Sktlim@umich.edu 458229Snate@binkert.org done = False 466658Snate@binkert.org while not done: 472733Sktlim@umich.edu result = [] 482907Sktlim@umich.edu for i in xrange(number): 492292SN/A result.append(options[i][indexes[i]]) 508232Snate@binkert.org yield result 518232Snate@binkert.org done = next() 528232Snate@binkert.org 532722Sktlim@umich.educlass JobFile(object): 542669Sktlim@umich.edu def __init__(self, jfile): 552292SN/A self.data = {} 562790Sktlim@umich.edu jfile = expanduser(jfile) 572790Sktlim@umich.edu if not isfile(jfile): 582790Sktlim@umich.edu for p in sys.path: 592790Sktlim@umich.edu if isfile(joinpath(p, jfile)): 602669Sktlim@umich.edu jfile = joinpath(p, jfile) 612678Sktlim@umich.edu break 622678Sktlim@umich.edu 635606Snate@binkert.org execfile(jfile, self.data) 642292SN/A self.options = self.data['options'] 652678Sktlim@umich.edu self.environment = self.data['environment'] 662292SN/A self.jobinfo = {} 672292SN/A self.jobs = [] 682669Sktlim@umich.edu for job in crossproduct(self.options): 692292SN/A jobname = '.'.join([ id[0] for id in job ]) 702678Sktlim@umich.edu self.jobs.append(jobname) 712292SN/A list = [] 722678Sktlim@umich.edu for info in job: 732678Sktlim@umich.edu for item in info[1:]: 742678Sktlim@umich.edu list.append(item) 754319Sktlim@umich.edu self.jobinfo[jobname] = list 764319Sktlim@umich.edu 774319Sktlim@umich.edu def env(self, jobname): 784319Sktlim@umich.edu env = {} 794319Sktlim@umich.edu for key,val in self.jobinfo[jobname]: 802678Sktlim@umich.edu env[key] = val 812678Sktlim@umich.edu 822292SN/A for key,val in self.environment: 832678Sktlim@umich.edu env[key] = val 842678Sktlim@umich.edu return env 855336Shines@cs.fsu.edu 862678Sktlim@umich.edu def printinfo(self, jobname): 874873Sstever@eecs.umich.edu print '%s:' % jobname 882678Sktlim@umich.edu for key,val in self.jobinfo[jobname]: 892292SN/A print ' %s = %s' % (key, val) 902678Sktlim@umich.edu 912678Sktlim@umich.edu for key,val in self.environment: 922678Sktlim@umich.edu print ' %s = %s' % (key, val) 932678Sktlim@umich.edu