annotate makeitso/python_package/{{package}}/{{main}}.py @ 193:a42d1aaa81c3

what i meant
author Jeff Hammel <k0scist@gmail.com>
date Thu, 08 May 2014 16:55:51 -0700
parents 1bcf60bcc455
children 3cb66c9e5ce8
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
159
Jeff Hammel <jhammel@mozilla.com>
parents: 155
diff changeset
2 # -*- coding: utf-8 -*-
79
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 """
8c326f764cfe add a CLI template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
5 {{description}}
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
187
74f41d53b057 STUB: makeitso/python_package/{{package}}/{{main}}.py
Jeff Hammel <k0scist@gmail.com>
parents: 161
diff changeset
8 # imports
188
1bcf60bcc455 update to argparse
Jeff Hammel <k0scist@gmail.com>
parents: 187
diff changeset
9 import argparse
159
Jeff Hammel <jhammel@mozilla.com>
parents: 155
diff changeset
10 import os
Jeff Hammel <jhammel@mozilla.com>
parents: 155
diff changeset
11 import subprocess
79
8c326f764cfe add a CLI template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
12 import sys
159
Jeff Hammel <jhammel@mozilla.com>
parents: 155
diff changeset
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
1bcf60bcc455 update to argparse
Jeff Hammel <k0scist@gmail.com>
parents: 187
diff changeset
16 string = (str, unicode)
187
74f41d53b057 STUB: makeitso/python_package/{{package}}/{{main}}.py
Jeff Hammel <k0scist@gmail.com>
parents: 161
diff changeset
17
188
1bcf60bcc455 update to argparse
Jeff Hammel <k0scist@gmail.com>
parents: 187
diff changeset
18 class PlainDescriptionFormatter(optparse.IndentedHelpFormatter):
1bcf60bcc455 update to argparse
Jeff Hammel <k0scist@gmail.com>
parents: 187
diff changeset
19 """description formatter for console script entry point"""
1bcf60bcc455 update to argparse
Jeff Hammel <k0scist@gmail.com>
parents: 187
diff changeset
20 def format_description(self, description):
1bcf60bcc455 update to argparse
Jeff Hammel <k0scist@gmail.com>
parents: 187
diff changeset
21 if description:
1bcf60bcc455 update to argparse
Jeff Hammel <k0scist@gmail.com>
parents: 187
diff changeset
22 return description.strip() + '\n'
1bcf60bcc455 update to argparse
Jeff Hammel <k0scist@gmail.com>
parents: 187
diff changeset
23 else:
1bcf60bcc455 update to argparse
Jeff Hammel <k0scist@gmail.com>
parents: 187
diff changeset
24 return ''
1bcf60bcc455 update to argparse
Jeff Hammel <k0scist@gmail.com>
parents: 187
diff changeset
25
1bcf60bcc455 update to argparse
Jeff Hammel <k0scist@gmail.com>
parents: 187
diff changeset
26
1bcf60bcc455 update to argparse
Jeff Hammel <k0scist@gmail.com>
parents: 187
diff changeset
27 class Parser(argparse.ArgumentParser):
1bcf60bcc455 update to argparse
Jeff Hammel <k0scist@gmail.com>
parents: 187
diff changeset
28 """CLI option parser"""
1bcf60bcc455 update to argparse
Jeff Hammel <k0scist@gmail.com>
parents: 187
diff changeset
29 def __init__(self):
1bcf60bcc455 update to argparse
Jeff Hammel <k0scist@gmail.com>
parents: 187
diff changeset
30 argparse.ArgumentParser.__init__(self, description=__doc__)
1bcf60bcc455 update to argparse
Jeff Hammel <k0scist@gmail.com>
parents: 187
diff changeset
31
79
8c326f764cfe add a CLI template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
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
1bcf60bcc455 update to argparse
Jeff Hammel <k0scist@gmail.com>
parents: 187
diff changeset
34 """CLI"""
130
d9201f911458 better description formatting
Jeff Hammel <jhammel@mozilla.com>
parents: 79
diff changeset
35
139
23652cbfdfad whitespace
Jeff Hammel <jhammel@mozilla.com>
parents: 130
diff changeset
36 # parse command line options
188
1bcf60bcc455 update to argparse
Jeff Hammel <k0scist@gmail.com>
parents: 187
diff changeset
37 parser = Parser()
1bcf60bcc455 update to argparse
Jeff Hammel <k0scist@gmail.com>
parents: 187
diff changeset
38 options = parser.parse_args(args)
79
8c326f764cfe add a CLI template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
39
8c326f764cfe add a CLI template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
40 if __name__ == '__main__':
139
23652cbfdfad whitespace
Jeff Hammel <jhammel@mozilla.com>
parents: 130
diff changeset
41 main()