Mercurial > hg > MakeItSo
annotate makeitso/python_module/{{module}}.py @ 159:cfd4f1e91090
wip
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Tue, 30 Jul 2013 15:20:38 -0700 |
parents | ebc5cfe17d95 |
children |
rev | line source |
---|---|
129
57834c2b0937
add a single-file module to the thingy
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
57834c2b0937
add a single-file module to the thingy
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
2 |
57834c2b0937
add a single-file module to the thingy
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
3 """ |
57834c2b0937
add a single-file module to the thingy
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
4 {{module}} |
152
88f5bab340a1
make this slightly less sucky
Jeff Hammel <jhammel@mozilla.com>
parents:
142
diff
changeset
|
5 {{description}} |
129
57834c2b0937
add a single-file module to the thingy
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
6 """ |
57834c2b0937
add a single-file module to the thingy
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
7 |
154
ebc5cfe17d95
order imports and add an add_options() API
Jeff Hammel <jhammel@mozilla.com>
parents:
153
diff
changeset
|
8 import optparse |
129
57834c2b0937
add a single-file module to the thingy
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
9 import sys |
154
ebc5cfe17d95
order imports and add an add_options() API
Jeff Hammel <jhammel@mozilla.com>
parents:
153
diff
changeset
|
10 |
ebc5cfe17d95
order imports and add an add_options() API
Jeff Hammel <jhammel@mozilla.com>
parents:
153
diff
changeset
|
11 def add_options(parser): |
ebc5cfe17d95
order imports and add an add_options() API
Jeff Hammel <jhammel@mozilla.com>
parents:
153
diff
changeset
|
12 """add {{module}} options to an OptionParser instance""" |
ebc5cfe17d95
order imports and add an add_options() API
Jeff Hammel <jhammel@mozilla.com>
parents:
153
diff
changeset
|
13 |
129
57834c2b0937
add a single-file module to the thingy
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
14 |
57834c2b0937
add a single-file module to the thingy
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
15 def main(args=sys.argv[1:]): |
57834c2b0937
add a single-file module to the thingy
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
16 |
57834c2b0937
add a single-file module to the thingy
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
17 # parse command line arguments |
57834c2b0937
add a single-file module to the thingy
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
18 usage = '%prog [options] ...' |
130
d9201f911458
better description formatting
Jeff Hammel <jhammel@mozilla.com>
parents:
129
diff
changeset
|
19 class PlainDescriptionFormatter(optparse.IndentedHelpFormatter): |
142 | 20 """description formatter""" |
130
d9201f911458
better description formatting
Jeff Hammel <jhammel@mozilla.com>
parents:
129
diff
changeset
|
21 def format_description(self, description): |
d9201f911458
better description formatting
Jeff Hammel <jhammel@mozilla.com>
parents:
129
diff
changeset
|
22 if description: |
153 | 23 return description.strip() + '\n' |
130
d9201f911458
better description formatting
Jeff Hammel <jhammel@mozilla.com>
parents:
129
diff
changeset
|
24 else: |
d9201f911458
better description formatting
Jeff Hammel <jhammel@mozilla.com>
parents:
129
diff
changeset
|
25 return '' |
d9201f911458
better description formatting
Jeff Hammel <jhammel@mozilla.com>
parents:
129
diff
changeset
|
26 parser = optparse.OptionParser(usage=usage, description=__doc__, formatter=PlainDescriptionFormatter()) |
154
ebc5cfe17d95
order imports and add an add_options() API
Jeff Hammel <jhammel@mozilla.com>
parents:
153
diff
changeset
|
27 add_options(parser) |
129
57834c2b0937
add a single-file module to the thingy
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
28 options, args = parser.parse_args(args) |
57834c2b0937
add a single-file module to the thingy
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
29 |
57834c2b0937
add a single-file module to the thingy
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
30 if __name__ == '__main__': |
57834c2b0937
add a single-file module to the thingy
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
31 main() |