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