]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
command line stuff
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 25 Apr 2010 18:51:30 +0000 (14:51 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 25 Apr 2010 18:51:30 +0000 (14:51 -0400)
alembic/command.py
alembic/options.py

index 7334dd76abdbb7f323a31b3acf4243ac340fa9fe..5110db26e2ba840620567d51f560b1350dcbd7db 100644 (file)
@@ -1,18 +1,9 @@
 from alembic.script import ScriptDirectory
-from alembic import options
+from alembic import options, util
 import os
 import sys
+import shutil
 
-def _status(msg, fn, *arg, **kw):
-    sys.stdout.write("  " + msg + "...")
-    try:
-        ret = fn(*arg, **kw)
-        sys.stdout.write("done\n")
-        return ret
-    except:
-        sys.stdout.write("FAILED\n")
-        raise
-    
 def list_templates(opts):
     """List available templates"""
     
@@ -32,13 +23,32 @@ def init(opts):
     """Initialize a new scripts directory."""
     
     dir_, = opts.get_command_args(1, 'alembic init <directory>')
-    if not _status("Checking for directory %s" % dir_, 
-                        os.access, dir_, os.F_OK):
-        _status("Creating directory %s" % dir_,
-                    os.makedirs, dir_)
-    else:
+    if os.access(dir_, os.F_OK):
         opts.err("Directory %s already exists" % dir_)
-    # copy files...
+
+    util.status("Creating directory %s" % os.path.abspath(dir_),
+                os.makedirs, dir_)
+    template_dir = os.path.join(opts.get_template_directory(),
+                                    opts.cmd_line_options.template)
+    if not os.access(template_dir, os.F_OK):
+        opts.err("No such template %r" % opts.cmd_line_options.template)
+    for file_ in os.listdir(template_dir):
+        if file_ == 'alembic.ini.mako':
+            config_file = os.path.abspath(opts.cmd_line_options.config)
+            util.status("Generating %s" % config_file,
+                util.template_to_file,
+                os.path.join(template_dir, file_),
+                config_file,
+                script_location=dir_
+            )
+        else:
+            output_file = os.path.join(dir_, file_)
+            util.status("Generating %s" % os.path.abspath(output_file), 
+                        shutil.copy, 
+                        os.path.join(template_dir, file_), output_file)
+
+    util.msg("\nPlease edit configuration/connection/logging "\
+            "settings in %r before proceeding." % config_file)
     
 def upgrade(opts):
     """Upgrade to the latest version."""
index 715f31391ebe11f652dc580a42dc8886a5da3d39..2efe4d8b50777cf098d298507cbeee043c07a25a 100644 (file)
@@ -3,10 +3,7 @@ import ConfigParser
 import inspect
 import os
 import sys
-
-def format_opt(opt, hlp, padding=22):
-    return "  " + opt + \
-        ((padding - len(opt)) * " ") + hlp
+from alembic import util
     
 def get_option_parser():
     from alembic import command
@@ -28,7 +25,7 @@ def get_option_parser():
                 "usage: %prog [options] <command> [command arguments]\n\n"
                 "Available Commands:\n" +
                 "\n".join([
-                    format_opt(cmd, hlp)
+                    util.format_opt(cmd, hlp)
                     for cmd, hlp in commands
                 ])
                 )