diff --git a/rhodecode/lib/dbmigrate/migrate/changeset/ansisql.py b/rhodecode/lib/dbmigrate/migrate/changeset/ansisql.py --- a/rhodecode/lib/dbmigrate/migrate/changeset/ansisql.py +++ b/rhodecode/lib/dbmigrate/migrate/changeset/ansisql.py @@ -4,7 +4,7 @@ At the moment, this isn't so much based off of ANSI as much as things that just happen to work with multiple databases. """ -from io import StringIO +import io import sqlalchemy as sa from sqlalchemy.schema import SchemaVisitor @@ -48,7 +48,7 @@ class AlterTableVisitor(SchemaVisitor): def __init__(self, dialect, connection, **kw): self.connection = connection - self.buffer = StringIO.StringIO() + self.buffer = io.StringIO() self.preparer = dialect.identifier_preparer self.dialect = dialect @@ -205,7 +205,7 @@ class ANSISchemaChanger(AlterTableVisito def visit_column(self, delta): """Rename/change a column.""" # ALTER COLUMN is implemented as several ALTER statements - keys = delta.keys() + keys = list(delta.keys()) if 'type' in keys: self._run_subvisit(delta, self._visit_column_type) if 'nullable' in keys: diff --git a/rhodecode/lib/dbmigrate/migrate/changeset/constraint.py b/rhodecode/lib/dbmigrate/migrate/changeset/constraint.py --- a/rhodecode/lib/dbmigrate/migrate/changeset/constraint.py +++ b/rhodecode/lib/dbmigrate/migrate/changeset/constraint.py @@ -128,7 +128,7 @@ class ForeignKeyConstraint(ConstraintCha """Mimic the database's automatic constraint names""" if hasattr(self.columns, 'keys'): # SA <= 0.5 - firstcol = self.columns[self.columns.keys()[0]] + firstcol = self.columns[list(self.columns.keys())[0]] ret = "%(table)s_%(firstcolumn)s_fkey" % { 'table': firstcol.table.name, 'firstcolumn': firstcol.name,} diff --git a/rhodecode/lib/dbmigrate/migrate/changeset/databases/oracle.py b/rhodecode/lib/dbmigrate/migrate/changeset/databases/oracle.py --- a/rhodecode/lib/dbmigrate/migrate/changeset/databases/oracle.py +++ b/rhodecode/lib/dbmigrate/migrate/changeset/databases/oracle.py @@ -34,7 +34,7 @@ class OracleSchemaChanger(OracleSchemaGe return ret def visit_column(self, delta): - keys = delta.keys() + keys = list(delta.keys()) if 'name' in keys: self._run_subvisit(delta, @@ -51,15 +51,15 @@ class OracleSchemaChanger(OracleSchemaGe # to null. We'll do that if default=None # http://forums.oracle.com/forums/message.jspa?messageID=1273234#1273234 dropdefault_hack = (column.server_default is None \ - and 'server_default' in delta.keys()) + and 'server_default' in list(delta.keys())) # Oracle apparently doesn't like it when we say "not null" if # the column's already not null. Fudge it, so we don't need a # new function notnull_hack = ((not column.nullable) \ - and ('nullable' not in delta.keys())) + and ('nullable' not in list(delta.keys()))) # We need to specify NULL if we're removing a NOT NULL # constraint - null_hack = (column.nullable and ('nullable' in delta.keys())) + null_hack = (column.nullable and ('nullable' in list(delta.keys()))) if dropdefault_hack: column.server_default = sa.PassiveDefault(sa.sql.null()) diff --git a/rhodecode/lib/dbmigrate/migrate/changeset/schema.py b/rhodecode/lib/dbmigrate/migrate/changeset/schema.py --- a/rhodecode/lib/dbmigrate/migrate/changeset/schema.py +++ b/rhodecode/lib/dbmigrate/migrate/changeset/schema.py @@ -245,12 +245,12 @@ class ColumnDelta(DictMixin, sqlalchemy. ) def __getitem__(self, key): - if key not in self.keys(): + if key not in list(self.keys()): raise KeyError("No such diff key, available: %s" % self.diffs ) return getattr(self.result_column, key) def __setitem__(self, key, value): - if key not in self.keys(): + if key not in list(self.keys()): raise KeyError("No such diff key, available: %s" % self.diffs ) setattr(self.result_column, key, value) @@ -264,7 +264,7 @@ class ColumnDelta(DictMixin, sqlalchemy. raise NotImplementedError def keys(self): - return self.diffs.keys() + return list(self.diffs.keys()) def compare_parameters(self, current_name, *p, **k): """Compares Column objects with reflection""" diff --git a/rhodecode/lib/dbmigrate/migrate/versioning/api.py b/rhodecode/lib/dbmigrate/migrate/versioning/api.py --- a/rhodecode/lib/dbmigrate/migrate/versioning/api.py +++ b/rhodecode/lib/dbmigrate/migrate/versioning/api.py @@ -58,7 +58,7 @@ command_desc = { 'make_update_script_for_model': 'create a script changing the old MetaData to the new (current) MetaData', 'update_db_from_model': 'modify the database to match the structure of the current MetaData', } -__all__ = command_desc.keys() +__all__ = list(command_desc.keys()) Repository = repository.Repository ControlledSchema = schema.ControlledSchema diff --git a/rhodecode/lib/dbmigrate/migrate/versioning/genmodel.py b/rhodecode/lib/dbmigrate/migrate/versioning/genmodel.py --- a/rhodecode/lib/dbmigrate/migrate/versioning/genmodel.py +++ b/rhodecode/lib/dbmigrate/migrate/versioning/genmodel.py @@ -192,7 +192,7 @@ class ModelGenerator(object): downgradeCommands.append( "post_meta.tables[%(table)r].drop()" % {'table': tn}) - for (tn, td) in self.diff.tables_different.items(): + for (tn, td) in list(self.diff.tables_different.items()): if td.columns_missing_from_A or td.columns_different: pre_table = self.diff.metadataB.tables[tn] decls.extend(self._getTableDefn( diff --git a/rhodecode/lib/dbmigrate/migrate/versioning/migrate_repository.py b/rhodecode/lib/dbmigrate/migrate/versioning/migrate_repository.py --- a/rhodecode/lib/dbmigrate/migrate/versioning/migrate_repository.py +++ b/rhodecode/lib/dbmigrate/migrate/versioning/migrate_repository.py @@ -13,12 +13,12 @@ log = logging.getLogger(__name__) def usage(): """Gives usage information.""" - print("""Usage: %(prog)s repository-to-migrate + print(("""Usage: %(prog)s repository-to-migrate Upgrade your repository to the new flat format. NOTE: You should probably make a backup before running this. - """ % {'prog': sys.argv[0]}) + """ % {'prog': sys.argv[0]})) sys.exit(1) diff --git a/rhodecode/lib/dbmigrate/migrate/versioning/repository.py b/rhodecode/lib/dbmigrate/migrate/versioning/repository.py --- a/rhodecode/lib/dbmigrate/migrate/versioning/repository.py +++ b/rhodecode/lib/dbmigrate/migrate/versioning/repository.py @@ -37,22 +37,22 @@ class Changeset(dict): self.add(change) def __iter__(self): - return iter(self.items()) + return iter(list(self.items())) def keys(self): """ In a series of upgrades x -> y, keys are version x. Sorted. """ - ret = super(Changeset, self).keys() + ret = list(super(Changeset, self).keys()) # Reverse order if downgrading ret.sort(reverse=(self.step < 1)) return ret def values(self): - return [self[k] for k in self.keys()] + return [self[k] for k in list(self.keys())] def items(self): - return zip(self.keys(), self.values()) + return list(zip(list(self.keys()), list(self.values()))) def add(self, change): """Add new change to changeset""" @@ -221,7 +221,7 @@ class Repository(pathed.Pathed): range_mod = 0 op = 'downgrade' - versions = range(int(start) + range_mod, int(end) + range_mod, step) + versions = list(range(int(start) + range_mod, int(end) + range_mod, step)) changes = [self.version(v).script(database, op) for v in versions] ret = Changeset(start, step=step, *changes) return ret diff --git a/rhodecode/lib/dbmigrate/migrate/versioning/schema.py b/rhodecode/lib/dbmigrate/migrate/versioning/schema.py --- a/rhodecode/lib/dbmigrate/migrate/versioning/schema.py +++ b/rhodecode/lib/dbmigrate/migrate/versioning/schema.py @@ -50,7 +50,7 @@ class ControlledSchema(object): data = list(result)[0] except: cls, exc, tb = sys.exc_info() - raise exceptions.DatabaseNotControlledError, exc.__str__(), tb + raise exceptions.DatabaseNotControlledError(exc.__str__()).with_traceback(tb) self.version = data['version'] return data diff --git a/rhodecode/lib/dbmigrate/migrate/versioning/schemadiff.py b/rhodecode/lib/dbmigrate/migrate/versioning/schemadiff.py --- a/rhodecode/lib/dbmigrate/migrate/versioning/schemadiff.py +++ b/rhodecode/lib/dbmigrate/migrate/versioning/schemadiff.py @@ -97,7 +97,7 @@ class ColDiff(object): self.diff=True return - def __nonzero__(self): + def __bool__(self): return self.diff __bool__ = __nonzero__ @@ -132,7 +132,7 @@ class TableDiff(object): 'columns_different', ) - def __nonzero__(self): + def __bool__(self): return bool( self.columns_missing_from_A or self.columns_missing_from_B or @@ -277,7 +277,7 @@ class SchemaDiff(object): label,', '.join(sorted(names)) ) ) - for name,cd in td.columns_different.items(): + for name,cd in list(td.columns_different.items()): out.append(' column with differences: %s' % name) out.append(column_template % (self.labelA,cd.col_A)) out.append(column_template % (self.labelB,cd.col_B)) diff --git a/rhodecode/lib/dbmigrate/migrate/versioning/shell.py b/rhodecode/lib/dbmigrate/migrate/versioning/shell.py --- a/rhodecode/lib/dbmigrate/migrate/versioning/shell.py +++ b/rhodecode/lib/dbmigrate/migrate/versioning/shell.py @@ -23,7 +23,7 @@ alias = { def alias_setup(): global alias - for key, val in alias.items(): + for key, val in list(alias.items()): setattr(api, key, val) alias_setup() @@ -135,7 +135,7 @@ def main(argv=None, **kwargs): override_kwargs[opt] = value # override kwargs with options if user is overwriting - for key, value in options.__dict__.items(): + for key, value in list(options.__dict__.items()): if value is not None: override_kwargs[key] = value @@ -143,7 +143,7 @@ def main(argv=None, **kwargs): f_required = list(f_args) candidates = dict(kwargs) candidates.update(override_kwargs) - for key, value in candidates.items(): + for key, value in list(candidates.items()): if key in f_args: f_required.remove(key) @@ -160,7 +160,7 @@ def main(argv=None, **kwargs): kwargs.update(override_kwargs) # configure options - for key, value in options.__dict__.items(): + for key, value in list(options.__dict__.items()): kwargs.setdefault(key, value) # configure logging diff --git a/rhodecode/lib/dbmigrate/migrate/versioning/util/__init__.py b/rhodecode/lib/dbmigrate/migrate/versioning/util/__init__.py --- a/rhodecode/lib/dbmigrate/migrate/versioning/util/__init__.py +++ b/rhodecode/lib/dbmigrate/migrate/versioning/util/__init__.py @@ -131,7 +131,7 @@ def construct_engine(engine, **opts): kwargs['echo'] = echo # parse keyword arguments - for key, value in opts.items(): + for key, value in list(opts.items()): if key.startswith('engine_arg_'): kwargs[key[11:]] = guess_obj_type(value) diff --git a/rhodecode/lib/dbmigrate/migrate/versioning/util/importpath.py b/rhodecode/lib/dbmigrate/migrate/versioning/util/importpath.py --- a/rhodecode/lib/dbmigrate/migrate/versioning/util/importpath.py +++ b/rhodecode/lib/dbmigrate/migrate/versioning/util/importpath.py @@ -1,5 +1,6 @@ import os import sys +import importlib def import_path(fullpath): """ Import a file with full path specification. Allows one to @@ -10,6 +11,6 @@ def import_path(fullpath): filename, ext = os.path.splitext(filename) sys.path.append(path) module = __import__(filename) - reload(module) # Might be out of date during tests + importlib.reload(module) # Might be out of date during tests del sys.path[-1] return module diff --git a/rhodecode/lib/dbmigrate/migrate/versioning/version.py b/rhodecode/lib/dbmigrate/migrate/versioning/version.py --- a/rhodecode/lib/dbmigrate/migrate/versioning/version.py +++ b/rhodecode/lib/dbmigrate/migrate/versioning/version.py @@ -96,13 +96,13 @@ class Collection(pathed.Pathed): # Create the versions member where the keys # are VerNum's and the values are Version's. self.versions = {} - for num, files in tempVersions.items(): + for num, files in list(tempVersions.items()): self.versions[VerNum(num)] = Version(num, path, files) @property def latest(self): """:returns: Latest version in Collection""" - return max([VerNum(0)] + self.versions.keys()) + return max([VerNum(0)] + list(self.versions.keys())) def _next_ver_num(self, use_timestamp_numbering): if use_timestamp_numbering == True: