some more PEP8 love
This commit is contained in:
parent
4b50def6ea
commit
672d9bd576
@ -99,7 +99,8 @@ class ANSIColumnGenerator(AlterTableVisitor, SchemaGenerator):
|
||||
unique=bool(column.index_name or column.index))
|
||||
ix.create()
|
||||
elif column.unique_name:
|
||||
constraint.UniqueConstraint(column, name=column.unique_name).create()
|
||||
constraint.UniqueConstraint(column,
|
||||
name=column.unique_name).create()
|
||||
|
||||
# SA bounds FK constraints to table, add manually
|
||||
for fk in column.foreign_keys:
|
||||
@ -107,7 +108,8 @@ class ANSIColumnGenerator(AlterTableVisitor, SchemaGenerator):
|
||||
|
||||
# add primary key constraint if needed
|
||||
if column.primary_key_name:
|
||||
cons = constraint.PrimaryKeyConstraint(column, name=column.primary_key_name)
|
||||
cons = constraint.PrimaryKeyConstraint(column,
|
||||
name=column.primary_key_name)
|
||||
cons.create()
|
||||
|
||||
|
||||
@ -145,14 +147,17 @@ class ANSISchemaChanger(AlterTableVisitor, SchemaGenerator):
|
||||
def visit_table(self, table):
|
||||
"""Rename a table. Other ops aren't supported."""
|
||||
self.start_alter_table(table)
|
||||
self.append("RENAME TO %s" % self.preparer.quote(table.new_name, table.quote))
|
||||
self.append("RENAME TO %s" % self.preparer.quote(table.new_name,
|
||||
table.quote))
|
||||
self.execute()
|
||||
|
||||
def visit_index(self, index):
|
||||
"""Rename an index"""
|
||||
self.append("ALTER INDEX %s RENAME TO %s" %
|
||||
(self.preparer.quote(self._validate_identifier(index.name, True), index.quote),
|
||||
self.preparer.quote(self._validate_identifier(index.new_name, True) , index.quote)))
|
||||
(self.preparer.quote(self._validate_identifier(index.name,
|
||||
True), index.quote),
|
||||
self.preparer.quote(self._validate_identifier(index.new_name,
|
||||
True), index.quote)))
|
||||
self.execute()
|
||||
|
||||
def visit_column(self, column):
|
||||
|
@ -2,7 +2,7 @@
|
||||
This module contains database dialect specific changeset
|
||||
implementations.
|
||||
"""
|
||||
__all__=[
|
||||
__all__ = [
|
||||
'postgres',
|
||||
'sqlite',
|
||||
'mysql',
|
||||
|
@ -42,16 +42,14 @@ class OracleSchemaChanger(OracleSchemaGenerator, ansisql.ANSISchemaChanger):
|
||||
|
||||
def _visit_column_change(self, table, col_name, delta):
|
||||
if not hasattr(delta, 'result_column'):
|
||||
# Oracle needs the whole column definition, not just a
|
||||
# lone name/type
|
||||
# Oracle needs the whole column definition, not just a lone name/type
|
||||
raise exceptions.NotSupportedError(
|
||||
"A column object is required to do this")
|
||||
|
||||
column = delta.result_column
|
||||
# Oracle cannot drop a default once created, but it can set it
|
||||
# to null. We'll do that if default=None
|
||||
# http://forums.oracle.com/forums/message.jspa?\
|
||||
# messageID=1273234#1273234
|
||||
# http://forums.oracle.com/forums/message.jspa?messageID=1273234#1273234
|
||||
dropdefault_hack = (column.server_default is None \
|
||||
and 'server_default' in delta.keys())
|
||||
# Oracle apparently doesn't like it when we say "not null" if
|
||||
|
@ -8,7 +8,7 @@ from migrate.changeset.databases import sqlite, postgres, mysql, oracle
|
||||
|
||||
|
||||
# Map SA dialects to the corresponding Migrate extensions
|
||||
dialects = {
|
||||
DIALECTS = {
|
||||
sa.engine.default.DefaultDialect: ansisql.ANSIDialect,
|
||||
sa.databases.sqlite.SQLiteDialect: sqlite.SQLiteDialect,
|
||||
sa.databases.postgres.PGDialect: postgres.PGDialect,
|
||||
@ -43,7 +43,7 @@ def get_dialect_visitor(sa_dialect, name):
|
||||
|
||||
# map sa dialect to migrate dialect and return visitor
|
||||
sa_dialect_cls = sa_dialect.__class__
|
||||
migrate_dialect_cls = dialects[sa_dialect_cls]
|
||||
migrate_dialect_cls = DIALECTS[sa_dialect_cls]
|
||||
visitor = getattr(migrate_dialect_cls, name)
|
||||
|
||||
# bind preparer
|
||||
|
@ -2,11 +2,13 @@
|
||||
This module provides an external API to the versioning system.
|
||||
|
||||
.. versionchanged:: 0.4.5
|
||||
``--preview_sql`` displays source file when using SQL scripts. If Python script is used,
|
||||
it runs the action with mocked engine and returns captured SQL statements.
|
||||
``--preview_sql`` displays source file when using SQL scripts.
|
||||
If Python script is used, it runs the action with mocked engine and
|
||||
returns captured SQL statements.
|
||||
|
||||
.. versionchanged:: 0.4.5
|
||||
Deprecated ``--echo`` parameter in favour of new :func:`migrate.versioning.util.construct_engine` behavior.
|
||||
Deprecated ``--echo`` parameter in favour of new
|
||||
:func:`migrate.versioning.util.construct_engine` behavior.
|
||||
"""
|
||||
|
||||
# Dear migrate developers,
|
||||
|
@ -1,5 +1,5 @@
|
||||
"""Things that should be imported by all migrate packages"""
|
||||
|
||||
#__all__ = ['logging','log','databases','operations']
|
||||
from logger import logging,log
|
||||
from const import databases,operations
|
||||
from logger import logging, log
|
||||
from const import databases, operations
|
||||
|
@ -1,10 +1,11 @@
|
||||
__all__ = ['databases','operations']
|
||||
from sqlalchemy.util import OrderedDict
|
||||
|
||||
#databases = ('sqlite','postgres','mysql','oracle','mssql','firebird')
|
||||
databases = ('sqlite','postgres','mysql','oracle','mssql')
|
||||
|
||||
__all__ = ['databases', 'operations']
|
||||
|
||||
databases = ('sqlite', 'postgres', 'mysql', 'oracle', 'mssql')
|
||||
|
||||
# Map operation names to function names
|
||||
from sqlalchemy.util import OrderedDict
|
||||
operations = OrderedDict()
|
||||
operations['upgrade'] = 'upgrade'
|
||||
operations['downgrade'] = 'downgrade'
|
||||
|
@ -6,4 +6,4 @@ log=logging.getLogger('migrate.versioning')
|
||||
log.setLevel(logging.WARNING)
|
||||
log.addHandler(logging.StreamHandler())
|
||||
|
||||
__all__=['log','logging']
|
||||
__all__ = ['log','logging']
|
||||
|
@ -52,7 +52,7 @@ class Pathed(KeyedInstance):
|
||||
#
|
||||
# Treat directories like files...
|
||||
if path[-1] == '/':
|
||||
path=path[:-1]
|
||||
path = path[:-1]
|
||||
ret = os.path.dirname(path)
|
||||
return ret
|
||||
|
||||
|
@ -62,7 +62,9 @@ class ControlledSchema(object):
|
||||
def changeset(self, version=None):
|
||||
"""API to Changeset creation.
|
||||
|
||||
Uses self.version for start version and engine.name to get database name."""
|
||||
Uses self.version for start version and engine.name
|
||||
to get database name.
|
||||
"""
|
||||
database = self.engine.name
|
||||
start_ver = self.version
|
||||
changeset = self.repository.changeset(database, start_ver, version)
|
||||
|
@ -112,7 +112,7 @@ class PythonScript(base.BaseScript):
|
||||
"""
|
||||
buf = StringIO()
|
||||
args['engine_arg_strategy'] = 'mock'
|
||||
args['engine_arg_executor'] = lambda s, p='': buf.write(s + p)
|
||||
args['engine_arg_executor'] = lambda s, p = '': buf.write(s + p)
|
||||
engine = construct_engine(url, **args)
|
||||
|
||||
self.run(engine, step)
|
||||
|
@ -17,8 +17,8 @@ alias = dict(
|
||||
|
||||
def alias_setup():
|
||||
global alias
|
||||
for key,val in alias.iteritems():
|
||||
setattr(api,key,val)
|
||||
for key, val in alias.iteritems():
|
||||
setattr(api, key, val)
|
||||
alias_setup()
|
||||
|
||||
|
||||
@ -33,7 +33,8 @@ class PassiveOptionParser(OptionParser):
|
||||
del rargs[0]
|
||||
return
|
||||
elif arg[0:2] == "--":
|
||||
# if parser does not know about the option, pass it along (make it anonymous)
|
||||
# if parser does not know about the option
|
||||
# pass it along (make it anonymous)
|
||||
try:
|
||||
opt = arg.split('=', 1)[0]
|
||||
self._match_long_opt(opt)
|
||||
@ -49,13 +50,15 @@ class PassiveOptionParser(OptionParser):
|
||||
del rargs[0]
|
||||
|
||||
def main(argv=None, **kwargs):
|
||||
"""kwargs are default options that can be overriden with passing --some_option to cmdline"""
|
||||
"""kwargs are default options that can be overriden with passing
|
||||
--some_option to cmdline
|
||||
"""
|
||||
|
||||
argv = argv or list(sys.argv[1:])
|
||||
commands = list(api.__all__)
|
||||
commands.sort()
|
||||
|
||||
usage="""%%prog COMMAND ...
|
||||
usage = """%%prog COMMAND ...
|
||||
|
||||
Available commands:
|
||||
%s
|
||||
@ -129,7 +132,8 @@ def main(argv=None, **kwargs):
|
||||
try:
|
||||
kw = f_required.pop(0)
|
||||
except IndexError:
|
||||
parser.error("Too many arguments for command %s: %s" % (command, arg))
|
||||
parser.error("Too many arguments for command %s: %s" % (command,
|
||||
arg))
|
||||
kwargs[kw] = arg
|
||||
|
||||
# apply overrides
|
||||
@ -143,7 +147,8 @@ def main(argv=None, **kwargs):
|
||||
f_args_default = f_args[len(f_args) - num_defaults:]
|
||||
required = list(set(f_required) - set(f_args_default))
|
||||
if required:
|
||||
parser.error("Not enough arguments for command %s: %s not specified" % (command, ', '.join(required)))
|
||||
parser.error("Not enough arguments for command %s: %s not specified" \
|
||||
% (command, ', '.join(required)))
|
||||
|
||||
# handle command
|
||||
try:
|
||||
|
@ -24,6 +24,7 @@ class Packaged(pathed.Pathed):
|
||||
ret = resource_filename(pkg_name, resource_name)
|
||||
return ret
|
||||
|
||||
|
||||
class Collection(Packaged):
|
||||
"""A collection of templates of a specific type"""
|
||||
|
||||
@ -35,12 +36,15 @@ class Collection(Packaged):
|
||||
def get_pkg(self, file):
|
||||
return (self.pkg, str(file))
|
||||
|
||||
|
||||
class RepositoryCollection(Collection):
|
||||
_default = 'default'
|
||||
|
||||
|
||||
class ScriptCollection(Collection):
|
||||
_default = 'default.py_tmpl'
|
||||
|
||||
|
||||
class Template(Packaged):
|
||||
"""Finds the paths/packages of various Migrate templates"""
|
||||
|
||||
@ -50,8 +54,9 @@ class Template(Packaged):
|
||||
|
||||
def __init__(self, pkg):
|
||||
super(Template, self).__init__(pkg)
|
||||
self.repository=RepositoryCollection('.'.join((self.pkg, self._repository)))
|
||||
self.script=ScriptCollection('.'.join((self.pkg, self._script)))
|
||||
self.repository = RepositoryCollection('.'.join((self.pkg,
|
||||
self._repository)))
|
||||
self.script = ScriptCollection('.'.join((self.pkg, self._script)))
|
||||
|
||||
def get_item(self, attr, filename=None, as_pkg=None, as_str=None):
|
||||
item = getattr(self, attr)
|
||||
@ -74,5 +79,6 @@ class Template(Packaged):
|
||||
def manage(self, **k):
|
||||
return (self.pkg, self._manage)
|
||||
|
||||
|
||||
template_pkg = 'migrate.versioning.templates'
|
||||
template = Template(template_pkg)
|
||||
|
@ -161,7 +161,8 @@ class Version(object):
|
||||
# TODO: maybe add force Python parameter?
|
||||
ret = self.python
|
||||
|
||||
assert ret is not None, "There is no script for %d version" % self.version
|
||||
assert ret is not None,
|
||||
"There is no script for %d version" % self.version
|
||||
return ret
|
||||
|
||||
# deprecated?
|
||||
|
Loading…
x
Reference in New Issue
Block a user