[RFR] Flake8
parent
b0da1f4fb9
commit
addc2d5b4f
|
@ -36,8 +36,8 @@
|
||||||
],
|
],
|
||||||
'description': """\
|
'description': """\
|
||||||
Clean your OpenERP database from remnants of modules, models, columns and
|
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
|
tables left by uninstalled modules (prior to 7.0) or a homebrew database
|
||||||
to a new major version of OpenERP.
|
upgrade to a new major version of OpenERP.
|
||||||
|
|
||||||
After installation of this module, go to the Settings menu -> Technical ->
|
After installation of this module, go to the Settings menu -> Technical ->
|
||||||
Database cleanup. Go through the modules, models, columns and tables
|
Database cleanup. Go through the modules, models, columns and tables
|
||||||
|
|
|
@ -53,7 +53,7 @@ class CleanupPurgeLineColumn(orm.TransientModel):
|
||||||
'WHERE attrelid = '
|
'WHERE attrelid = '
|
||||||
'( SELECT oid FROM pg_class WHERE relname = %s ) '
|
'( SELECT oid FROM pg_class WHERE relname = %s ) '
|
||||||
'AND attname = %s',
|
'AND attname = %s',
|
||||||
(model_pool._table, line.name));
|
(model_pool._table, line.name))
|
||||||
if not cr.fetchone()[0]:
|
if not cr.fetchone()[0]:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -68,6 +68,7 @@ class CleanupPurgeLineColumn(orm.TransientModel):
|
||||||
cr.commit()
|
cr.commit()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
class CleanupPurgeWizardColumn(orm.TransientModel):
|
class CleanupPurgeWizardColumn(orm.TransientModel):
|
||||||
_inherit = 'cleanup.purge.wizard'
|
_inherit = 'cleanup.purge.wizard'
|
||||||
_name = 'cleanup.purge.wizard.column'
|
_name = 'cleanup.purge.wizard.column'
|
||||||
|
@ -75,7 +76,7 @@ class CleanupPurgeWizardColumn(orm.TransientModel):
|
||||||
# List of known columns in use without corresponding fields
|
# List of known columns in use without corresponding fields
|
||||||
# Format: {table: [fields]}
|
# Format: {table: [fields]}
|
||||||
blacklist = {
|
blacklist = {
|
||||||
'wkf_instance': ['uid'], # lp:1277899
|
'wkf_instance': ['uid'], # lp:1277899
|
||||||
}
|
}
|
||||||
|
|
||||||
def default_get(self, cr, uid, fields, context=None):
|
def default_get(self, cr, uid, fields, context=None):
|
||||||
|
@ -123,7 +124,6 @@ class CleanupPurgeWizardColumn(orm.TransientModel):
|
||||||
res = []
|
res = []
|
||||||
model_pool = self.pool['ir.model']
|
model_pool = self.pool['ir.model']
|
||||||
model_ids = model_pool.search(cr, uid, [], context=context)
|
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, ...])
|
# mapping of tables to tuples (model id, [pool1, pool2, ...])
|
||||||
table2model = {}
|
table2model = {}
|
||||||
|
@ -132,7 +132,8 @@ class CleanupPurgeWizardColumn(orm.TransientModel):
|
||||||
model_pool = self.pool.get(model.model)
|
model_pool = self.pool.get(model.model)
|
||||||
if not model_pool or not model_pool._auto:
|
if not model_pool or not model_pool._auto:
|
||||||
continue
|
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 table, model_spec in table2model.iteritems():
|
||||||
for column in self.get_orphaned_columns(
|
for column in self.get_orphaned_columns(
|
||||||
|
|
|
@ -48,6 +48,7 @@ class CleanupPurgeLineData(orm.TransientModel):
|
||||||
self.pool['ir.model.data'].unlink(cr, uid, data_ids, context=context)
|
self.pool['ir.model.data'].unlink(cr, uid, data_ids, context=context)
|
||||||
return self.write(cr, uid, ids, {'purged': True}, context=context)
|
return self.write(cr, uid, ids, {'purged': True}, context=context)
|
||||||
|
|
||||||
|
|
||||||
class CleanupPurgeWizardData(orm.TransientModel):
|
class CleanupPurgeWizardData(orm.TransientModel):
|
||||||
_inherit = 'cleanup.purge.wizard'
|
_inherit = 'cleanup.purge.wizard'
|
||||||
_name = 'cleanup.purge.wizard.data'
|
_name = 'cleanup.purge.wizard.data'
|
||||||
|
|
|
@ -53,11 +53,11 @@ class CleanupPurgeLineModel(orm.TransientModel):
|
||||||
constraint_pool = self.pool['ir.model.constraint']
|
constraint_pool = self.pool['ir.model.constraint']
|
||||||
fields_pool = self.pool['ir.model.fields']
|
fields_pool = self.pool['ir.model.fields']
|
||||||
|
|
||||||
local_context=(context or {}).copy()
|
local_context = (context or {}).copy()
|
||||||
local_context.update({
|
local_context.update({
|
||||||
MODULE_UNINSTALL_FLAG: True,
|
MODULE_UNINSTALL_FLAG: True,
|
||||||
'no_drop_table': True,
|
'no_drop_table': True,
|
||||||
})
|
})
|
||||||
|
|
||||||
for line in self.browse(cr, uid, ids, context=context):
|
for line in self.browse(cr, uid, ids, context=context):
|
||||||
cr.execute(
|
cr.execute(
|
||||||
|
|
|
@ -56,8 +56,8 @@ class CleanupPurgeLineTable(orm.TransientModel):
|
||||||
FROM pg_attribute af, pg_attribute a,
|
FROM pg_attribute af, pg_attribute a,
|
||||||
(SELECT conname, conrelid, confrelid,conkey[i] AS conkey,
|
(SELECT conname, conrelid, confrelid,conkey[i] AS conkey,
|
||||||
confkey[i] AS confkey
|
confkey[i] AS confkey
|
||||||
FROM (select conname, conrelid, confrelid, conkey, confkey,
|
FROM (select conname, conrelid, confrelid, conkey,
|
||||||
generate_series(1,array_upper(conkey,1)) AS i
|
confkey, generate_series(1,array_upper(conkey,1)) AS i
|
||||||
FROM pg_constraint WHERE contype = 'f') ss) ss2
|
FROM pg_constraint WHERE contype = 'f') ss) ss2
|
||||||
WHERE af.attnum = confkey AND af.attrelid = confrelid AND
|
WHERE af.attnum = confkey AND af.attrelid = confrelid AND
|
||||||
a.attnum = conkey AND a.attrelid = conrelid
|
a.attnum = conkey AND a.attrelid = conrelid
|
||||||
|
@ -80,6 +80,7 @@ class CleanupPurgeLineTable(orm.TransientModel):
|
||||||
cr.commit()
|
cr.commit()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
class CleanupPurgeWizardTable(orm.TransientModel):
|
class CleanupPurgeWizardTable(orm.TransientModel):
|
||||||
_inherit = 'cleanup.purge.wizard'
|
_inherit = 'cleanup.purge.wizard'
|
||||||
_name = 'cleanup.purge.wizard.table'
|
_name = 'cleanup.purge.wizard.table'
|
||||||
|
@ -97,7 +98,6 @@ class CleanupPurgeWizardTable(orm.TransientModel):
|
||||||
Ignore views for now.
|
Ignore views for now.
|
||||||
"""
|
"""
|
||||||
model_ids = self.pool['ir.model'].search(cr, uid, [], context=context)
|
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
|
# Start out with known tables with no model
|
||||||
known_tables = ['wkf_witm_trans']
|
known_tables = ['wkf_witm_trans']
|
||||||
for model in self.pool['ir.model'].browse(
|
for model in self.pool['ir.model'].browse(
|
||||||
|
|
|
@ -36,6 +36,7 @@ class CleanupPurgeLine(orm.AbstractModel):
|
||||||
def purge(self, cr, uid, ids, context=None):
|
def purge(self, cr, uid, ids, context=None):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
class PurgeWizard(orm.AbstractModel):
|
class PurgeWizard(orm.AbstractModel):
|
||||||
""" Abstract base class for the purge wizards """
|
""" Abstract base class for the purge wizards """
|
||||||
_name = 'cleanup.purge.wizard'
|
_name = 'cleanup.purge.wizard'
|
||||||
|
|
Loading…
Reference in New Issue