jobfile.py (12563:8d59ed22ae79) jobfile.py (13663:9b64aeabf9a5)
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

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

33class Data(object):
34 def __init__(self, name, desc, **kwargs):
35 self.name = name
36 self.desc = desc
37 self.__dict__.update(kwargs)
38
39 def update(self, obj):
40 if not isinstance(obj, Data):
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

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

33class Data(object):
34 def __init__(self, name, desc, **kwargs):
35 self.name = name
36 self.desc = desc
37 self.__dict__.update(kwargs)
38
39 def update(self, obj):
40 if not isinstance(obj, Data):
41 raise AttributeError, "can only update from Data object"
41 raise AttributeError("can only update from Data object")
42
43 for key,val in obj.__dict__.iteritems():
44 if key.startswith('_') or key in ('name', 'desc'):
45 continue
46
47 if key not in self.__dict__:
48 self.__dict__[key] = val
49 continue
50
51 if not isinstance(val, dict):
52 if self.__dict__[key] == val:
53 continue
54
42
43 for key,val in obj.__dict__.iteritems():
44 if key.startswith('_') or key in ('name', 'desc'):
45 continue
46
47 if key not in self.__dict__:
48 self.__dict__[key] = val
49 continue
50
51 if not isinstance(val, dict):
52 if self.__dict__[key] == val:
53 continue
54
55 raise AttributeError, \
56 "%s specified more than once old: %s new: %s" % \
57 (key, self.__dict__[key], val)
55 raise AttributeError(
56 "%s specified more than once old: %s new: %s" % \
57 (key, self.__dict__[key], val))
58
59 d = self.__dict__[key]
60 for k,v in val.iteritems():
61 if k in d:
58
59 d = self.__dict__[key]
60 for k,v in val.iteritems():
61 if k in d:
62 raise AttributeError, \
63 "%s specified more than once in %s" % (k, key)
62 raise AttributeError(
63 "%s specified more than once in %s" % (k, key))
64 d[k] = v
65
66 if hasattr(self, 'system') and hasattr(obj, 'system'):
67 if self.system != obj.system:
64 d[k] = v
65
66 if hasattr(self, 'system') and hasattr(obj, 'system'):
67 if self.system != obj.system:
68 raise AttributeError, \
69 "conflicting values for system: '%s'/'%s'" % \
70 (self.system, obj.system)
68 raise AttributeError(
69 "conflicting values for system: '%s'/'%s'" % \
70 (self.system, obj.system))
71
72 def printinfo(self):
73 if self.name:
74 print('name: %s' % self.name)
75 if self.desc:
76 print('desc: %s' % self.desc)
77 try:
78 if self.system:

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

91
92 def __contains__(self, attr):
93 if attr.startswith('_'):
94 return False
95 return attr in self.__dict__
96
97 def __getitem__(self, key):
98 if key.startswith('_'):
71
72 def printinfo(self):
73 if self.name:
74 print('name: %s' % self.name)
75 if self.desc:
76 print('desc: %s' % self.desc)
77 try:
78 if self.system:

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

91
92 def __contains__(self, attr):
93 if attr.startswith('_'):
94 return False
95 return attr in self.__dict__
96
97 def __getitem__(self, key):
98 if key.startswith('_'):
99 raise KeyError, "Key '%s' not found" % attr
99 raise KeyError("Key '%s' not found" % attr)
100 return self.__dict__[key]
101
102 def __iter__(self):
103 keys = self.__dict__.keys()
104 keys.sort()
105 for key in keys:
106 if not key.startswith('_'):
107 yield key

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

126
127class Job(Data):
128 def __init__(self, options):
129 super(Job, self).__init__('', '')
130
131 config = options[0]._config
132 for opt in options:
133 if opt._config != config:
100 return self.__dict__[key]
101
102 def __iter__(self):
103 keys = self.__dict__.keys()
104 keys.sort()
105 for key in keys:
106 if not key.startswith('_'):
107 yield key

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

126
127class Job(Data):
128 def __init__(self, options):
129 super(Job, self).__init__('', '')
130
131 config = options[0]._config
132 for opt in options:
133 if opt._config != config:
134 raise AttributeError, \
135 "All options are not from the same Configuration"
134 raise AttributeError(
135 "All options are not from the same Configuration")
136
137 self._config = config
138 self._groups = [ opt._group for opt in options ]
139 self._options = options
140
141 self.update(self._config)
142 for group in self._groups:
143 self.update(group)

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

304 return grp
305
306 def groups(self):
307 return self._groups
308
309 def checkchildren(self, kids):
310 for kid in kids:
311 if kid._config != self:
136
137 self._config = config
138 self._groups = [ opt._group for opt in options ]
139 self._options = options
140
141 self.update(self._config)
142 for group in self._groups:
143 self.update(group)

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

304 return grp
305
306 def groups(self):
307 return self._groups
308
309 def checkchildren(self, kids):
310 for kid in kids:
311 if kid._config != self:
312 raise AttributeError, "child from the wrong configuration"
312 raise AttributeError("child from the wrong configuration")
313
314 def sortgroups(self, groups):
315 groups = [ (grp._number, grp) for grp in groups ]
316 groups.sort()
317 return [ grp[1] for grp in groups ]
318
319 def options(self, groups=None, checkpoint=False):
320 if groups is None:

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

382 for options in self.options(groups, False):
383 yield Job(options)
384
385 def find(self, jobname):
386 for job in self.alljobs():
387 if job.name == jobname:
388 return job
389 else:
313
314 def sortgroups(self, groups):
315 groups = [ (grp._number, grp) for grp in groups ]
316 groups.sort()
317 return [ grp[1] for grp in groups ]
318
319 def options(self, groups=None, checkpoint=False):
320 if groups is None:

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

382 for options in self.options(groups, False):
383 yield Job(options)
384
385 def find(self, jobname):
386 for job in self.alljobs():
387 if job.name == jobname:
388 return job
389 else:
390 raise AttributeError, "job '%s' not found" % jobname
390 raise AttributeError("job '%s' not found" % jobname)
391
392 def job(self, options):
393 self.checkchildren(options)
394 options = [ (opt._group._number, opt) for opt in options ]
395 options.sort()
396 options = [ opt[1] for opt in options ]
397 job = Job(options)
398 return job

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

409 # Can't find filename in the current path, search sys.path
410 if not isfile(filename):
411 for path in sys.path:
412 testname = joinpath(path, filename)
413 if isfile(testname):
414 filename = testname
415 break
416 else:
391
392 def job(self, options):
393 self.checkchildren(options)
394 options = [ (opt._group._number, opt) for opt in options ]
395 options.sort()
396 options = [ opt[1] for opt in options ]
397 job = Job(options)
398 return job

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

409 # Can't find filename in the current path, search sys.path
410 if not isfile(filename):
411 for path in sys.path:
412 testname = joinpath(path, filename)
413 if isfile(testname):
414 filename = testname
415 break
416 else:
417 raise AttributeError, \
418 "Could not find file '%s'" % jobfile
417 raise AttributeError("Could not find file '%s'" % jobfile)
419
420 data = {}
421 execfile(filename, data)
422 if 'conf' not in data:
418
419 data = {}
420 execfile(filename, data)
421 if 'conf' not in data:
423 raise ImportError, 'cannot import name conf from %s' % jobfile
422 raise ImportError('cannot import name conf from %s' % jobfile)
424 return data['conf']
425
426def main(conf=None):
427 usage = 'Usage: %s [-b] [-c] [-v]' % sys.argv[0]
428 if conf is None:
429 usage += ' <jobfile>'
430
431 try:

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

443 checkpoint = True
444 if opt == '-c':
445 checkpoint = True
446 if opt == '-v':
447 verbose = True
448
449 if conf is None:
450 if len(args) != 1:
423 return data['conf']
424
425def main(conf=None):
426 usage = 'Usage: %s [-b] [-c] [-v]' % sys.argv[0]
427 if conf is None:
428 usage += ' <jobfile>'
429
430 try:

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

442 checkpoint = True
443 if opt == '-c':
444 checkpoint = True
445 if opt == '-v':
446 verbose = True
447
448 if conf is None:
449 if len(args) != 1:
451 raise AttributeError, usage
450 raise AttributeError(usage)
452 conf = JobFile(args[0])
453 else:
454 if len(args) != 0:
451 conf = JobFile(args[0])
452 else:
453 if len(args) != 0:
455 raise AttributeError, usage
454 raise AttributeError(usage)
456
457 if both:
458 jobs = conf.alljobs()
459 elif checkpoint:
460 jobs = conf.checkpoints()
461 else:
462 jobs = conf.jobs()
463
464 for job in jobs:
465 if verbose:
466 job.printinfo()
467 else:
468 cpt = ''
469 if job._checkpoint:
470 cpt = job._checkpoint.name
471 print(job.name, cpt)
472
473if __name__ == '__main__':
474 main()
455
456 if both:
457 jobs = conf.alljobs()
458 elif checkpoint:
459 jobs = conf.checkpoints()
460 else:
461 jobs = conf.jobs()
462
463 for job in jobs:
464 if verbose:
465 job.printinfo()
466 else:
467 cpt = ''
468 if job._checkpoint:
469 cpt = job._checkpoint.name
470 print(job.name, cpt)
471
472if __name__ == '__main__':
473 main()