Browse Source

[RFR] Flake8

pull/95/head
Stefan Rijnhart 11 years ago
parent
commit
addc2d5b4f
  1. 4
      database_cleanup/__openerp__.py
  2. 15
      database_cleanup/model/purge_columns.py
  3. 1
      database_cleanup/model/purge_data.py
  4. 8
      database_cleanup/model/purge_models.py
  5. 2
      database_cleanup/model/purge_modules.py
  6. 12
      database_cleanup/model/purge_tables.py
  7. 1
      database_cleanup/model/purge_wizard.py

4
database_cleanup/__openerp__.py

@ -36,8 +36,8 @@
],
'description': """\
Clean your OpenERP database from remnants of modules, models, columns and
tables left by uninstalled modules (prior to 7.0) or a homebrew database upgrade
to a new major version of OpenERP.
tables left by uninstalled modules (prior to 7.0) or a homebrew database
upgrade to a new major version of OpenERP.
After installation of this module, go to the Settings menu -> Technical ->
Database cleanup. Go through the modules, models, columns and tables

15
database_cleanup/model/purge_columns.py

@ -53,7 +53,7 @@ class CleanupPurgeLineColumn(orm.TransientModel):
'WHERE attrelid = '
'( SELECT oid FROM pg_class WHERE relname = %s ) '
'AND attname = %s',
(model_pool._table, line.name));
(model_pool._table, line.name))
if not cr.fetchone()[0]:
continue
@ -68,6 +68,7 @@ class CleanupPurgeLineColumn(orm.TransientModel):
cr.commit()
return True
class CleanupPurgeWizardColumn(orm.TransientModel):
_inherit = 'cleanup.purge.wizard'
_name = 'cleanup.purge.wizard.column'
@ -75,7 +76,7 @@ class CleanupPurgeWizardColumn(orm.TransientModel):
# List of known columns in use without corresponding fields
# Format: {table: [fields]}
blacklist = {
'wkf_instance': ['uid'], # lp:1277899
'wkf_instance': ['uid'], # lp:1277899
}
def default_get(self, cr, uid, fields, context=None):
@ -91,9 +92,9 @@ class CleanupPurgeWizardColumn(orm.TransientModel):
Iterate on the database columns to identify columns
of fields which have been removed
"""
columns = list(set([
column for model_pool in model_pools
column for model_pool in model_pools
for column in model_pool._columns
if not (isinstance(model_pool._columns[column], fields.function)
and not model_pool._columns[column].store)
@ -123,7 +124,6 @@ class CleanupPurgeWizardColumn(orm.TransientModel):
res = []
model_pool = self.pool['ir.model']
model_ids = model_pool.search(cr, uid, [], context=context)
line_pool = self.pool['cleanup.purge.line.column']
# mapping of tables to tuples (model id, [pool1, pool2, ...])
table2model = {}
@ -132,8 +132,9 @@ class CleanupPurgeWizardColumn(orm.TransientModel):
model_pool = self.pool.get(model.model)
if not model_pool or not model_pool._auto:
continue
table2model.setdefault(model_pool._table, (model.id, []))[1].append(model_pool)
table2model.setdefault(
model_pool._table, (model.id, []))[1].append(model_pool)
for table, model_spec in table2model.iteritems():
for column in self.get_orphaned_columns(
cr, uid, model_spec[1], context=context):

1
database_cleanup/model/purge_data.py

@ -48,6 +48,7 @@ class CleanupPurgeLineData(orm.TransientModel):
self.pool['ir.model.data'].unlink(cr, uid, data_ids, context=context)
return self.write(cr, uid, ids, {'purged': True}, context=context)
class CleanupPurgeWizardData(orm.TransientModel):
_inherit = 'cleanup.purge.wizard'
_name = 'cleanup.purge.wizard.data'

8
database_cleanup/model/purge_models.py

@ -53,11 +53,11 @@ class CleanupPurgeLineModel(orm.TransientModel):
constraint_pool = self.pool['ir.model.constraint']
fields_pool = self.pool['ir.model.fields']
local_context=(context or {}).copy()
local_context = (context or {}).copy()
local_context.update({
MODULE_UNINSTALL_FLAG: True,
'no_drop_table': True,
})
MODULE_UNINSTALL_FLAG: True,
'no_drop_table': True,
})
for line in self.browse(cr, uid, ids, context=context):
cr.execute(

2
database_cleanup/model/purge_modules.py

@ -50,7 +50,7 @@ class CleanupPurgeLineModule(orm.TransientModel):
module_pool.write(
cr, uid, module_ids, {'state': 'to remove'}, context=context)
cr.commit()
_db, _pool = pooler.restart_pool(cr.dbname, update_module=True)
_db, _pool = pooler.restart_pool(cr.dbname, update_module=True)
module_pool.unlink(cr, uid, module_ids, context=context)
return self.write(cr, uid, ids, {'purged': True}, context=context)

12
database_cleanup/model/purge_tables.py

@ -56,11 +56,11 @@ class CleanupPurgeLineTable(orm.TransientModel):
FROM pg_attribute af, pg_attribute a,
(SELECT conname, conrelid, confrelid,conkey[i] AS conkey,
confkey[i] AS confkey
FROM (select conname, conrelid, confrelid, conkey, confkey,
generate_series(1,array_upper(conkey,1)) AS i
FROM (select conname, conrelid, confrelid, conkey,
confkey, generate_series(1,array_upper(conkey,1)) AS i
FROM pg_constraint WHERE contype = 'f') ss) ss2
WHERE af.attnum = confkey AND af.attrelid = confrelid AND
a.attnum = conkey AND a.attrelid = conrelid
a.attnum = conkey AND a.attrelid = conrelid
AND confrelid::regclass = '%s'::regclass;
""" % line.name)
@ -80,6 +80,7 @@ class CleanupPurgeLineTable(orm.TransientModel):
cr.commit()
return True
class CleanupPurgeWizardTable(orm.TransientModel):
_inherit = 'cleanup.purge.wizard'
_name = 'cleanup.purge.wizard.table'
@ -97,12 +98,11 @@ class CleanupPurgeWizardTable(orm.TransientModel):
Ignore views for now.
"""
model_ids = self.pool['ir.model'].search(cr, uid, [], context=context)
line_pool = self.pool['cleanup.purge.line.table']
# Start out with known tables with no model
known_tables = ['wkf_witm_trans']
for model in self.pool['ir.model'].browse(
cr, uid, model_ids, context=context):
model_pool = self.pool.get(model.model)
if not model_pool:
continue
@ -120,7 +120,7 @@ class CleanupPurgeWizardTable(orm.TransientModel):
[("'%s'" % table) for table in known_tables])
cr.execute(
"""
SELECT table_name FROM information_schema.tables
SELECT table_name FROM information_schema.tables
WHERE table_schema = 'public' AND table_type = 'BASE TABLE'
AND table_name NOT IN (%s)""" % known_tables_repr)

1
database_cleanup/model/purge_wizard.py

@ -36,6 +36,7 @@ class CleanupPurgeLine(orm.AbstractModel):
def purge(self, cr, uid, ids, context=None):
raise NotImplementedError
class PurgeWizard(orm.AbstractModel):
""" Abstract base class for the purge wizards """
_name = 'cleanup.purge.wizard'

Loading…
Cancel
Save