summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel <g2p.code+sqla@gmail.com>2011-06-29 13:47:45 +0200
committerGabriel <g2p.code+sqla@gmail.com>2011-06-29 13:47:45 +0200
commit28d2ca21d5e503324c515a89af888d84c713b59b (patch)
tree9ebf7866b2e72c4be47bacaacd8d92b4eb4276b4
parent75df12b2274b78a5d8cae40dfb13a71caaa894e2 (diff)
downloadsqalchemy-migrate-28d2ca21d5e503324c515a89af888d84c713b59b.tar.gz
More concise declarative output.
https://code.google.com/p/sqlalchemy-migrate/issues/detail?id=122
-rw-r--r--migrate/versioning/genmodel.py29
1 files changed, 11 insertions, 18 deletions
diff --git a/migrate/versioning/genmodel.py b/migrate/versioning/genmodel.py
index 5c235da..826575a 100644
--- a/migrate/versioning/genmodel.py
+++ b/migrate/versioning/genmodel.py
@@ -59,7 +59,7 @@ class ModelGenerator(object):
pass
else:
kwarg.append('default')
- ks = ', '.join('%s=%r' % (k, getattr(col, k)) for k in kwarg)
+ args = ['%s=%r' % (k, getattr(col, k)) for k in kwarg]
# crs: not sure if this is good idea, but it gets rid of extra
# u''
@@ -73,28 +73,21 @@ class ModelGenerator(object):
type_ = cls()
break
- data = {
- 'name': name,
- 'type': type_,
- 'constraints': ', '.join([repr(cn) for cn in col.constraints]),
- 'args': ks and ks or ''}
+ type_repr = repr(type_)
+ if type_repr.endswith('()'):
+ type_repr = type_repr[:-2]
- if data['constraints']:
- if data['args']:
- data['args'] = ',' + data['args']
+ constraints = [repr(cn) for cn in col.constraints]
- if data['constraints'] or data['args']:
- data['maybeComma'] = ','
- else:
- data['maybeComma'] = ''
+ data = {
+ 'name': name,
+ 'commonStuff': ', '.join([type_repr] + args + constraints),
+ }
- commonStuff = """ %(maybeComma)s %(constraints)s %(args)s)""" % data
- commonStuff = commonStuff.strip()
- data['commonStuff'] = commonStuff
if self.declarative:
- return """%(name)s = Column(%(type)r%(commonStuff)s""" % data
+ return """%(name)s = Column(%(commonStuff)s)""" % data
else:
- return """Column(%(name)r, %(type)r%(commonStuff)s""" % data
+ return """Column(%(name)r, %(commonStuff)s)""" % data
def getTableDefn(self, table):
out = []