Last change
on this file since 187a8f9 was
2e46f35,
checked in by mikeryan <mikeryan@…>, 14 years ago
|
switch to /usr/bin/env python to run python
|
-
Property mode set to
100644
|
File size:
1.1 KB
|
Rev | Line | |
---|
[2e46f35] | 1 | #!/usr/bin/env python |
---|
[b4778de] | 2 | |
---|
| 3 | import sys |
---|
| 4 | import pickle |
---|
| 5 | from optparse import OptionParser |
---|
| 6 | |
---|
| 7 | from string import join |
---|
| 8 | |
---|
| 9 | class Parser(OptionParser): |
---|
| 10 | def __init__(self): |
---|
| 11 | OptionParser.__init__(self, |
---|
| 12 | usage='%prog [options] state_file [allocid]') |
---|
| 13 | self.add_option('--field', dest='field', default='manifest', |
---|
| 14 | help='field to extract: deafult %default') |
---|
| 15 | |
---|
| 16 | |
---|
| 17 | parser = Parser() |
---|
| 18 | opts, args = parser.parse_args() |
---|
| 19 | |
---|
| 20 | if len(args) == 1: |
---|
| 21 | fn = args[0] |
---|
| 22 | a = None |
---|
| 23 | elif len(args) == 2: |
---|
| 24 | fn, a = args |
---|
| 25 | else: |
---|
| 26 | parser.print_help() |
---|
| 27 | sys.exit(1) |
---|
| 28 | |
---|
| 29 | try: |
---|
| 30 | f = open(fn, 'r') |
---|
| 31 | d = pickle.load(f) |
---|
| 32 | f.close() |
---|
| 33 | except EnvironmentError, e: |
---|
| 34 | sys.exit("Can't read %s: %s" % (e.filename or '!?', e.strerror)) |
---|
| 35 | except pickle.PickleError, e: |
---|
| 36 | f.close() |
---|
| 37 | sys.exit("Unpickling error: %s" %e) |
---|
| 38 | |
---|
| 39 | if 'allocation' in d: |
---|
| 40 | alloc = d['allocation'] |
---|
| 41 | |
---|
| 42 | if a: |
---|
| 43 | if a in alloc: |
---|
| 44 | if opts.field in alloc[a]: |
---|
| 45 | print alloc[a][opts.field] |
---|
| 46 | else: |
---|
| 47 | sys.exit('No %s in %s' % (opts.field, a)) |
---|
| 48 | else: |
---|
| 49 | sys.exit('Allocation %s not in state' % a) |
---|
| 50 | else: |
---|
| 51 | for k in alloc.keys(): |
---|
| 52 | if opts.field in alloc[k]: |
---|
| 53 | print k |
---|
| 54 | else: |
---|
| 55 | sys.exit('No allocation in state') |
---|
Note: See
TracBrowser
for help on using the repository browser.