From b25f6a097890a86fb7c7d2632b275f62c0169af9 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 8 Nov 2010 11:08:57 +0100 Subject: [PATCH 1/6] [IMP] base: migrate res_config to logging bzr revid: xmo@openerp.com-20101108100857-jkc1bv57qq45z8ey --- bin/addons/base/res/res_config.py | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/bin/addons/base/res/res_config.py b/bin/addons/base/res/res_config.py index 1b4df76ec1d..a2aa4b84d1c 100644 --- a/bin/addons/base/res/res_config.py +++ b/bin/addons/base/res/res_config.py @@ -18,7 +18,7 @@ # along with this program. If not, see . # ############################################################################## - +import logging from operator import attrgetter from osv import osv, fields @@ -37,6 +37,7 @@ class res_config_configurable(osv.osv_memory): _name = 'res.config' _inherit = 'ir.wizard.screen' logger = netsvc.Logger() + __logger = logging.getLogger(_name) def get_current_progress(self, cr, uid, context=None): '''Return a description the current progress of configuration: @@ -63,8 +64,7 @@ class res_config_configurable(osv.osv_memory): def _next_action(self, cr, uid, context=None): todos = self.pool.get('ir.actions.todo') - self.logger.notifyChannel('actions', netsvc.LOG_INFO, - 'getting next %s' % todos) + self.__logger.info('getting next %s', todos) active_todos = todos.search(cr, uid, [('state','=','open')], limit=1) dont_skip_todo = True @@ -103,11 +103,9 @@ class res_config_configurable(osv.osv_memory): previous_todo.write({'state':state}) def _next(self, cr, uid, context=None): - self.logger.notifyChannel('actions', netsvc.LOG_INFO, - 'getting next operation') + self.__logger.info('getting next operation') next = self._next_action(cr, uid) - self.logger.notifyChannel('actions', netsvc.LOG_INFO, - 'next action is %s' % next) + self.__logger.info('next action is %s', next) if next: action = next.action_id return { @@ -118,9 +116,7 @@ class res_config_configurable(osv.osv_memory): 'type': action.type, 'target': action.target, } - self.logger.notifyChannel( - 'actions', netsvc.LOG_INFO, - 'all configuration actions have been executed') + self.__logger.info('all configuration actions have been executed') current_user_menu = self.pool.get('res.users')\ .browse(cr, uid, uid).menu_id @@ -313,6 +309,7 @@ class res_config_installer(osv.osv_memory): """ _name = 'res.config.installer' _inherit = 'res.config' + __logger = logging.getLogger(_name) _install_if = {} @@ -408,9 +405,7 @@ class res_config_installer(osv.osv_memory): modules = self.pool.get('ir.module.module') 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) + self.__logger.info('Selecting addons %s to install', to_install) modules.state_update( cr, uid, modules.search(cr, uid, [('name','in',to_install)]), @@ -432,6 +427,7 @@ class ir_actions_configuration_wizard(osv.osv_memory): ''' _name='ir.actions.configuration.wizard' _inherit = 'res.config' + __logger = logging.getLogger(_name) def _next_action_note(self, cr, uid, ids, context=None): next = self._next_action(cr, uid) @@ -451,8 +447,7 @@ class ir_actions_configuration_wizard(osv.osv_memory): } def execute(self, cr, uid, ids, context=None): - self.logger.notifyChannel( - 'configuration', netsvc.LOG_WARNING, DEPRECATION_MESSAGE) + self.__logger.warn(DEPRECATION_MESSAGE) ir_actions_configuration_wizard() From d1ad030ba6f9b521c5262ff1462a0b6af9171fdb Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 8 Nov 2010 11:17:20 +0100 Subject: [PATCH 2/6] [IMP] base: remove useless context-setting bzr revid: xmo@openerp.com-20101108101720-7wjqznxd5l2ejwq8 --- bin/addons/base/res/res_config.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/bin/addons/base/res/res_config.py b/bin/addons/base/res/res_config.py index a2aa4b84d1c..58944a6884e 100644 --- a/bin/addons/base/res/res_config.py +++ b/bin/addons/base/res/res_config.py @@ -90,8 +90,6 @@ class res_config_configurable(osv.osv_memory): `ValueError`: if no state is provided anything ir_actions_todo.write can throw """ - if context is None: - context = {} # this is ultra brittle, but apart from storing the todo id # into the res.config view, I'm not sure how to get the # "previous" todo From bde7060598105f2db6b1a4729a0f283af2b43600 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 8 Nov 2010 11:41:28 +0100 Subject: [PATCH 3/6] [IMP] res_config: better scope dont_skip_todo bzr revid: xmo@openerp.com-20101108104128-bew5ri7jpxbydp34 --- bin/addons/base/res/res_config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/addons/base/res/res_config.py b/bin/addons/base/res/res_config.py index 58944a6884e..f4aee874839 100644 --- a/bin/addons/base/res/res_config.py +++ b/bin/addons/base/res/res_config.py @@ -67,10 +67,10 @@ class res_config_configurable(osv.osv_memory): self.__logger.info('getting next %s', todos) active_todos = todos.search(cr, uid, [('state','=','open')], limit=1) - dont_skip_todo = True if active_todos: todo_obj = todos.browse(cr, uid, active_todos[0], context=None) todo_groups = map(lambda x:x.id, todo_obj.groups_id) + dont_skip_todo = True if todo_groups: cr.execute("select 1 from res_groups_users_rel where uid=%s and gid IN %s",(uid, tuple(todo_groups),)) dont_skip_todo = bool(cr.fetchone()) From 89af2f0c8e1fe2b8154dbae862c824ad285d3663 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 8 Nov 2010 11:44:12 +0100 Subject: [PATCH 4/6] [FIX] Do not raise an error if the next todo isn't found to set the previous todo's status The previous line hardly makes any sense, so clarification: finding the 'next' todo is based on todo states, so until we've set the state of the todo item we've just executed (aka the previous todo) it remains the 'next' todo as well. So in order to set the previous todo's state, we look for the next todo (which it still is) and set its state, actually marking it as the 'previous' todo bzr revid: xmo@openerp.com-20101108104412-bd7bf3k7c5p5jkpl --- bin/addons/base/res/res_config.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/addons/base/res/res_config.py b/bin/addons/base/res/res_config.py index f4aee874839..b5956b14a4e 100644 --- a/bin/addons/base/res/res_config.py +++ b/bin/addons/base/res/res_config.py @@ -95,7 +95,8 @@ class res_config_configurable(osv.osv_memory): # "previous" todo previous_todo = self._next_action(cr, uid, context=context) if not previous_todo: - raise LookupError(_("Couldn't find previous ir.actions.todo")) + self.__logger.warn(_("Couldn't find previous ir.actions.todo")) + return if not state: raise ValueError(_("Can't set an ir.actions.todo's state to an empty value.")) previous_todo.write({'state':state}) From bf35164a656771d433912c2d7d2f25e68d381306 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 8 Nov 2010 11:47:18 +0100 Subject: [PATCH 5/6] [REM] pre-check that we're not setting ir_actions_todo.state to nothing: it's a selection field, so the write call can check that itself bzr revid: xmo@openerp.com-20101108104718-md2wdklz5rc92ef5 --- bin/addons/base/res/res_config.py | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/bin/addons/base/res/res_config.py b/bin/addons/base/res/res_config.py index b5956b14a4e..eefef533fb2 100644 --- a/bin/addons/base/res/res_config.py +++ b/bin/addons/base/res/res_config.py @@ -97,8 +97,6 @@ class res_config_configurable(osv.osv_memory): if not previous_todo: self.__logger.warn(_("Couldn't find previous ir.actions.todo")) return - if not state: - raise ValueError(_("Can't set an ir.actions.todo's state to an empty value.")) previous_todo.write({'state':state}) def _next(self, cr, uid, context=None): @@ -169,10 +167,7 @@ class res_config_configurable(osv.osv_memory): an action dictionary -- executes the action provided by calling ``next``. """ - try: - self._set_previous_todo(cr, uid, state='done', context=context) - except Exception, e: - raise osv.except_osv(_('Error'), e.message) + self._set_previous_todo(cr, uid, state='done', context=context) next = self.execute(cr, uid, ids, context=None) if next: return next return self.next(cr, uid, ids, context=context) @@ -185,10 +180,7 @@ class res_config_configurable(osv.osv_memory): an action dictionary -- executes the action provided by calling ``next``. """ - try: - self._set_previous_todo(cr, uid, state='skip', context=context) - except Exception, e: - raise osv.except_osv(_('Error'), e.message) + self._set_previous_todo(cr, uid, state='skip', context=context) next = self.cancel(cr, uid, ids, context=None) if next: return next return self.next(cr, uid, ids, context=context) @@ -204,10 +196,7 @@ class res_config_configurable(osv.osv_memory): an action dictionary -- executes the action provided by calling ``next``. """ - try: - self._set_previous_todo(cr, uid, state='cancel', context=context) - except Exception, e: - raise osv.except_osv(_('Error'), e.message) + self._set_previous_todo(cr, uid, state='cancel', context=context) next = self.cancel(cr, uid, ids, context=None) if next: return next return self.next(cr, uid, ids, context=context) From 31346d6259e4e605f7abaa2b438a2c1fabbcc982 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 8 Nov 2010 12:01:59 +0100 Subject: [PATCH 6/6] [FIX] documentation of _set_previous_todo: doesn't inherently throw anything anymore bzr revid: xmo@openerp.com-20101108110159-ptfhu5krjs4y0ald --- bin/addons/base/res/res_config.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/bin/addons/base/res/res_config.py b/bin/addons/base/res/res_config.py index eefef533fb2..5b3b0755f96 100644 --- a/bin/addons/base/res/res_config.py +++ b/bin/addons/base/res/res_config.py @@ -84,11 +84,6 @@ class res_config_configurable(osv.osv_memory): def _set_previous_todo(self, cr, uid, state, context=None): """ lookup the previous (which is still the next at this point) ir.actions.todo, set it to whatever state was provided. - - Raises - `LookupError`: if we couldn't find *any* previous todo - `ValueError`: if no state is provided - anything ir_actions_todo.write can throw """ # this is ultra brittle, but apart from storing the todo id # into the res.config view, I'm not sure how to get the