##// END OF EJS Templates
dbmigrate: 2to3 pass with fixes
super-admin -
r4988:ff25f201 default
parent child Browse files
Show More
@@ -4,7 +4,7 b''
4 4 At the moment, this isn't so much based off of ANSI as much as
5 5 things that just happen to work with multiple databases.
6 6 """
7 from io import StringIO
7 import io
8 8
9 9 import sqlalchemy as sa
10 10 from sqlalchemy.schema import SchemaVisitor
@@ -48,7 +48,7 b' class AlterTableVisitor(SchemaVisitor):'
48 48
49 49 def __init__(self, dialect, connection, **kw):
50 50 self.connection = connection
51 self.buffer = StringIO.StringIO()
51 self.buffer = io.StringIO()
52 52 self.preparer = dialect.identifier_preparer
53 53 self.dialect = dialect
54 54
@@ -205,7 +205,7 b' class ANSISchemaChanger(AlterTableVisito'
205 205 def visit_column(self, delta):
206 206 """Rename/change a column."""
207 207 # ALTER COLUMN is implemented as several ALTER statements
208 keys = delta.keys()
208 keys = list(delta.keys())
209 209 if 'type' in keys:
210 210 self._run_subvisit(delta, self._visit_column_type)
211 211 if 'nullable' in keys:
@@ -128,7 +128,7 b' class ForeignKeyConstraint(ConstraintCha'
128 128 """Mimic the database's automatic constraint names"""
129 129 if hasattr(self.columns, 'keys'):
130 130 # SA <= 0.5
131 firstcol = self.columns[self.columns.keys()[0]]
131 firstcol = self.columns[list(self.columns.keys())[0]]
132 132 ret = "%(table)s_%(firstcolumn)s_fkey" % {
133 133 'table': firstcol.table.name,
134 134 'firstcolumn': firstcol.name,}
@@ -34,7 +34,7 b' class OracleSchemaChanger(OracleSchemaGe'
34 34 return ret
35 35
36 36 def visit_column(self, delta):
37 keys = delta.keys()
37 keys = list(delta.keys())
38 38
39 39 if 'name' in keys:
40 40 self._run_subvisit(delta,
@@ -51,15 +51,15 b' class OracleSchemaChanger(OracleSchemaGe'
51 51 # to null. We'll do that if default=None
52 52 # http://forums.oracle.com/forums/message.jspa?messageID=1273234#1273234
53 53 dropdefault_hack = (column.server_default is None \
54 and 'server_default' in delta.keys())
54 and 'server_default' in list(delta.keys()))
55 55 # Oracle apparently doesn't like it when we say "not null" if
56 56 # the column's already not null. Fudge it, so we don't need a
57 57 # new function
58 58 notnull_hack = ((not column.nullable) \
59 and ('nullable' not in delta.keys()))
59 and ('nullable' not in list(delta.keys())))
60 60 # We need to specify NULL if we're removing a NOT NULL
61 61 # constraint
62 null_hack = (column.nullable and ('nullable' in delta.keys()))
62 null_hack = (column.nullable and ('nullable' in list(delta.keys())))
63 63
64 64 if dropdefault_hack:
65 65 column.server_default = sa.PassiveDefault(sa.sql.null())
@@ -245,12 +245,12 b' class ColumnDelta(DictMixin, sqlalchemy.'
245 245 )
246 246
247 247 def __getitem__(self, key):
248 if key not in self.keys():
248 if key not in list(self.keys()):
249 249 raise KeyError("No such diff key, available: %s" % self.diffs )
250 250 return getattr(self.result_column, key)
251 251
252 252 def __setitem__(self, key, value):
253 if key not in self.keys():
253 if key not in list(self.keys()):
254 254 raise KeyError("No such diff key, available: %s" % self.diffs )
255 255 setattr(self.result_column, key, value)
256 256
@@ -264,7 +264,7 b' class ColumnDelta(DictMixin, sqlalchemy.'
264 264 raise NotImplementedError
265 265
266 266 def keys(self):
267 return self.diffs.keys()
267 return list(self.diffs.keys())
268 268
269 269 def compare_parameters(self, current_name, *p, **k):
270 270 """Compares Column objects with reflection"""
@@ -58,7 +58,7 b' command_desc = {'
58 58 'make_update_script_for_model': 'create a script changing the old MetaData to the new (current) MetaData',
59 59 'update_db_from_model': 'modify the database to match the structure of the current MetaData',
60 60 }
61 __all__ = command_desc.keys()
61 __all__ = list(command_desc.keys())
62 62
63 63 Repository = repository.Repository
64 64 ControlledSchema = schema.ControlledSchema
@@ -192,7 +192,7 b' class ModelGenerator(object):'
192 192 downgradeCommands.append(
193 193 "post_meta.tables[%(table)r].drop()" % {'table': tn})
194 194
195 for (tn, td) in self.diff.tables_different.items():
195 for (tn, td) in list(self.diff.tables_different.items()):
196 196 if td.columns_missing_from_A or td.columns_different:
197 197 pre_table = self.diff.metadataB.tables[tn]
198 198 decls.extend(self._getTableDefn(
@@ -13,12 +13,12 b' log = logging.getLogger(__name__)'
13 13
14 14 def usage():
15 15 """Gives usage information."""
16 print("""Usage: %(prog)s repository-to-migrate
16 print(("""Usage: %(prog)s repository-to-migrate
17 17
18 18 Upgrade your repository to the new flat format.
19 19
20 20 NOTE: You should probably make a backup before running this.
21 """ % {'prog': sys.argv[0]})
21 """ % {'prog': sys.argv[0]}))
22 22
23 23 sys.exit(1)
24 24
@@ -37,22 +37,22 b' class Changeset(dict):'
37 37 self.add(change)
38 38
39 39 def __iter__(self):
40 return iter(self.items())
40 return iter(list(self.items()))
41 41
42 42 def keys(self):
43 43 """
44 44 In a series of upgrades x -> y, keys are version x. Sorted.
45 45 """
46 ret = super(Changeset, self).keys()
46 ret = list(super(Changeset, self).keys())
47 47 # Reverse order if downgrading
48 48 ret.sort(reverse=(self.step < 1))
49 49 return ret
50 50
51 51 def values(self):
52 return [self[k] for k in self.keys()]
52 return [self[k] for k in list(self.keys())]
53 53
54 54 def items(self):
55 return zip(self.keys(), self.values())
55 return list(zip(list(self.keys()), list(self.values())))
56 56
57 57 def add(self, change):
58 58 """Add new change to changeset"""
@@ -221,7 +221,7 b' class Repository(pathed.Pathed):'
221 221 range_mod = 0
222 222 op = 'downgrade'
223 223
224 versions = range(int(start) + range_mod, int(end) + range_mod, step)
224 versions = list(range(int(start) + range_mod, int(end) + range_mod, step))
225 225 changes = [self.version(v).script(database, op) for v in versions]
226 226 ret = Changeset(start, step=step, *changes)
227 227 return ret
@@ -50,7 +50,7 b' class ControlledSchema(object):'
50 50 data = list(result)[0]
51 51 except:
52 52 cls, exc, tb = sys.exc_info()
53 raise exceptions.DatabaseNotControlledError, exc.__str__(), tb
53 raise exceptions.DatabaseNotControlledError(exc.__str__()).with_traceback(tb)
54 54
55 55 self.version = data['version']
56 56 return data
@@ -97,7 +97,7 b' class ColDiff(object):'
97 97 self.diff=True
98 98 return
99 99
100 def __nonzero__(self):
100 def __bool__(self):
101 101 return self.diff
102 102
103 103 __bool__ = __nonzero__
@@ -132,7 +132,7 b' class TableDiff(object):'
132 132 'columns_different',
133 133 )
134 134
135 def __nonzero__(self):
135 def __bool__(self):
136 136 return bool(
137 137 self.columns_missing_from_A or
138 138 self.columns_missing_from_B or
@@ -277,7 +277,7 b' class SchemaDiff(object):'
277 277 label,', '.join(sorted(names))
278 278 )
279 279 )
280 for name,cd in td.columns_different.items():
280 for name,cd in list(td.columns_different.items()):
281 281 out.append(' column with differences: %s' % name)
282 282 out.append(column_template % (self.labelA,cd.col_A))
283 283 out.append(column_template % (self.labelB,cd.col_B))
@@ -23,7 +23,7 b' alias = {'
23 23
24 24 def alias_setup():
25 25 global alias
26 for key, val in alias.items():
26 for key, val in list(alias.items()):
27 27 setattr(api, key, val)
28 28 alias_setup()
29 29
@@ -135,7 +135,7 b' def main(argv=None, **kwargs):'
135 135 override_kwargs[opt] = value
136 136
137 137 # override kwargs with options if user is overwriting
138 for key, value in options.__dict__.items():
138 for key, value in list(options.__dict__.items()):
139 139 if value is not None:
140 140 override_kwargs[key] = value
141 141
@@ -143,7 +143,7 b' def main(argv=None, **kwargs):'
143 143 f_required = list(f_args)
144 144 candidates = dict(kwargs)
145 145 candidates.update(override_kwargs)
146 for key, value in candidates.items():
146 for key, value in list(candidates.items()):
147 147 if key in f_args:
148 148 f_required.remove(key)
149 149
@@ -160,7 +160,7 b' def main(argv=None, **kwargs):'
160 160 kwargs.update(override_kwargs)
161 161
162 162 # configure options
163 for key, value in options.__dict__.items():
163 for key, value in list(options.__dict__.items()):
164 164 kwargs.setdefault(key, value)
165 165
166 166 # configure logging
@@ -131,7 +131,7 b' def construct_engine(engine, **opts):'
131 131 kwargs['echo'] = echo
132 132
133 133 # parse keyword arguments
134 for key, value in opts.items():
134 for key, value in list(opts.items()):
135 135 if key.startswith('engine_arg_'):
136 136 kwargs[key[11:]] = guess_obj_type(value)
137 137
@@ -1,5 +1,6 b''
1 1 import os
2 2 import sys
3 import importlib
3 4
4 5 def import_path(fullpath):
5 6 """ Import a file with full path specification. Allows one to
@@ -10,6 +11,6 b' def import_path(fullpath):'
10 11 filename, ext = os.path.splitext(filename)
11 12 sys.path.append(path)
12 13 module = __import__(filename)
13 reload(module) # Might be out of date during tests
14 importlib.reload(module) # Might be out of date during tests
14 15 del sys.path[-1]
15 16 return module
@@ -96,13 +96,13 b' class Collection(pathed.Pathed):'
96 96 # Create the versions member where the keys
97 97 # are VerNum's and the values are Version's.
98 98 self.versions = {}
99 for num, files in tempVersions.items():
99 for num, files in list(tempVersions.items()):
100 100 self.versions[VerNum(num)] = Version(num, path, files)
101 101
102 102 @property
103 103 def latest(self):
104 104 """:returns: Latest version in Collection"""
105 return max([VerNum(0)] + self.versions.keys())
105 return max([VerNum(0)] + list(self.versions.keys()))
106 106
107 107 def _next_ver_num(self, use_timestamp_numbering):
108 108 if use_timestamp_numbering == True:
General Comments 0
You need to be logged in to leave comments. Login now