annotate makeitso/script2package.py @ 175:5fa35ff86644

STUB: makeitso/script2package.py
author Jeff Hammel <k0scist@gmail.com>
date Thu, 16 Jan 2014 14:59:23 -0800
parents aed8c4af5f26
children 668b01d04457
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
164
6cd2894bb11c stub: makeitso/script2package.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
1 #!/usr/bin/env python
6cd2894bb11c stub: makeitso/script2package.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
6cd2894bb11c stub: makeitso/script2package.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
3
6cd2894bb11c stub: makeitso/script2package.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
4 """
6cd2894bb11c stub: makeitso/script2package.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
5 make a package from a .py file
6cd2894bb11c stub: makeitso/script2package.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
6 """
6cd2894bb11c stub: makeitso/script2package.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
7
6cd2894bb11c stub: makeitso/script2package.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
8 ### STUB ###
6cd2894bb11c stub: makeitso/script2package.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
9 # TODO:
6cd2894bb11c stub: makeitso/script2package.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
10 # - thing to make a setup.py from a .py file
6cd2894bb11c stub: makeitso/script2package.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
11 # - use makeitso templates -> directory structure
6cd2894bb11c stub: makeitso/script2package.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
12
6cd2894bb11c stub: makeitso/script2package.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
13 import optparse
6cd2894bb11c stub: makeitso/script2package.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
14 import os
6cd2894bb11c stub: makeitso/script2package.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
15 import subprocess
6cd2894bb11c stub: makeitso/script2package.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
16 import sys
6cd2894bb11c stub: makeitso/script2package.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
17
174
aed8c4af5f26 STUB: makeitso/cli.py makeitso/script2package.py setup.py
Jeff Hammel <k0scist@gmail.com>
parents: 164
diff changeset
18 from .python import PythonModuleTemplate, PythonPackageTemplate
aed8c4af5f26 STUB: makeitso/cli.py makeitso/script2package.py setup.py
Jeff Hammel <k0scist@gmail.com>
parents: 164
diff changeset
19
164
6cd2894bb11c stub: makeitso/script2package.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
20 def add_options(parser):
6cd2894bb11c stub: makeitso/script2package.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
21 """add options to the OptionParser instance"""
174
aed8c4af5f26 STUB: makeitso/cli.py makeitso/script2package.py setup.py
Jeff Hammel <k0scist@gmail.com>
parents: 164
diff changeset
22 # TODO: replace with `configuration` package
aed8c4af5f26 STUB: makeitso/cli.py makeitso/script2package.py setup.py
Jeff Hammel <k0scist@gmail.com>
parents: 164
diff changeset
23
aed8c4af5f26 STUB: makeitso/cli.py makeitso/script2package.py setup.py
Jeff Hammel <k0scist@gmail.com>
parents: 164
diff changeset
24 parser.add_option('-m', '--module', dest='py_module',
aed8c4af5f26 STUB: makeitso/cli.py makeitso/script2package.py setup.py
Jeff Hammel <k0scist@gmail.com>
parents: 164
diff changeset
25 action='store_true', default=False,
aed8c4af5f26 STUB: makeitso/cli.py makeitso/script2package.py setup.py
Jeff Hammel <k0scist@gmail.com>
parents: 164
diff changeset
26 help="create a single-module package with py_modules in setup.py")
aed8c4af5f26 STUB: makeitso/cli.py makeitso/script2package.py setup.py
Jeff Hammel <k0scist@gmail.com>
parents: 164
diff changeset
27 parser.add_option('-n', '--name', dest='name',
aed8c4af5f26 STUB: makeitso/cli.py makeitso/script2package.py setup.py
Jeff Hammel <k0scist@gmail.com>
parents: 164
diff changeset
28 help="Name of package; default taken from script name")
aed8c4af5f26 STUB: makeitso/cli.py makeitso/script2package.py setup.py
Jeff Hammel <k0scist@gmail.com>
parents: 164
diff changeset
29 parser.add_option('-o', '--output', dest='output',
aed8c4af5f26 STUB: makeitso/cli.py makeitso/script2package.py setup.py
Jeff Hammel <k0scist@gmail.com>
parents: 164
diff changeset
30 help="where to output the resulting package [DEFAULT: '.']")
164
6cd2894bb11c stub: makeitso/script2package.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
31
6cd2894bb11c stub: makeitso/script2package.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
32 def main(args=sys.argv[1:]):
6cd2894bb11c stub: makeitso/script2package.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
33
6cd2894bb11c stub: makeitso/script2package.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
34 # parse command line options
174
aed8c4af5f26 STUB: makeitso/cli.py makeitso/script2package.py setup.py
Jeff Hammel <k0scist@gmail.com>
parents: 164
diff changeset
35 usage = '%prog [options] script.py'
164
6cd2894bb11c stub: makeitso/script2package.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
36 class PlainDescriptionFormatter(optparse.IndentedHelpFormatter):
6cd2894bb11c stub: makeitso/script2package.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
37 """description formatter for console script entry point"""
6cd2894bb11c stub: makeitso/script2package.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
38 def format_description(self, description):
6cd2894bb11c stub: makeitso/script2package.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
39 if description:
6cd2894bb11c stub: makeitso/script2package.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
40 return description.strip() + '\n'
6cd2894bb11c stub: makeitso/script2package.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
41 else:
6cd2894bb11c stub: makeitso/script2package.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
42 return ''
6cd2894bb11c stub: makeitso/script2package.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
43 parser = optparse.OptionParser(usage=usage, description=__doc__, formatter=PlainDescriptionFormatter())
174
aed8c4af5f26 STUB: makeitso/cli.py makeitso/script2package.py setup.py
Jeff Hammel <k0scist@gmail.com>
parents: 164
diff changeset
44 add_options(parser)
164
6cd2894bb11c stub: makeitso/script2package.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
45 options, args = parser.parse_args(args)
174
aed8c4af5f26 STUB: makeitso/cli.py makeitso/script2package.py setup.py
Jeff Hammel <k0scist@gmail.com>
parents: 164
diff changeset
46 if len(args) != 1:
aed8c4af5f26 STUB: makeitso/cli.py makeitso/script2package.py setup.py
Jeff Hammel <k0scist@gmail.com>
parents: 164
diff changeset
47 parser.error("Please specify a source script")
aed8c4af5f26 STUB: makeitso/cli.py makeitso/script2package.py setup.py
Jeff Hammel <k0scist@gmail.com>
parents: 164
diff changeset
48
175
5fa35ff86644 STUB: makeitso/script2package.py
Jeff Hammel <k0scist@gmail.com>
parents: 174
diff changeset
49 # require a directory (for now)
5fa35ff86644 STUB: makeitso/script2package.py
Jeff Hammel <k0scist@gmail.com>
parents: 174
diff changeset
50 # options.force = False # -> add_options
5fa35ff86644 STUB: makeitso/script2package.py
Jeff Hammel <k0scist@gmail.com>
parents: 174
diff changeset
51 if os.path.exists(options.output) and not os.path.isdir(options.output):
5fa35ff86644 STUB: makeitso/script2package.py
Jeff Hammel <k0scist@gmail.com>
parents: 174
diff changeset
52 parser.error("'%s' is a file" % options.output)
5fa35ff86644 STUB: makeitso/script2package.py
Jeff Hammel <k0scist@gmail.com>
parents: 174
diff changeset
53
174
aed8c4af5f26 STUB: makeitso/cli.py makeitso/script2package.py setup.py
Jeff Hammel <k0scist@gmail.com>
parents: 164
diff changeset
54 # configure template
aed8c4af5f26 STUB: makeitso/cli.py makeitso/script2package.py setup.py
Jeff Hammel <k0scist@gmail.com>
parents: 164
diff changeset
55 template = PythonModuleTemplate if options.py_module else PythonPackageTemplate
aed8c4af5f26 STUB: makeitso/cli.py makeitso/script2package.py setup.py
Jeff Hammel <k0scist@gmail.com>
parents: 164
diff changeset
56
aed8c4af5f26 STUB: makeitso/cli.py makeitso/script2package.py setup.py
Jeff Hammel <k0scist@gmail.com>
parents: 164
diff changeset
57 # interpolate template
175
5fa35ff86644 STUB: makeitso/script2package.py
Jeff Hammel <k0scist@gmail.com>
parents: 174
diff changeset
58 import pdb; pdb.set_trace()
174
aed8c4af5f26 STUB: makeitso/cli.py makeitso/script2package.py setup.py
Jeff Hammel <k0scist@gmail.com>
parents: 164
diff changeset
59
aed8c4af5f26 STUB: makeitso/cli.py makeitso/script2package.py setup.py
Jeff Hammel <k0scist@gmail.com>
parents: 164
diff changeset
60 # TODO
164
6cd2894bb11c stub: makeitso/script2package.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
61
6cd2894bb11c stub: makeitso/script2package.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
62 if __name__ == '__main__':
6cd2894bb11c stub: makeitso/script2package.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
63 main()