comparison makeitso/script2package.py @ 176:668b01d04457

STUB: makeitso/makeitso.py makeitso/script2package.py
author Jeff Hammel <k0scist@gmail.com>
date Thu, 16 Jan 2014 15:44:31 -0800
parents 5fa35ff86644
children
comparison
equal deleted inserted replaced
175:5fa35ff86644 176:668b01d04457
15 import subprocess 15 import subprocess
16 import sys 16 import sys
17 17
18 from .python import PythonModuleTemplate, PythonPackageTemplate 18 from .python import PythonModuleTemplate, PythonPackageTemplate
19 19
20 ### name transformers.... -> ???
21
22 def scriptname2packagename(script):
23 return os.path.splitext(os.path.basename(script))[0]
24
25
26
27 ### CLI parsing
28
20 def add_options(parser): 29 def add_options(parser):
21 """add options to the OptionParser instance""" 30 """add options to the OptionParser instance"""
22 # TODO: replace with `configuration` package 31 # TODO: replace with `configuration` package
23 32
24 parser.add_option('-m', '--module', dest='py_module', 33 parser.add_option('-m', '--module', dest='py_module',
25 action='store_true', default=False, 34 action='store_true', default=False,
26 help="create a single-module package with py_modules in setup.py") 35 help="create a single-module package with py_modules in setup.py")
27 parser.add_option('-n', '--name', dest='name', 36 parser.add_option('-n', '--name', dest='name',
28 help="Name of package; default taken from script name") 37 help="Name of package; default taken from script name")
29 parser.add_option('-o', '--output', dest='output', 38 parser.add_option('-o', '--output', dest='output',
39 default=os.getcwd(),
30 help="where to output the resulting package [DEFAULT: '.']") 40 help="where to output the resulting package [DEFAULT: '.']")
31 41
32 def main(args=sys.argv[1:]): 42 def main(args=sys.argv[1:]):
33 43
34 # parse command line options 44 # parse command line options
43 parser = optparse.OptionParser(usage=usage, description=__doc__, formatter=PlainDescriptionFormatter()) 53 parser = optparse.OptionParser(usage=usage, description=__doc__, formatter=PlainDescriptionFormatter())
44 add_options(parser) 54 add_options(parser)
45 options, args = parser.parse_args(args) 55 options, args = parser.parse_args(args)
46 if len(args) != 1: 56 if len(args) != 1:
47 parser.error("Please specify a source script") 57 parser.error("Please specify a source script")
58 script = args[0]
59
60 # Get package name from script
61 if not options.name:
62 options.name = scriptname2packagename(script)
48 63
49 # require a directory (for now) 64 # require a directory (for now)
50 # options.force = False # -> add_options 65 if os.path.exists(options.output):
51 if os.path.exists(options.output) and not os.path.isdir(options.output): 66 if not os.path.isdir(options.output):
52 parser.error("'%s' is a file" % options.output) 67 parser.error("'%s' is a file" % options.output)
68 options.output = os.path.join(options.output, options.name)
69 # XXX bad naming
70 else:
71 raise NotImplementedError("TODO")
53 72
54 # configure template 73 # configure template
55 template = PythonModuleTemplate if options.py_module else PythonPackageTemplate 74 template = PythonModuleTemplate if options.py_module else PythonPackageTemplate
75 template = template()
56 76
77 # get some variables:
78 # - author
79 # - description
80 # - email
81 # - repo
82 # - url
83 variables = {}
84
57 # interpolate template 85 # interpolate template
86 template.substitute()
58 import pdb; pdb.set_trace() 87 import pdb; pdb.set_trace()
59
60 # TODO 88 # TODO
61 89
62 if __name__ == '__main__': 90 if __name__ == '__main__':
63 main() 91 main()