Mercurial > hg > MakeItSo
annotate makeitso/python_package/{{package}}/{{main}}.py @ 188:1bcf60bcc455
update to argparse
| author | Jeff Hammel <k0scist@gmail.com> |
|---|---|
| date | Fri, 11 Apr 2014 18:50:40 -0700 |
| parents | 74f41d53b057 |
| children | 3cb66c9e5ce8 |
| rev | line source |
|---|---|
| 79 | 1 #!/usr/bin/env python |
| 159 | 2 # -*- coding: utf-8 -*- |
| 79 | 3 |
| 4 """ | |
| 5 {{description}} | |
| 6 """ | |
| 7 | |
|
187
74f41d53b057
STUB: makeitso/python_package/{{package}}/{{main}}.py
Jeff Hammel <k0scist@gmail.com>
parents:
161
diff
changeset
|
8 # imports |
| 188 | 9 import argparse |
| 159 | 10 import os |
| 11 import subprocess | |
| 79 | 12 import sys |
| 159 | 13 |
|
187
74f41d53b057
STUB: makeitso/python_package/{{package}}/{{main}}.py
Jeff Hammel <k0scist@gmail.com>
parents:
161
diff
changeset
|
14 __all__ = ['main'] |
|
74f41d53b057
STUB: makeitso/python_package/{{package}}/{{main}}.py
Jeff Hammel <k0scist@gmail.com>
parents:
161
diff
changeset
|
15 here = os.path.dirname(os.path.realpath(__file__)) |
| 188 | 16 string = (str, unicode) |
|
187
74f41d53b057
STUB: makeitso/python_package/{{package}}/{{main}}.py
Jeff Hammel <k0scist@gmail.com>
parents:
161
diff
changeset
|
17 |
| 188 | 18 class PlainDescriptionFormatter(optparse.IndentedHelpFormatter): |
| 19 """description formatter for console script entry point""" | |
| 20 def format_description(self, description): | |
| 21 if description: | |
| 22 return description.strip() + '\n' | |
| 23 else: | |
| 24 return '' | |
| 25 | |
| 26 | |
| 27 class Parser(argparse.ArgumentParser): | |
| 28 """CLI option parser""" | |
| 29 def __init__(self): | |
| 30 argparse.ArgumentParser.__init__(self, description=__doc__) | |
| 31 | |
| 79 | 32 |
|
155
386a44a52139
moving to a thing with script template
Jeff Hammel <jhammel@mozilla.com>
parents:
149
diff
changeset
|
33 def main(args=sys.argv[1:]): |
| 188 | 34 """CLI""" |
|
130
d9201f911458
better description formatting
Jeff Hammel <jhammel@mozilla.com>
parents:
79
diff
changeset
|
35 |
| 139 | 36 # parse command line options |
| 188 | 37 parser = Parser() |
| 38 options = parser.parse_args(args) | |
| 79 | 39 |
| 40 if __name__ == '__main__': | |
| 139 | 41 main() |
