annotate makeitso/python_package/{{package}}/main.py @ 155:386a44a52139

moving to a thing with script template
author Jeff Hammel <jhammel@mozilla.com>
date Wed, 05 Jun 2013 13:38:23 -0700
parents d37ee77a9317
children cfd4f1e91090
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
79
8c326f764cfe add a CLI template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
1 #!/usr/bin/env python
8c326f764cfe add a CLI template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
2
8c326f764cfe add a CLI template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
3 """
8c326f764cfe add a CLI template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
4 {{description}}
8c326f764cfe add a CLI template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
5 """
8c326f764cfe add a CLI template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
6
8c326f764cfe add a CLI template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
7 import sys
130
d9201f911458 better description formatting
Jeff Hammel <jhammel@mozilla.com>
parents: 79
diff changeset
8 import optparse
79
8c326f764cfe add a CLI template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
9
155
386a44a52139 moving to a thing with script template
Jeff Hammel <jhammel@mozilla.com>
parents: 149
diff changeset
10 def main(args=sys.argv[1:]):
130
d9201f911458 better description formatting
Jeff Hammel <jhammel@mozilla.com>
parents: 79
diff changeset
11
139
23652cbfdfad whitespace
Jeff Hammel <jhammel@mozilla.com>
parents: 130
diff changeset
12 # parse command line options
23652cbfdfad whitespace
Jeff Hammel <jhammel@mozilla.com>
parents: 130
diff changeset
13 usage = '%prog [options]'
23652cbfdfad whitespace
Jeff Hammel <jhammel@mozilla.com>
parents: 130
diff changeset
14 class PlainDescriptionFormatter(optparse.IndentedHelpFormatter):
140
3046e15c3dd7 fix up sectioning
Jeff Hammel <jhammel@mozilla.com>
parents: 139
diff changeset
15 """description formatter for console script entry point"""
139
23652cbfdfad whitespace
Jeff Hammel <jhammel@mozilla.com>
parents: 130
diff changeset
16 def format_description(self, description):
23652cbfdfad whitespace
Jeff Hammel <jhammel@mozilla.com>
parents: 130
diff changeset
17 if description:
149
d37ee77a9317 strip the description
Jeff Hammel <jhammel@mozilla.com>
parents: 140
diff changeset
18 return description.strip() + '\n'
139
23652cbfdfad whitespace
Jeff Hammel <jhammel@mozilla.com>
parents: 130
diff changeset
19 else:
23652cbfdfad whitespace
Jeff Hammel <jhammel@mozilla.com>
parents: 130
diff changeset
20 return ''
23652cbfdfad whitespace
Jeff Hammel <jhammel@mozilla.com>
parents: 130
diff changeset
21 parser = optparse.OptionParser(usage=usage, description=__doc__, formatter=PlainDescriptionFormatter())
23652cbfdfad whitespace
Jeff Hammel <jhammel@mozilla.com>
parents: 130
diff changeset
22 options, args = parser.parse_args(args)
79
8c326f764cfe add a CLI template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
23
8c326f764cfe add a CLI template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
24 if __name__ == '__main__':
139
23652cbfdfad whitespace
Jeff Hammel <jhammel@mozilla.com>
parents: 130
diff changeset
25 main()