Mercurial > hg > MakeItSo
comparison makeitso/script2package.py @ 174:aed8c4af5f26
STUB: makeitso/cli.py makeitso/script2package.py setup.py
| author | Jeff Hammel <k0scist@gmail.com> |
|---|---|
| date | Thu, 16 Jan 2014 13:31:54 -0800 |
| parents | 6cd2894bb11c |
| children | 5fa35ff86644 |
comparison
equal
deleted
inserted
replaced
| 173:ceb8c8042e48 | 174:aed8c4af5f26 |
|---|---|
| 13 import optparse | 13 import optparse |
| 14 import os | 14 import os |
| 15 import subprocess | 15 import subprocess |
| 16 import sys | 16 import sys |
| 17 | 17 |
| 18 from .python import PythonModuleTemplate, PythonPackageTemplate | |
| 19 | |
| 18 def add_options(parser): | 20 def add_options(parser): |
| 19 """add options to the OptionParser instance""" | 21 """add options to the OptionParser instance""" |
| 22 # TODO: replace with `configuration` package | |
| 23 | |
| 24 parser.add_option('-m', '--module', dest='py_module', | |
| 25 action='store_true', default=False, | |
| 26 help="create a single-module package with py_modules in setup.py") | |
| 27 parser.add_option('-n', '--name', dest='name', | |
| 28 help="Name of package; default taken from script name") | |
| 29 parser.add_option('-o', '--output', dest='output', | |
| 30 help="where to output the resulting package [DEFAULT: '.']") | |
| 20 | 31 |
| 21 def main(args=sys.argv[1:]): | 32 def main(args=sys.argv[1:]): |
| 22 | 33 |
| 23 # parse command line options | 34 # parse command line options |
| 24 usage = '%prog [options] ...' | 35 usage = '%prog [options] script.py' |
| 25 class PlainDescriptionFormatter(optparse.IndentedHelpFormatter): | 36 class PlainDescriptionFormatter(optparse.IndentedHelpFormatter): |
| 26 """description formatter for console script entry point""" | 37 """description formatter for console script entry point""" |
| 27 def format_description(self, description): | 38 def format_description(self, description): |
| 28 if description: | 39 if description: |
| 29 return description.strip() + '\n' | 40 return description.strip() + '\n' |
| 30 else: | 41 else: |
| 31 return '' | 42 return '' |
| 32 parser = optparse.OptionParser(usage=usage, description=__doc__, formatter=PlainDescriptionFormatter()) | 43 parser = optparse.OptionParser(usage=usage, description=__doc__, formatter=PlainDescriptionFormatter()) |
| 44 add_options(parser) | |
| 33 options, args = parser.parse_args(args) | 45 options, args = parser.parse_args(args) |
| 46 if len(args) != 1: | |
| 47 parser.error("Please specify a source script") | |
| 48 | |
| 49 # configure template | |
| 50 template = PythonModuleTemplate if options.py_module else PythonPackageTemplate | |
| 51 | |
| 52 # interpolate template | |
| 53 | |
| 54 | |
| 55 # TODO | |
| 34 | 56 |
| 35 if __name__ == '__main__': | 57 if __name__ == '__main__': |
| 36 main() | 58 main() |
| 37 |
