Permalink
Browse files

Fix various warnings, mostly indentation, reported by flake8.

  • Loading branch information...
1 parent e3207b0 commit fd8868668efa571ae4816d67e1cefac5aa967a07 @jmafc jmafc committed Mar 26, 2013
View
@@ -15,13 +15,13 @@ def parent_parser():
parser.add_argument('dbname', help='database name')
group = parser.add_argument_group('Connection options')
group.add_argument('-H', '--host', help="database server host or "
- "socket directory (default %(default)s)")
+ "socket directory (default %(default)s)")
group.add_argument('-p', '--port', type=int, help="database server port "
- "number (default %(default)s)")
+ "number (default %(default)s)")
group.add_argument('-U', '--username', dest='username',
- help="database user name (default %(default)s)")
+ help="database user name (default %(default)s)")
group.add_argument('-W', '--password', action="store_true",
- help="force password prompt")
+ help="force password prompt")
parser.add_argument('-o', '--output', type=FileType('w'),
help="output file name (default stdout)")
parser.add_argument('--version', action='version',
View
@@ -299,7 +299,7 @@ def diff_map(self, input_map, opts):
langs = None
if self.dbconn.version >= 90100:
langs = [lang[0] for lang in self.dbconn.fetchall(
- "SELECT tmplname FROM pg_pltemplate")]
+ "SELECT tmplname FROM pg_pltemplate")]
self.from_map(input_map, langs)
stmts = self.db.extensions.diff_map(self.ndb.extensions)
stmts.append(self.db.languages.diff_map(self.ndb.languages))
View
@@ -6,8 +6,7 @@
This module defines two classes: Column derived from
DbSchemaObject and ColumnDict derived from DbObjectDict.
"""
-from pyrseas.dbobject import DbObjectDict, DbSchemaObject
-from pyrseas.dbobject import quote_id, grantable
+from pyrseas.dbobject import DbObjectDict, DbSchemaObject, quote_id
from pyrseas.dbobject.privileges import privileges_from_map, add_grant
from pyrseas.dbobject.privileges import diff_privs
@@ -133,7 +132,7 @@ def set_sequence_default(self):
if pth:
stmts.append(pth)
stmts.append("ALTER TABLE %s ALTER COLUMN %s SET DEFAULT %s" % (
- quote_id(self.table), quote_id(self.name), self.default))
+ quote_id(self.table), quote_id(self.name), self.default))
return stmts
def diff_map(self, incol):
@@ -170,22 +169,22 @@ def diff_map(self, incol):
QUERY_PRE91 = \
- """SELECT nspname AS schema, relname AS table, attname AS name,
- attnum AS number, format_type(atttypid, atttypmod) AS type,
- attnotnull AS not_null, attinhcount AS inherited,
- pg_get_expr(adbin, adrelid) AS default,
- attisdropped AS dropped,
- array_to_string(attacl, ',') AS privileges,
- col_description(c.oid, attnum) AS description
- FROM pg_attribute JOIN pg_class c ON (attrelid = c.oid)
- JOIN pg_namespace ON (relnamespace = pg_namespace.oid)
- LEFT JOIN pg_attrdef ON (attrelid = pg_attrdef.adrelid
- AND attnum = pg_attrdef.adnum)
- WHERE relkind in ('c', 'r', 'f')
- AND (nspname != 'pg_catalog'
- AND nspname != 'information_schema')
- AND attnum > 0
- ORDER BY nspname, relname, attnum"""
+ """SELECT nspname AS schema, relname AS table, attname AS name,
+ attnum AS number, format_type(atttypid, atttypmod) AS type,
+ attnotnull AS not_null, attinhcount AS inherited,
+ pg_get_expr(adbin, adrelid) AS default,
+ attisdropped AS dropped,
+ array_to_string(attacl, ',') AS privileges,
+ col_description(c.oid, attnum) AS description
+ FROM pg_attribute JOIN pg_class c ON (attrelid = c.oid)
+ JOIN pg_namespace ON (relnamespace = pg_namespace.oid)
+ LEFT JOIN pg_attrdef ON (attrelid = pg_attrdef.adrelid
+ AND attnum = pg_attrdef.adnum)
+ WHERE relkind in ('c', 'r', 'f')
+ AND (nspname != 'pg_catalog'
+ AND nspname != 'information_schema')
+ AND attnum > 0
+ ORDER BY nspname, relname, attnum"""
class ColumnDict(DbObjectDict):
@@ -245,9 +244,9 @@ def from_map(self, table, incols):
if not hasattr(table, 'owner'):
raise ValueError("Column '%s.%s' has privileges but "
"no owner information" % (
- table.name, key))
+ table.name, key))
col.privileges = privileges_from_map(
- col.privileges, col.allprivs, table.owner)
+ col.privileges, col.allprivs, table.owner)
cols.append(col)
def diff_map(self, incols):
@@ -333,7 +333,7 @@ def from_map(self, table, inconstrs, target=''):
chks = inconstrs['check_constraints']
for cns in list(chks.keys()):
check = CheckConstraint(table=table.name, schema=table.schema,
- name=cns)
+ name=cns)
val = chks[cns]
try:
check.expression = val['expression']
@@ -368,7 +368,7 @@ def from_map(self, table, inconstrs, target=''):
fkeys = inconstrs['foreign_keys']
for cns in list(fkeys.keys()):
fkey = ForeignKey(table=table.name, schema=table.schema,
- name=cns)
+ name=cns)
val = fkeys[cns]
if 'on_update' in val:
act = val['on_update']
@@ -412,7 +412,7 @@ def from_map(self, table, inconstrs, target=''):
fkey.ref_cols = refs['columns']
except KeyError as exc:
exc.args = ("Constraint '%s' missing reference columns"
- % cns, )
+ % cns, )
raise
sch = table.schema
if 'schema' in refs:
@@ -425,7 +425,7 @@ def from_map(self, table, inconstrs, target=''):
uconstrs = inconstrs['unique_constraints']
for cns in list(uconstrs.keys()):
unq = UniqueConstraint(table=table.name, schema=table.schema,
- name=cns)
+ name=cns)
val = uconstrs[cns]
try:
unq.keycols = val['columns']
View
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
"""
- pyrseas.dbobject.type
- ~~~~~~~~~~~~~~~~~~~~~
+ pyrseas.dbobject.dbtype
+ ~~~~~~~~~~~~~~~~~~~~~~~
This module defines six classes: DbType derived from
DbSchemaObject, BaseType, Composite, Domain and Enum derived from
@@ -59,7 +59,7 @@ def create(self):
if fnc in self.dep_funcs:
stmts.append(self.dep_funcs[fnc].create(basetype=True))
opt_clauses.append("%s = %s" % (
- fnc.upper(), self.dep_funcs[fnc].qualname()))
+ fnc.upper(), self.dep_funcs[fnc].qualname()))
if hasattr(self, 'internallength'):
opt_clauses.append("INTERNALLENGTH = %s" % self.internallength)
if hasattr(self, 'alignment'):
@@ -74,8 +74,8 @@ def create(self):
opt_clauses.append("PREFERRED = TRUE")
stmts.append("CREATE TYPE %s (\n INPUT = %s,"
"\n OUTPUT = %s%s%s)" % (
- self.qualname(), self.input, self.output,
- opt_clauses and ',\n ' or '', ',\n '.join(opt_clauses)))
+ self.qualname(), self.input, self.output, opt_clauses and
+ ',\n ' or '', ',\n '.join(opt_clauses)))
return stmts
def drop(self):
@@ -139,7 +139,7 @@ def diff_map(self, intype):
if not hasattr(intype, 'attributes'):
raise KeyError("Composite '%s' has no attributes" % intype.name)
attrnames = [attr.name for attr in self.attributes
- if not hasattr(attr, 'dropped')]
+ if not hasattr(attr, 'dropped')]
dbattrs = len(attrnames)
base = "ALTER TYPE %s\n " % (self.qualname())
@@ -125,9 +125,9 @@ def create(self, newsrc=None, basetype=False):
stmts.append("CREATE%s FUNCTION %s(%s) RETURNS %s\n LANGUAGE %s"
"%s%s%s%s%s%s\n AS %s" % (
- newsrc and " OR REPLACE" or '', self.qualname(),
- self.arguments, self.returns, self.language, volat, strict,
- secdef, cost, rows, config, src))
+ newsrc and " OR REPLACE" or '', self.qualname(),
+ self.arguments, self.returns, self.language, volat,
+ strict, secdef, cost, rows, config, src))
return stmts
def diff_map(self, infunction):
@@ -185,7 +185,7 @@ def create(self):
if hasattr(self, 'sortop'):
opt_clauses.append("SORTOP = %s" % self.sortop)
return ["CREATE AGGREGATE %s(%s) (\n SFUNC = %s,"
- "\n STYPE = %s%s%s)" % (
+ "\n STYPE = %s%s%s)" % (
self.qualname(),
self.arguments, self.sfunc, self.stype,
opt_clauses and ',\n ' or '', ',\n '.join(opt_clauses))]
@@ -268,11 +268,11 @@ def diff_map(self, inindexes):
oldname = inidx.oldname
try:
stmts.append(self[(sch, tbl, oldname)].rename(
- inidx.name))
+ inidx.name))
del self[(sch, tbl, oldname)]
except KeyError as exc:
exc.args = ("Previous name '%s' for index '%s' "
- "not found" % (oldname, inidx.name), )
+ "not found" % (oldname, inidx.name), )
raise
else:
# create new index
@@ -131,10 +131,10 @@ def add_grant(obj, privspec, subobj=''):
stmts = []
if privs:
stmts.append("GRANT %s ON %s %s TO %s" % (
- ', '.join(privs), objtype, obj.identifier(), usr))
+ ', '.join(privs), objtype, obj.identifier(), usr))
if wgo:
stmts.append("GRANT %s ON %s %s TO %s WITH GRANT OPTION" % (
- ', '.join(wgo), objtype, obj.identifier(), usr))
+ ', '.join(wgo), objtype, obj.identifier(), usr))
return stmts
@@ -154,10 +154,10 @@ def add_revoke(obj, privspec, subobj=''):
stmts = []
if wgo:
stmts.append("REVOKE %s ON %s %s FROM %s" % (
- ', '.join(wgo), objtype, obj.identifier(), usr))
+ ', '.join(wgo), objtype, obj.identifier(), usr))
if privs:
stmts.append("REVOKE %s ON %s %s FROM %s" % (
- ', '.join(privs), objtype, obj.identifier(), usr))
+ ', '.join(privs), objtype, obj.identifier(), usr))
return stmts
View
@@ -70,7 +70,7 @@ def _from_catalog(self):
do_loc = rule.definition.index(' DO ')
if 'WHERE' in rule.definition:
rule.condition = rule.definition[rule.definition.index(
- ' WHERE ') + 7:do_loc]
+ ' WHERE ') + 7:do_loc]
if hasattr(rule, 'instead') and rule.instead:
do_loc += 8
rule.actions = rule.definition[do_loc + 4:-1]
@@ -84,8 +84,8 @@ def from_map(self, table, inmap):
"""
for rul in list(inmap.keys()):
inrule = inmap[rul]
- rule = Rule(table=table.name, schema=table.schema,
- name=rul, **inrule)
+ rule = Rule(table=table.name, schema=table.schema, name=rul,
+ **inrule)
if inrule:
if 'oldname' in inrule:
rule.oldname = inrule['oldname']
View
@@ -79,14 +79,14 @@ def to_map(self, opts):
(self.name not in opts.tables and
not hasattr(self, 'owner_table') or
self.owner_table not in opts.tables) or (
- hasattr(opts, 'excl_tables') and opts.excl_tables
- and self.name in opts.excl_tables):
+ hasattr(opts, 'excl_tables') and opts.excl_tables
+ and self.name in opts.excl_tables):
return None
seq = {}
for key, val in list(self.__dict__.items()):
if key in self.keylist or key == 'dependent_table' or (
- key == 'owner' and opts.no_owner) or (
- key == 'privileges' and opts.no_privs):
+ key == 'owner' and opts.no_owner) or (
+ key == 'privileges' and opts.no_privs):
continue
if key == 'privileges':
seq[key] = self.map_privs()
@@ -138,8 +138,8 @@ def add_owner(self):
if pth:
stmts.append(pth)
stmts.append("ALTER SEQUENCE %s OWNED BY %s.%s" % (
- quote_id(self.name), quote_id(self.owner_table),
- quote_id(self.owner_column)))
+ quote_id(self.name), quote_id(self.owner_table),
+ quote_id(self.owner_column)))
return stmts
def diff_map(self, inseq):
@@ -236,16 +236,15 @@ def to_map(self, dbschemas, opts):
self.check_constraints[k.name].to_map(self.column_names()))
if hasattr(self, 'primary_key'):
tbl.update(primary_key=self.primary_key.to_map(
- self.column_names()))
+ self.column_names()))
if hasattr(self, 'foreign_keys'):
if not 'foreign_keys' in tbl:
tbl['foreign_keys'] = {}
for k in list(self.foreign_keys.values()):
tbls = dbschemas[k.ref_schema].tables
tbl['foreign_keys'].update(self.foreign_keys[k.name].to_map(
- self.column_names(),
- tbls[self.foreign_keys[k.name].ref_table].
- column_names()))
+ self.column_names(),
+ tbls[self.foreign_keys[k.name].ref_table]. column_names()))
if hasattr(self, 'unique_constraints'):
if not 'unique_constraints' in tbl:
tbl.update(unique_constraints={})
@@ -304,8 +303,8 @@ def create(self):
if hasattr(self, 'tablespace'):
tblspc = " TABLESPACE %s" % self.tablespace
stmts.append("CREATE %sTABLE %s (\n%s)%s%s%s" % (
- unlogged, self.qualname(), ",\n".join(cols), inhclause,
- opts, tblspc))
+ unlogged, self.qualname(), ",\n".join(cols), inhclause, opts,
+ tblspc))
if hasattr(self, 'owner'):
stmts.append(self.alter_owner())
if hasattr(self, 'privileges'):
@@ -416,8 +415,8 @@ def diff_map(self, intable):
newopts = intable.options
diff_opts = self.diff_options(newopts)
if diff_opts:
- stmts.append("ALTER %s %s %s" % (
- self.objtype, self.identifier(), diff_opts))
+ stmts.append("ALTER %s %s %s" % (self.objtype, self.identifier(),
+ diff_opts))
if hasattr(intable, 'owner'):
if intable.owner != self.owner:
stmts.append(self.alter_owner(intable.owner))
@@ -501,20 +500,20 @@ def diff_map(self, inview):
QUERY_PRE91 = \
- """SELECT nspname AS schema, relname AS name, relkind AS kind,
- reloptions AS options, spcname AS tablespace,
- rolname AS owner, array_to_string(relacl, ',') AS privileges,
- CASE WHEN relkind = 'v' THEN pg_get_viewdef(c.oid, TRUE)
- ELSE '' END AS definition,
- obj_description(c.oid, 'pg_class') AS description
- FROM pg_class c
- JOIN pg_roles r ON (r.oid = relowner)
- JOIN pg_namespace ON (relnamespace = pg_namespace.oid)
- LEFT JOIN pg_tablespace t ON (reltablespace = t.oid)
- WHERE relkind in ('r', 'S', 'v')
- AND (nspname != 'pg_catalog'
- AND nspname != 'information_schema')
- ORDER BY nspname, relname"""
+ """SELECT nspname AS schema, relname AS name, relkind AS kind,
+ reloptions AS options, spcname AS tablespace,
+ rolname AS owner, array_to_string(relacl, ',') AS privileges,
+ CASE WHEN relkind = 'v' THEN pg_get_viewdef(c.oid, TRUE)
+ ELSE '' END AS definition,
+ obj_description(c.oid, 'pg_class') AS description
+ FROM pg_class c
+ JOIN pg_roles r ON (r.oid = relowner)
+ JOIN pg_namespace ON (relnamespace = pg_namespace.oid)
+ LEFT JOIN pg_tablespace t ON (reltablespace = t.oid)
+ WHERE relkind in ('r', 'S', 'v')
+ AND (nspname != 'pg_catalog'
+ AND nspname != 'information_schema')
+ ORDER BY nspname, relname"""
class ClassDict(DbObjectDict):
@@ -730,7 +729,7 @@ def _rename(self, obj, objtype):
del self[(obj.schema, oldname)]
except KeyError as exc:
exc.args = ("Previous name '%s' for %s '%s' not found" % (
- oldname, objtype, obj.name), )
+ oldname, objtype, obj.name), )
raise
return stmt
@@ -850,7 +849,7 @@ def diff_map(self, intables):
if (isinstance(table, Sequence)
and (hasattr(table, 'owner_table')
or hasattr(table, 'dependent_table'))) \
- or isinstance(table, View):
+ or isinstance(table, View):
continue
if hasattr(table, 'dropped') and not table.dropped:
# next, drop other subordinate objects
Oops, something went wrong.

0 comments on commit fd88686

Please sign in to comment.