diff 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
line wrap: on
line diff
--- a/makeitso/script2package.py	Thu Jan 16 14:59:23 2014 -0800
+++ b/makeitso/script2package.py	Thu Jan 16 15:44:31 2014 -0800
@@ -17,6 +17,15 @@
 
 from .python import PythonModuleTemplate, PythonPackageTemplate
 
+### name transformers.... -> ???
+
+def scriptname2packagename(script):
+    return os.path.splitext(os.path.basename(script))[0]
+
+
+
+### CLI parsing
+
 def add_options(parser):
     """add options to the OptionParser instance"""
     # TODO: replace with `configuration` package
@@ -27,6 +36,7 @@
     parser.add_option('-n', '--name', dest='name',
                       help="Name of package; default taken from script name")
     parser.add_option('-o', '--output', dest='output',
+                      default=os.getcwd(),
                       help="where to output the resulting package [DEFAULT: '.']")
 
 def main(args=sys.argv[1:]):
@@ -45,18 +55,36 @@
     options, args = parser.parse_args(args)
     if len(args) != 1:
         parser.error("Please specify a source script")
+    script = args[0]
+
+    # Get package name from script
+    if not options.name:
+        options.name = scriptname2packagename(script)
 
     # require a directory (for now)
-    #    options.force = False # -> add_options
-    if os.path.exists(options.output) and not os.path.isdir(options.output):
-        parser.error("'%s' is a file" % options.output)
+    if os.path.exists(options.output):
+        if not os.path.isdir(options.output):
+            parser.error("'%s' is a file" % options.output)
+        options.output = os.path.join(options.output, options.name)
+        # XXX bad naming
+    else:
+        raise NotImplementedError("TODO")
 
     # configure template
     template = PythonModuleTemplate if options.py_module else PythonPackageTemplate
+    template = template()
 
+    # get some variables:
+    # - author
+    # - description
+    # - email
+    # - repo
+    # - url
+    variables = {}
+    
     # interpolate template
+    template.substitute()
     import pdb; pdb.set_trace()
-    
     # TODO
 
 if __name__ == '__main__':