From bf462bb02b88b3ac5c2e88cb55c571fc46c8ba9b Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Wed, 6 Jan 2010 08:53:30 +0100 Subject: [PATCH 1/3] [imp] installer config object bzr revid: xmo@tinyerp.com-20100106075330-40m5n6j1nko5p2mk --- bin/addons/base/res/res_config.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/bin/addons/base/res/res_config.py b/bin/addons/base/res/res_config.py index 0060de4e1d1..57222efea7a 100644 --- a/bin/addons/base/res/res_config.py +++ b/bin/addons/base/res/res_config.py @@ -21,6 +21,7 @@ from osv import osv, fields import netsvc +import pooler class res_config_configurable(osv.osv_memory): ''' Base classes for new-style configuration items @@ -109,6 +110,31 @@ class res_config_configurable(osv.osv_memory): return self.next(cr, uid, ids, context=context) res_config_configurable() +class res_config_installer(osv.osv_memory): + ''' New-style configuration base specialized for modules selection + and installation. + ''' + _name = 'res.config.installer' + _inherit = 'res.config' + + def execute(self, cr, uid, ids, context=None): + modules = self.pool.get('ir.module.module') + + for installer in self.read(cr, uid, ids): + for addon_name, to_install in installer.iteritems(): + if addon_name != 'id' and to_install: + self.logger.notifyChannel( + 'installer', netsvc.LOG_INFO, + 'Selecting addon "%s" to install'%addon_name) + modules.button_install( + cr, uid, + modules.search(cr, uid, [('name','=',addon_name)]), + context=context) + cr.commit() + + pooler.restart_pool(cr.dbname, update_module=True) +res_config_installer() + DEPRECATION_MESSAGE = 'You are using an addon using old-style configuration '\ 'wizards (ir.actions.configuration.wizard). Old-style configuration '\ 'wizards have been deprecated.\n'\ From fa1a8fe6be6d36802ea7afe746122505cc1933d0 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Wed, 6 Jan 2010 12:54:54 +0100 Subject: [PATCH 2/3] [imp] Split modules selection from actual installation, add handling of hooks and additionals * Hooks are functions executed when a given module has been selected for installation - Named ``_if_%(module_name)s`` - Provided cr, uid, ids and context - If they return something, it must be an iterable of supplementary addons to install * Additionals are module sets to install when a given set of 1..n module(s) is selected for installation - ``_install_if`` class member - dictionary of {tuple: iterable}, the tuple is the set of modules to check for, the iterable is the set of modules to install if the condition modules are all present bzr revid: xmo@tinyerp.com-20100106115454-r8qrooqkfvy5kg41 --- bin/addons/base/res/res_config.py | 42 +++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/bin/addons/base/res/res_config.py b/bin/addons/base/res/res_config.py index 57222efea7a..db93e152f3c 100644 --- a/bin/addons/base/res/res_config.py +++ b/bin/addons/base/res/res_config.py @@ -117,19 +117,39 @@ class res_config_installer(osv.osv_memory): _name = 'res.config.installer' _inherit = 'res.config' + _install_if = {} + + def _modules_to_install(self, cr, uid, ids, context=None): + base = set(module_name + for installer in self.read(cr, uid, ids, context=context) + for module_name, to_install in installer.iteritems() + if module_name != 'id' + if type(self._columns[module_name]) is fields.boolean + if to_install) + hooks_results = set() + for module in base: + hook = getattr(self, '_if_%s'%(module), None) + if hook: + hooks_results.update(hook(cr, uid, ids, context=None) or set()) + + additionals = set( + module for requirements, consequences \ + in self._install_if.iteritems() + if base.issuperset(requirements) + for module in consequences) + + return base | hooks_results | additionals + def execute(self, cr, uid, ids, context=None): modules = self.pool.get('ir.module.module') - - for installer in self.read(cr, uid, ids): - for addon_name, to_install in installer.iteritems(): - if addon_name != 'id' and to_install: - self.logger.notifyChannel( - 'installer', netsvc.LOG_INFO, - 'Selecting addon "%s" to install'%addon_name) - modules.button_install( - cr, uid, - modules.search(cr, uid, [('name','=',addon_name)]), - context=context) + for module in self._modules_to_install(cr, uid, ids, context=context): + self.logger.notifyChannel( + 'installer', netsvc.LOG_INFO, + 'Selecting addon "%s" to install'%module) + modules.button_install( + cr, uid, + modules.search(cr, uid, [('name','=',module)]), + context=context) cr.commit() pooler.restart_pool(cr.dbname, update_module=True) From 43579e17c2d9ad548eadaa069b52853d2204c5e6 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Sun, 10 Jan 2010 19:31:46 +0100 Subject: [PATCH 3/3] [imp] batched modules update in module installer bzr revid: xmo@tinyerp.com-20100110183146-oe6d0k0a977s2hc0 --- bin/addons/base/res/res_config.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/bin/addons/base/res/res_config.py b/bin/addons/base/res/res_config.py index db93e152f3c..204be08c9d0 100644 --- a/bin/addons/base/res/res_config.py +++ b/bin/addons/base/res/res_config.py @@ -142,14 +142,15 @@ class res_config_installer(osv.osv_memory): def execute(self, cr, uid, ids, context=None): modules = self.pool.get('ir.module.module') - for module in self._modules_to_install(cr, uid, ids, context=context): - self.logger.notifyChannel( - 'installer', netsvc.LOG_INFO, - 'Selecting addon "%s" to install'%module) - modules.button_install( - cr, uid, - modules.search(cr, uid, [('name','=',module)]), - context=context) + to_install = list(self._modules_to_install( + cr, uid, ids, context=context)) + self.logger.notifyChannel( + 'installer', netsvc.LOG_INFO, + 'Selecting addons %s to install'%to_install) + modules.state_update( + cr, uid, + modules.search(cr, uid, [('name','in',to_install)]), + 'to install', ['uninstalled'], context=context) cr.commit() pooler.restart_pool(cr.dbname, update_module=True)