jobfile.py (5467:6d9df90d70d7) jobfile.py (5618:1abb23c038d5)
1# Copyright (c) 2005-2006 The Regents of The University of Michigan
2# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are
6# met: redistributions of source code must retain the above copyright
7# notice, this list of conditions and the following disclaimer;
8# redistributions in binary form must reproduce the above copyright

--- 14 unchanged lines hidden (view full) ---

23# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26#
27# Authors: Nathan Binkert
28
29import sys
30
1# Copyright (c) 2005-2006 The Regents of The University of Michigan
2# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are
6# met: redistributions of source code must retain the above copyright
7# notice, this list of conditions and the following disclaimer;
8# redistributions in binary form must reproduce the above copyright

--- 14 unchanged lines hidden (view full) ---

23# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26#
27# Authors: Nathan Binkert
28
29import sys
30
31from attrdict import attrdict, optiondict
32from misc import crossproduct, flatten
31from attrdict import optiondict
32from misc import crossproduct
33
34class Data(object):
35 def __init__(self, name, desc, **kwargs):
36 self.name = name
37 self.desc = desc
38 self.__dict__.update(kwargs)
39
40 def update(self, obj):
41 if not isinstance(obj, Data):
42 raise AttributeError, "can only update from Data object"
43
33
34class Data(object):
35 def __init__(self, name, desc, **kwargs):
36 self.name = name
37 self.desc = desc
38 self.__dict__.update(kwargs)
39
40 def update(self, obj):
41 if not isinstance(obj, Data):
42 raise AttributeError, "can only update from Data object"
43
44 for k,v in obj.__dict__.iteritems():
45 if not k.startswith('_'):
46 self.__dict__[k] = v
44 for key,val in obj.__dict__.iteritems():
45 if key.startswith('_') or key in ('name', 'desc'):
46 continue
47
48 if key not in self.__dict__:
49 self.__dict__[key] = val
50 continue
51
52 if not isinstance(val, dict):
53 if self.__dict__[key] == val:
54 continue
55
56 raise AttributeError, \
57 "%s specified more than once old: %s new: %s" % \
58 (key, self.__dict__[key], val)
59
60 d = self.__dict__[key]
61 for k,v in val.iteritems():
62 if k in d:
63 raise AttributeError, \
64 "%s specified more than once in %s" % (k, key)
65 d[k] = v
66
47 if hasattr(self, 'system') and hasattr(obj, 'system'):
48 if self.system != obj.system:
49 raise AttributeError, \
50 "conflicting values for system: '%s'/'%s'" % \
51 (self.system, obj.system)
52
53 def printinfo(self):
54 if self.name:

--- 33 unchanged lines hidden (view full) ---

88 yield key
89
90 def optiondict(self):
91 result = optiondict()
92 for key in self:
93 result[key] = self[key]
94 return result
95
67 if hasattr(self, 'system') and hasattr(obj, 'system'):
68 if self.system != obj.system:
69 raise AttributeError, \
70 "conflicting values for system: '%s'/'%s'" % \
71 (self.system, obj.system)
72
73 def printinfo(self):
74 if self.name:

--- 33 unchanged lines hidden (view full) ---

108 yield key
109
110 def optiondict(self):
111 result = optiondict()
112 for key in self:
113 result[key] = self[key]
114 return result
115
116 def __repr__(self):
117 d = {}
118 for key,value in self.__dict__.iteritems():
119 if not key.startswith('_'):
120 d[key] = value
121
122 return "<%s: %s>" % (type(self).__name__, d)
123
96 def __str__(self):
97 return self.name
98
99class Job(Data):
100 def __init__(self, options):
101 super(Job, self).__init__('', '')
102
103 config = options[0]._config

--- 282 unchanged lines hidden (view full) ---

386 else:
387 raise AttributeError, \
388 "Could not find file '%s'" % jobfile
389
390 data = {}
391 execfile(filename, data)
392 if 'conf' not in data:
393 raise ImportError, 'cannot import name conf from %s' % jobfile
124 def __str__(self):
125 return self.name
126
127class Job(Data):
128 def __init__(self, options):
129 super(Job, self).__init__('', '')
130
131 config = options[0]._config

--- 282 unchanged lines hidden (view full) ---

414 else:
415 raise AttributeError, \
416 "Could not find file '%s'" % jobfile
417
418 data = {}
419 execfile(filename, data)
420 if 'conf' not in data:
421 raise ImportError, 'cannot import name conf from %s' % jobfile
394 conf = data['conf']
395 import jobfile
396 if not isinstance(conf, Configuration):
397 raise AttributeError, \
398 'conf in jobfile: %s (%s) is not type %s' % \
399 (jobfile, type(conf), Configuration)
400 return conf
422 return data['conf']
401
402def main(conf=None):
423
424def main(conf=None):
403 import sys
425 usage = 'Usage: %s [-b] [-c] [-v]' % sys.argv[0]
426 if conf is None:
427 usage += ' <jobfile>'
404
428
405 usage = 'Usage: %s [-b] [-c] [-v] <jobfile>' % sys.argv[0]
406
407 try:
408 import getopt
409 opts, args = getopt.getopt(sys.argv[1:], '-bcv')
410 except getopt.GetoptError:
411 sys.exit(usage)
412
413 both = False
414 checkpoint = False

--- 36 unchanged lines hidden ---
429 try:
430 import getopt
431 opts, args = getopt.getopt(sys.argv[1:], '-bcv')
432 except getopt.GetoptError:
433 sys.exit(usage)
434
435 both = False
436 checkpoint = False

--- 36 unchanged lines hidden ---