From: Mike Bayer Date: Sun, 25 Apr 2010 18:51:30 +0000 (-0400) Subject: command line stuff X-Git-Tag: rel_0_1_0~111 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=822a3c9b9f6fa1ca7732a12545c6f887bfb473da;p=thirdparty%2Fsqlalchemy%2Falembic.git command line stuff --- diff --git a/alembic/command.py b/alembic/command.py index 7334dd76..5110db26 100644 --- a/alembic/command.py +++ b/alembic/command.py @@ -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 ') - 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.""" diff --git a/alembic/options.py b/alembic/options.py index 715f3139..2efe4d8b 100644 --- a/alembic/options.py +++ b/alembic/options.py @@ -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 arguments]\n\n" "Available Commands:\n" + "\n".join([ - format_opt(cmd, hlp) + util.format_opt(cmd, hlp) for cmd, hlp in commands ]) )