Mercurial > hg > PaInt
comparison paint/main.py @ 26:8beffeb750b3
begin to add command parser
| author | Jeff Hammel <jhammel@mozilla.com> |
|---|---|
| date | Fri, 30 Mar 2012 10:02:08 -0700 |
| parents | 583f678eb0c9 |
| children | 7e9eb858d086 |
comparison
equal
deleted
inserted
replaced
| 25:c54411c721cb | 26:8beffeb750b3 |
|---|---|
| 2 | 2 |
| 3 """ | 3 """ |
| 4 python PAckage INTrospection | 4 python PAckage INTrospection |
| 5 """ | 5 """ |
| 6 | 6 |
| 7 import commandparser | |
| 8 import package | |
| 7 import sys | 9 import sys |
| 8 import optparse | |
| 9 import tempfile | |
| 10 | |
| 11 class InspectPackages(object): | |
| 12 def __init__(self): | |
| 13 pass | |
| 14 | |
| 15 def dependencies(self, *packages): | |
| 16 if len(packages) > 1: | |
| 17 retval = set() | |
| 18 for package in packages: | |
| 19 retval += self.dependencies(package) | |
| 20 else: | |
| 21 raise NotImplementedError | |
| 22 | |
| 23 def cleanup(self): | |
| 24 pass | |
| 25 __del__ = cleanup | |
| 26 | 10 |
| 27 def main(args=sys.argv[:]): | 11 def main(args=sys.argv[:]): |
| 28 | 12 |
| 29 # parse command line options | 13 parser = commandparser.CommandParser(package.Package) |
| 30 usage = '%prog [options]' | 14 parser.invoke(args) |
| 31 | |
| 32 # description formatter | |
| 33 class PlainDescriptionFormatter(optparse.IndentedHelpFormatter): | |
| 34 def format_description(self, description): | |
| 35 if description: | |
| 36 return description + '\n' | |
| 37 else: | |
| 38 return '' | |
| 39 | |
| 40 parser = optparse.OptionParser(usage=usage, description=__doc__, formatter=PlainDescriptionFormatter()) | |
| 41 options, args = parser.parse_args(args) | |
| 42 | 15 |
| 43 if __name__ == '__main__': | 16 if __name__ == '__main__': |
| 44 main() | 17 main() |
