[IMP] : Improvement in server(module.py file)

bzr revid: sus@sus-desktop-20110301074035-7fx0v3gv8889slbb
This commit is contained in:
sus 2011-03-01 13:10:35 +05:30
parent 129a713b14
commit 73378da514
6 changed files with 50 additions and 60 deletions

View File

@ -843,7 +843,7 @@ def load_modules(db, force_demo=False, status=None, update_module=False):
if 'base' in tools.config['update'] or 'all' in tools.config['update']:
cr.execute("update ir_module_module set state=%s where name=%s and state=%s", ('to upgrade', 'base', 'installed'))
# STEP 1: LOAD BASE (must be done before module dependencies can be computed for later steps)
# STEP 1: LOAD BASE (must be done before module dependencies can be computed for later steps)
graph = create_graph(cr, ['base'], force)
if not graph:
logger.notifyChannel('init', netsvc.LOG_CRITICAL, 'module base cannot be loaded! (hint: verify addons-path)')

View File

@ -200,6 +200,7 @@ class module(osv.osv):
def _name_uniq_msg(self, cr, uid, ids, context=None):
return _('The name of the module must be unique !')
def _certificate_uniq_msg(self, cr, uid, ids, context=None):
return _('The certificate ID of the module must be unique !')
@ -285,8 +286,41 @@ class module(osv.osv):
demo = demo or mdemo
return demo
def upgrade(self, cr, uid, ids, context=None):
mod_obj = self.pool.get('ir.module.module')
ids = mod_obj.search(cr, uid, [('state', 'in', ['to upgrade', 'to remove', 'to install'])])
unmet_packages = []
mod_dep_obj = self.pool.get('ir.module.module.dependency')
for mod in mod_obj.browse(cr, uid, ids, context=context):
depends_mod_ids = mod_dep_obj.search(cr, uid, [('module_id', '=', mod.id)], context=context)
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 len(unmet_packages):
raise osv.except_osv(_('Unmet dependency !'), _('Following modules are not installed or unknown: %s') % ('\n\n' + '\n'.join(unmet_packages)))
mod_obj.download(cr, uid, ids, context=context)
cr.commit()
_db, pool = pooler.restart_pool(cr.dbname, update_module=True)
return True
def button_install(self, cr, uid, ids, context=None):
return self.state_update(cr, uid, ids, 'to install', ['uninstalled'], context)
self.state_update(cr, uid, ids, 'to install', ['uninstalled'], context)
self.upgrade(cr, uid, ids, context=context)
data_obj = self.pool.get('ir.model.data')
id2 = data_obj._get_id(cr, uid, 'base', 'view_base_module_upgrade_install')
if id2:
id2 = data_obj.browse(cr, uid, id2, context=context).res_id
return {
'view_type': 'form',
'view_mode': 'form',
'res_model': 'base.module.upgrade',
'views': [(id2, 'form')],
'view_id': False,
'type': 'ir.actions.act_window',
'target': 'new',
'nodestroy':True,
}
def button_install_cancel(self, cr, uid, ids, context=None):
self.write(cr, uid, ids, {'state': 'uninstalled', 'demo':False})
@ -305,49 +339,41 @@ class module(osv.osv):
res = cr.fetchall()
if res:
raise orm.except_orm(_('Error'), _('Some installed modules depend on the module you plan to Uninstall :\n %s') % '\n'.join(map(lambda x: '\t%s: %s' % (x[0], x[1]), res)))
self.write(cr, uid, ids, {'state': 'to remove'})
self.upgrade(cr, uid, ids, context=context)
return True
def button_uninstall_cancel(self, cr, uid, ids, context=None):
self.write(cr, uid, ids, {'state': 'installed'})
return True
def button_upgrade(self, cr, uid, ids, context=None):
depobj = self.pool.get('ir.module.module.dependency')
todo = self.browse(cr, uid, ids, context=context)
self.update_list(cr, uid)
i = 0
while i<len(todo):
mod = todo[i]
i += 1
if mod.state not in ('installed','to upgrade'):
raise orm.except_orm(_('Error'),
_("Can not upgrade module '%s'. It is not installed.") % (mod.name,))
self.check_external_dependencies(mod.name, 'to upgrade')
iids = depobj.search(cr, uid, [('name', '=', mod.name)], context=context)
for dep in depobj.browse(cr, uid, iids, context=context):
if dep.module_id.state=='installed' and dep.module_id not in todo:
todo.append(dep.module_id)
ids = map(lambda x: x.id, todo)
self.write(cr, uid, ids, {'state':'to upgrade'}, context=context)
to_install = []
for mod in todo:
for dep in mod.dependencies_id:
if dep.state == 'unknown':
raise orm.except_orm(_('Error'), _('You try to upgrade a module that depends on the module: %s.\nBut this module is not available in your system.') % (dep.name,))
if dep.state == 'uninstalled':
if dep.state == 'installed':
ids2 = self.search(cr, uid, [('name','=',dep.name)])
to_install.extend(ids2)
self.button_install(cr, uid, to_install, context=context)
self.upgrade(cr, uid, to_install, context=context)
return True
def button_upgrade_cancel(self, cr, uid, ids, context=None):
self.write(cr, uid, ids, {'state': 'installed'})
return True
def button_update_translations(self, cr, uid, ids, context=None):
self.update_translations(cr, uid, ids)
return True
@ -383,7 +409,7 @@ class module(osv.osv):
updated_values = {}
for key in values:
old = getattr(mod, key)
updated = isinstance(values[key], basestring) and tools.ustr(values[key]) or values[key]
updated = isinstance(values[key], basestring) and tools.ustr(values[key]) or values[key]
if not old == updated:
updated_values[key] = values[key]
if terp.get('installable', True) and mod.state == 'uninstallable':

View File

@ -112,7 +112,7 @@
<newline/>
<field name="state" readonly="1" select="1"/>
<group col="6" colspan="2">
<button name="button_install" states="uninstalled" string="Schedule for Installation" icon="terp-gtk-jump-to-ltr" type="object"/>
<button name="button_install" states="uninstalled" string="Install" icon="terp-gtk-jump-to-ltr" type="object"/>
<button name="button_install_cancel" states="to install" string="Cancel Install" icon="gtk-cancel" type="object"/>
<button name="button_uninstall" states="installed" string="Uninstall (beta)" icon="terp-dialog-close" type="object"/>
<button name="button_uninstall_cancel" states="to remove" string="Cancel Uninstall" icon="gtk-cancel" type="object"/>

View File

@ -19,7 +19,6 @@
#
##############################################################################
import pooler
from osv import osv, fields
from tools.translate import _
@ -81,36 +80,6 @@ class base_module_upgrade(osv.osv_memory):
res = mod_obj.read(cr, uid, ids, ['name','state'], context)
return {'module_info': '\n'.join(map(lambda x: x['name']+' : '+x['state'], res))}
def upgrade_module(self, cr, uid, ids, context=None):
mod_obj = self.pool.get('ir.module.module')
ids = mod_obj.search(cr, uid, [('state', 'in', ['to upgrade', 'to remove', 'to install'])])
unmet_packages = []
mod_dep_obj = self.pool.get('ir.module.module.dependency')
for mod in mod_obj.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 len(unmet_packages):
raise osv.except_osv(_('Unmet dependency !'), _('Following modules are not installed or unknown: %s') % ('\n\n' + '\n'.join(unmet_packages)))
mod_obj.download(cr, uid, ids, context=context)
cr.commit()
_db, pool = pooler.restart_pool(cr.dbname, update_module=True)
data_obj = pool.get('ir.model.data')
id2 = data_obj._get_id(cr, uid, 'base', 'view_base_module_upgrade_install')
if id2:
id2 = data_obj.browse(cr, uid, id2, context=context).res_id
return {
'view_type': 'form',
'view_mode': 'form',
'res_model': 'base.module.upgrade',
'views': [(id2, 'form')],
'view_id': False,
'type': 'ir.actions.act_window',
'target': 'new',
}
def config(self, cr, uid, ids, context=None):
return self.pool.get('res.config').next(cr, uid, [], context=context)

View File

@ -30,17 +30,13 @@
<field name="target">new</field>
</record>
<menuitem
name="Apply Scheduled Upgrades"
action="action_view_base_module_upgrade"
id="menu_view_base_module_upgrade"
parent="menu_management"
sequence="3"/>
<!-- <menuitem-->
<!-- name="Apply Scheduled Upgrades"-->
<!-- action="action_view_base_module_upgrade"-->
<!-- id="menu_view_base_module_upgrade"-->
<!-- parent="menu_management"-->
<!-- sequence="3"/>-->
<act_window id="action_view_base_module_upgrade_window"
key2="client_action_multi" name="Apply Scheduled Upgrades"
res_model="base.module.upgrade" src_model="ir.module.module"
view_mode="form" target="new" view_type="form" />
<record id="view_base_module_upgrade_install" model="ir.ui.view">
<field name="name">Module Upgrade Install</field>

View File

@ -571,7 +571,6 @@ class groups2(osv.osv): ##FIXME: Is there a reason to inherit this object ?
for record in self.read(cr, uid, ids, ['users'], context=context):
if record['users']:
group_users.extend(record['users'])
if group_users:
user_names = [user.name for user in self.pool.get('res.users').browse(cr, uid, group_users, context=context)]
if len(user_names) >= 5: