# HG changeset patch # User Jeff Hammel # Date 1389907914 28800 # Node ID aed8c4af5f2642525c29cc0bc4245017c0c4cb98 # Parent ceb8c8042e481938586f10de105d029045e4f2a5 STUB: makeitso/cli.py makeitso/script2package.py setup.py diff -r ceb8c8042e48 -r aed8c4af5f26 makeitso/cli.py --- a/makeitso/cli.py Wed Dec 11 04:57:15 2013 -0800 +++ b/makeitso/cli.py Thu Jan 16 13:31:54 2014 -0800 @@ -7,7 +7,7 @@ class MakeItSoCLI(object): """command line interface to a makeitso template""" - + def __init__(self, template_class): self.template_class = template_class @@ -50,11 +50,12 @@ # template variables variables = self.get_variables(options) - + # return the variables and the output return variables, args[0] - + def __call__(self, *args): + """interpolate template""" variables, output = self.parse(list(args)) template = self.template_class(variables=variables) template.substitute({}, output=output) diff -r ceb8c8042e48 -r aed8c4af5f26 makeitso/script2package.py --- a/makeitso/script2package.py Wed Dec 11 04:57:15 2013 -0800 +++ b/makeitso/script2package.py Thu Jan 16 13:31:54 2014 -0800 @@ -15,13 +15,24 @@ import subprocess import sys +from .python import PythonModuleTemplate, PythonPackageTemplate + def add_options(parser): """add options to the OptionParser instance""" + # TODO: replace with `configuration` package + + parser.add_option('-m', '--module', dest='py_module', + action='store_true', default=False, + help="create a single-module package with py_modules in setup.py") + parser.add_option('-n', '--name', dest='name', + help="Name of package; default taken from script name") + parser.add_option('-o', '--output', dest='output', + help="where to output the resulting package [DEFAULT: '.']") def main(args=sys.argv[1:]): # parse command line options - usage = '%prog [options] ...' + usage = '%prog [options] script.py' class PlainDescriptionFormatter(optparse.IndentedHelpFormatter): """description formatter for console script entry point""" def format_description(self, description): @@ -30,8 +41,18 @@ else: return '' parser = optparse.OptionParser(usage=usage, description=__doc__, formatter=PlainDescriptionFormatter()) + add_options(parser) options, args = parser.parse_args(args) + if len(args) != 1: + parser.error("Please specify a source script") + + # configure template + template = PythonModuleTemplate if options.py_module else PythonPackageTemplate + + # interpolate template + + + # TODO if __name__ == '__main__': main() - diff -r ceb8c8042e48 -r aed8c4af5f26 setup.py --- a/setup.py Wed Dec 11 04:57:15 2013 -0800 +++ b/setup.py Thu Jan 16 13:31:54 2014 -0800 @@ -33,6 +33,7 @@ makeitso = makeitso.makeitso:main make-python-package = makeitso.python:main mkpydir = makeitso.mkpydir:main + script2package = makeitso.script2package:main [makeitso.templates] python-package = makeitso.python:PythonPackageTemplate