[IMP] b.m.u: make dependency check faster before upgrade, cleanup

We need to be careful with naming dummy variables
"_" because that can conflict within the local
scope with the translation method _() if it is
used in the same method!

bzr revid: odo@openerp.com-20120330222023-3xzazf735k50f5xc
This commit is contained in:
Olivier Dony
2012-03-31 00:20:23 +02:00
parent 7588c0c888
commit 58605daded
2 changed files with 17 additions and 16 deletions
+4
View File
@@ -677,8 +677,12 @@ class module_dependency(osv.osv):
return result
_columns = {
# The dependency name
'name': fields.char('Name', size=128, select=True),
# The module that depends on it
'module_id': fields.many2one('ir.module.module', 'Module', select=True, ondelete='cascade'),
'state': fields.function(_state, type='selection', selection=[
('uninstallable','Uninstallable'),
('uninstalled','Not Installed'),
@@ -74,27 +74,24 @@ class base_module_upgrade(osv.osv_memory):
# install/upgrade: double-check preconditions
ids = ir_module.search(cr, uid, [('state', 'in', ['to upgrade', 'to install'])])
unmet_packages = []
mod_dep_obj = self.pool.get('ir.module.module.dependency')
# TODO: Replace the following loop with a single SQL query to make it much faster!
for mod in ir_module.browse(cr, uid, ids):
depends_mod_ids = mod_dep_obj.search(cr, uid, [('module_id', '=', mod.id)])
for dep_mod in mod_dep_obj.browse(cr, uid, depends_mod_ids):
if dep_mod.state in ('unknown','uninstalled'):
unmet_packages.append(dep_mod.name)
if unmet_packages:
raise osv.except_osv(_('Unmet dependency !'), _('Following modules are not installed or unknown: %s') % ('\n\n' + '\n'.join(unmet_packages)))
ir_module.download(cr, uid, ids, context=context)
if ids:
cr.execute("""SELECT d.name FROM ir_module_module m
JOIN ir_module_module_dependency d ON (m.id = d.module_id)
LEFT JOIN ir_module_module m2 ON (d.name = m2.name)
WHERE m.id in %s and (m2.state IS NULL or m2.state IN %s)""",
(tuple(ids), ('uninstalled',)))
unmet_packages = [x[0] for x in cr.fetchall()]
if unmet_packages:
raise osv.except_osv(_('Unmet dependency !'),
_('Following modules are not installed or unknown: %s') % ('\n\n' + '\n'.join(unmet_packages)))
# uninstall: double-check preconditions
# TODO: check all dependent modules are uninstalled
# XXX mod_ids_to_uninstall = ir_module.search(cr, uid, [('state', '=', 'to remove')])
ir_module.download(cr, uid, ids, context=context)
cr.commit() # save before re-creating cursor below
cr.commit() # persist changes before reopening a cursor
pooler.restart_pool(cr.dbname, update_module=True)
ir_model_data = self.pool.get('ir.model.data')
_, res_id = ir_model_data.get_object_reference(cr, uid, 'base', 'view_base_module_upgrade_install')
__, res_id = ir_model_data.get_object_reference(cr, uid, 'base', 'view_base_module_upgrade_install')
return {
'view_type': 'form',
'view_mode': 'form',