diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-11-19 17:42:44 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-11-19 17:42:44 -0500 |
commit | 478f2e6584a809f91e78076038ebba4f5fea5fa9 (patch) | |
tree | 390011802810cf3b5a8601addc9c26cd6c7e050a | |
parent | be7b26633bc811584f0b3c51615aa8d6e663f07b (diff) | |
download | alembic-478f2e6584a809f91e78076038ebba4f5fea5fa9.tar.gz |
- convert arg system to be a little cleaner
- other tweaks
-rw-r--r-- | alembic/command.py | 24 | ||||
-rw-r--r-- | alembic/config.py | 140 | ||||
-rw-r--r-- | alembic/migration.py | 1 |
3 files changed, 95 insertions, 70 deletions
diff --git a/alembic/command.py b/alembic/command.py index 2096d66..8f4a8f7 100644 --- a/alembic/command.py +++ b/alembic/command.py @@ -18,7 +18,7 @@ def list_templates(config): config.print_stdout("%s - %s", tempname, synopsis) config.print_stdout("\nTemplates are used via the 'init' command, e.g.:") - config.print_stdout("\n alembic init --template pylons ./scripts") + config.print_stdout("\n alembic init --template generic ./scripts") def init(config, directory, template='generic'): @@ -84,7 +84,8 @@ def revision( environment = True def retrieve_migrations(rev, context): - if set(script.get_revisions(rev)) != set(script.get_revisions("heads")): + if set(script.get_revisions(rev)) != \ + set(script.get_revisions("heads")): raise util.CommandError("Target database is not up to date.") autogen._produce_migration_diffs(context, template_args, imports) return [] @@ -249,18 +250,21 @@ def heads(config, verbose=False): def branches(config, verbose=False): - """Show current un-spliced branch points""" + """Show current branch points""" script = ScriptDirectory.from_config(config) for sc in script.walk_revisions(): if sc.is_branch_point: - config.print_stdout(sc.cmd_format(verbose, include_branches=True)) - for rev in sc.nextrev: - rev_obj = script.get_revision(rev) - config.print_stdout( - "%s -> %s", - " " * len(str(sc.down_revision)), - rev_obj.cmd_format(False, include_branches=True) + config.print_stdout( + "%s\n%s\n", + sc.cmd_format(verbose, include_branches=True), + "\n".join( + "%s -> %s" % ( + " " * len(str(sc.revision)), + rev_obj.cmd_format(False, include_branches=True) + ) for rev_obj in + (script.get_revision(rev) for rev in sc.nextrev) ) + ) def current(config, verbose=False, head_only=False): diff --git a/alembic/config.py b/alembic/config.py index 19705ed..a388a84 100644 --- a/alembic/config.py +++ b/alembic/config.py @@ -190,80 +190,102 @@ class CommandLine(object): def _generate_args(self, prog): def add_options(parser, positional, kwargs): - if 'template' in kwargs: - parser.add_argument("-t", "--template", - default='generic', - type=str, - help="Setup template for use with 'init'") - if 'message' in kwargs: - parser.add_argument( + kwargs_opts = { + 'template': ( + "-t", "--template", + dict( + default='generic', + type=str, + help="Setup template for use with 'init'" + ) + ), + 'message': ( "-m", "--message", - type=str, - help="Message string to use with 'revision'") - if 'sql' in kwargs: - parser.add_argument( + dict( + type=str, + help="Message string to use with 'revision'") + ), + 'sql': ( "--sql", - action="store_true", - help="Don't emit SQL to database - dump to " - "standard output/file instead") - if 'tag' in kwargs: - parser.add_argument( + dict( + action="store_true", + help="Don't emit SQL to database - dump to " + "standard output/file instead" + ) + ), + 'tag': ( "--tag", - type=str, - help="Arbitrary 'tag' name - can be used by " - "custom env.py scripts.") - if 'head' in kwargs: - parser.add_argument( + dict( + type=str, + help="Arbitrary 'tag' name - can be used by " + "custom env.py scripts.") + ), + 'head': ( "--head", - type=str, - help="Specify head revision or <branchname>@head " - "to base new revision on." - ) - if 'splice' in kwargs: - parser.add_argument( + dict( + type=str, + help="Specify head revision or <branchname>@head " + "to base new revision on." + ) + ), + 'splice': ( "--splice", - action="store_true", - help="Allow a non-head revision as the " - "'head' to splice onto" - ) - if 'branch_label' in kwargs: - parser.add_argument( + dict( + action="store_true", + help="Allow a non-head revision as the " + "'head' to splice onto" + ) + ), + 'branch_label': ( "--branch-label", - type=str, - help="Specify a branch label to apply to the new revision" - ) - if 'verbose' in kwargs: - parser.add_argument( + dict( + type=str, + help="Specify a branch label to apply to the " + "new revision" + ) + ), + 'verbose': ( "-v", "--verbose", - action="store_true", - help="Use more verbose output" - ) - if 'autogenerate' in kwargs: - parser.add_argument( + dict( + action="store_true", + help="Use more verbose output" + ) + ), + 'autogenerate': ( "--autogenerate", - action="store_true", - help="Populate revision script with candidate " - "migration operations, based on comparison " - "of database to model.") - # "current" command - if 'head_only' in kwargs: - parser.add_argument( + dict( + action="store_true", + help="Populate revision script with candidate " + "migration operations, based on comparison " + "of database to model.") + ), + 'head_only': ( "--head-only", - action="store_true", - help="Deprecated. Use --verbose for additional output") - - if 'rev_range' in kwargs: - parser.add_argument("-r", "--rev-range", - action="store", - help="Specify a revision range; " - "format is [start]:[end]") - + dict( + action="store_true", + help="Deprecated. Use --verbose for " + "additional output") + ), + 'rev_range': ( + "-r", "--rev-range", + dict( + action="store", + help="Specify a revision range; " + "format is [start]:[end]") + ) + } positional_help = { 'directory': "location of scripts directory", 'revision': "revision identifier", 'revisions': "one or more revisions, or 'heads' for all heads" } + for arg in kwargs: + if arg in kwargs_opts: + args = kwargs_opts[arg] + args, kw = args[0:-1], args[-1] + parser.add_argument(*args, **kw) + for arg in positional: if arg == "revisions": subparser.add_argument( diff --git a/alembic/migration.py b/alembic/migration.py index ffd5731..7d509af 100644 --- a/alembic/migration.py +++ b/alembic/migration.py @@ -8,7 +8,6 @@ from sqlalchemy.engine import url as sqla_url from .compat import callable, EncodedIO from . import ddl, util -from .revision import tuple_rev_as_scalar log = logging.getLogger(__name__) |