From 2d251ea98769d36e57c82fee43846cf891f74808 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 19 Mar 2013 16:34:22 +0100 Subject: [PATCH 1/6] [REM] unused openerp.workflow.common bzr revid: xmo@openerp.com-20130319153422-0s7sly0cjg491s0b --- openerp/workflow/common.py | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 openerp/workflow/common.py diff --git a/openerp/workflow/common.py b/openerp/workflow/common.py deleted file mode 100644 index fc29419721a..00000000000 --- a/openerp/workflow/common.py +++ /dev/null @@ -1,28 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# Copyright (C) 2004-2009 Tiny SPRL (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## - -class except_wkf(Exception): - def __init__(self, name, value): - self.name = name - self.value = value - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: - From 5f956523d4ea67e2552c6b72e6aff3fe10bea6d3 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 19 Mar 2013 16:48:57 +0100 Subject: [PATCH 2/6] [IMP] flow of workflow.workitem.process bzr revid: xmo@openerp.com-20130319154857-q7l99vyqtksegiy0 --- openerp/workflow/workitem.py | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/openerp/workflow/workitem.py b/openerp/workflow/workitem.py index 0f94dfa788d..06ba3672371 100644 --- a/openerp/workflow/workitem.py +++ b/openerp/workflow/workitem.py @@ -40,30 +40,26 @@ def create(cr, act_datas, inst_id, ident, stack): process(cr, res, ident, stack=stack) def process(cr, workitem, ident, signal=None, force_running=False, stack=None): - if stack is None: - raise 'Error !!!' - result = True + assert stack is not None cr.execute('select * from wkf_activity where id=%s', (workitem['act_id'],)) activity = cr.dictfetchone() + if workitem['state'] == 'running': + return True + triggers = False - if workitem['state']=='active': + if workitem['state'] == 'active': triggers = True - result = _execute(cr, workitem, activity, ident, stack) - if not result: + if not _execute(cr, workitem, activity, ident, stack): return False - if workitem['state']=='running': - pass - - if workitem['state']=='complete' or force_running: + if force_running or workitem['state'] == 'complete': ok = _split_test(cr, workitem, activity['split_mode'], ident, signal, stack) triggers = triggers and not ok if triggers: cr.execute('select * from wkf_transition where act_from=%s', (workitem['act_id'],)) - alltrans = cr.dictfetchall() - for trans in alltrans: + for trans in cr.dictfetchall(): if trans['trigger_model']: ids = wkf_expr._eval_expr(cr,ident,workitem,trans['trigger_expr_id']) for res_id in ids: @@ -71,7 +67,7 @@ def process(cr, workitem, ident, signal=None, force_running=False, stack=None): id =cr.fetchone()[0] cr.execute('insert into wkf_triggers (model,res_id,instance_id,workitem_id,id) values (%s,%s,%s,%s,%s)', (trans['trigger_model'],res_id,workitem['inst_id'], workitem['id'], id)) - return result + return True # ---------------------- PRIVATE FUNCS -------------------------------- @@ -146,8 +142,6 @@ def _execute(cr, workitem, activity, ident, stack): return result def _split_test(cr, workitem, split_mode, ident, signal=None, stack=None): - if stack is None: - raise 'Error !!!' cr.execute('select * from wkf_transition where act_from=%s', (workitem['act_id'],)) test = False transitions = [] From db6b6480f7bf034ef180f382de27dc4f27a3c42e Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 19 Mar 2013 17:31:33 +0100 Subject: [PATCH 3/6] [IMP] switch workflows to standard logging (silenced by default), remove wkf_logs bzr revid: xmo@openerp.com-20130319163133-3n1k1hgooddzxntz --- openerp/netsvc.py | 1 + openerp/workflow/wkf_logs.py | 39 ------------------------------------ openerp/workflow/workitem.py | 10 ++++++--- 3 files changed, 8 insertions(+), 42 deletions(-) delete mode 100644 openerp/workflow/wkf_logs.py diff --git a/openerp/netsvc.py b/openerp/netsvc.py index ef72ba179f2..ffbd38de36a 100644 --- a/openerp/netsvc.py +++ b/openerp/netsvc.py @@ -131,6 +131,7 @@ def init_logger(): # Configure handlers default_config = [ + 'openerp.workflow.workitem:WARNING', 'openerp.netsvc.rpc.request:INFO', 'openerp.netsvc.rpc.response:INFO', 'openerp.addons.web.http:INFO', diff --git a/openerp/workflow/wkf_logs.py b/openerp/workflow/wkf_logs.py deleted file mode 100644 index 9463fe61814..00000000000 --- a/openerp/workflow/wkf_logs.py +++ /dev/null @@ -1,39 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# Copyright (C) 2004-2009 Tiny SPRL (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## - -# -# May be uncommented to logs workflows modifications -# - -def log(cr,ident,act_id,info=''): - return - # msg = """ - #res_type: %r - #res_id: %d - #uid: %d - #act_id: %d - #info: %s - #""" % (ident[1], ident[2], ident[0], act_id, info) - - #cr.execute('insert into wkf_logs (res_type, res_id, uid, act_id, time, info) values (%s,%s,%s,%s,current_time,%s)', (ident[1],int(ident[2]),int(ident[0]),int(act_id),info)) - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: - diff --git a/openerp/workflow/workitem.py b/openerp/workflow/workitem.py index 06ba3672371..88a786e6c67 100644 --- a/openerp/workflow/workitem.py +++ b/openerp/workflow/workitem.py @@ -23,11 +23,13 @@ # TODO: # cr.execute('delete from wkf_triggers where model=%s and res_id=%s', (res_type,res_id)) # +import logging import instance import wkf_expr -import wkf_logs + +logger = logging.getLogger(__name__) def create(cr, act_datas, inst_id, ident, stack): for act in act_datas: @@ -36,7 +38,8 @@ def create(cr, act_datas, inst_id, ident, stack): cr.execute("insert into wkf_workitem (id,act_id,inst_id,state) values (%s,%s,%s,'active')", (id_new, act['id'], inst_id)) cr.execute('select * from wkf_workitem where id=%s',(id_new,)) res = cr.dictfetchone() - wkf_logs.log(cr,ident,act['id'],'active') + logger.info('Created workflow item in activity %s', + act['id'], extra={'ident': ident}) process(cr, res, ident, stack=stack) def process(cr, workitem, ident, signal=None, force_running=False, stack=None): @@ -75,7 +78,8 @@ def process(cr, workitem, ident, signal=None, force_running=False, stack=None): def _state_set(cr, workitem, activity, state, ident): cr.execute('update wkf_workitem set state=%s where id=%s', (state,workitem['id'])) workitem['state'] = state - wkf_logs.log(cr,ident,activity['id'],state) + logger.info("Changed state of work item %s to \"%s\" in activity %s", + workitem['id'], state, activity['id'], extra={'ident': ident}) def _execute(cr, workitem, activity, ident, stack): result = True From 7c2b70eb46707aec46472ebf91bd9bf7ce957155 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 19 Mar 2013 17:36:06 +0100 Subject: [PATCH 4/6] [IMP] declaratively map openerp logging levels to logging, move default logging conf to 'constant' bzr revid: xmo@openerp.com-20130319163606-un9ogalwfk3eykc8 --- openerp/netsvc.py | 54 ++++++++++++++++++++--------------------------- 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/openerp/netsvc.py b/openerp/netsvc.py index ffbd38de36a..e833bcc60e4 100644 --- a/openerp/netsvc.py +++ b/openerp/netsvc.py @@ -130,39 +130,11 @@ def init_logger(): handler.setFormatter(formatter) # Configure handlers - default_config = [ - 'openerp.workflow.workitem:WARNING', - 'openerp.netsvc.rpc.request:INFO', - 'openerp.netsvc.rpc.response:INFO', - 'openerp.addons.web.http:INFO', - 'openerp.sql_db:INFO', - ':INFO', - ] - - if tools.config['log_level'] == 'info': - pseudo_config = [] - elif tools.config['log_level'] == 'debug_rpc': - pseudo_config = ['openerp:DEBUG','openerp.netsvc.rpc.request:DEBUG'] - elif tools.config['log_level'] == 'debug_rpc_answer': - pseudo_config = ['openerp:DEBUG','openerp.netsvc.rpc.request:DEBUG', 'openerp.netsvc.rpc.response:DEBUG'] - elif tools.config['log_level'] == 'debug': - pseudo_config = ['openerp:DEBUG'] - elif tools.config['log_level'] == 'test': - pseudo_config = ['openerp:TEST'] - elif tools.config['log_level'] == 'warn': - pseudo_config = ['openerp:WARNING'] - elif tools.config['log_level'] == 'error': - pseudo_config = ['openerp:ERROR'] - elif tools.config['log_level'] == 'critical': - pseudo_config = ['openerp:CRITICAL'] - elif tools.config['log_level'] == 'debug_sql': - pseudo_config = ['openerp.sql_db:DEBUG'] - else: - pseudo_config = [] + pseudo_config = PSEUDOCONFIG_MAPPER.get(tools.config['log_level'], []) logconfig = tools.config['log_handler'] - for logconfig_item in default_config + pseudo_config + logconfig: + for logconfig_item in DEFAULT_LOG_CONFIGURATION + pseudo_config + logconfig: loggername, level = logconfig_item.split(':') level = getattr(logging, level, logging.INFO) logger = logging.getLogger(loggername) @@ -172,9 +144,29 @@ def init_logger(): if loggername != '': logger.propagate = False - for logconfig_item in default_config + pseudo_config + logconfig: + for logconfig_item in DEFAULT_LOG_CONFIGURATION + pseudo_config + logconfig: _logger.debug('logger level set: "%s"', logconfig_item) +DEFAULT_LOG_CONFIGURATION = [ + 'openerp.workflow.workitem:WARNING', + 'openerp.netsvc.rpc.request:INFO', + 'openerp.netsvc.rpc.response:INFO', + 'openerp.addons.web.http:INFO', + 'openerp.sql_db:INFO', + ':INFO', +] +PSEUDOCONFIG_MAPPER = { + 'debug_rpc_answer': ['openerp:DEBUG','openerp.netsvc.rpc.request:DEBUG', 'openerp.netsvc.rpc.response:DEBUG'], + 'debug_rpc': ['openerp:DEBUG','openerp.netsvc.rpc.request:DEBUG'], + 'debug': ['openerp:DEBUG'], + 'debug_sql': ['openerp.sql_db:DEBUG'], + 'test': ['openerp:TEST'], + 'info': [], + 'warn': ['openerp:WARNING'], + 'error': ['openerp:ERROR'], + 'critical': ['openerp:CRITICAL'], +} + # A alternative logging scheme for automated runs of the # server intended to test it. def init_alternative_logger(): From 9476f0795472a3b7ce8f99be17acf3f2065d3435 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 19 Mar 2013 17:37:08 +0100 Subject: [PATCH 5/6] [IMP] only concatenate logging configuration subsequences once bzr revid: xmo@openerp.com-20130319163708-s4mxsdg3f9xksr07 --- openerp/netsvc.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/openerp/netsvc.py b/openerp/netsvc.py index e833bcc60e4..6b66830b75e 100644 --- a/openerp/netsvc.py +++ b/openerp/netsvc.py @@ -134,7 +134,8 @@ def init_logger(): logconfig = tools.config['log_handler'] - for logconfig_item in DEFAULT_LOG_CONFIGURATION + pseudo_config + logconfig: + logging_configurations = DEFAULT_LOG_CONFIGURATION + pseudo_config + logconfig + for logconfig_item in logging_configurations: loggername, level = logconfig_item.split(':') level = getattr(logging, level, logging.INFO) logger = logging.getLogger(loggername) @@ -144,7 +145,7 @@ def init_logger(): if loggername != '': logger.propagate = False - for logconfig_item in DEFAULT_LOG_CONFIGURATION + pseudo_config + logconfig: + for logconfig_item in logging_configurations: _logger.debug('logger level set: "%s"', logconfig_item) DEFAULT_LOG_CONFIGURATION = [ From 5cc71e1bababf7ea1d2bc9d8ccdd33ae8af74711 Mon Sep 17 00:00:00 2001 From: Vo Minh Thu Date: Tue, 26 Mar 2013 15:39:37 +0100 Subject: [PATCH 6/6] [FIX] workitem: the early return in the case workitem.state == running was seemingly wrong as workitem.state is mutated in some other IFs. bzr revid: vmt@openerp.com-20130326143937-lf4mswer4ablj46i --- openerp/workflow/workitem.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/openerp/workflow/workitem.py b/openerp/workflow/workitem.py index 88a786e6c67..a5639fa0c7c 100644 --- a/openerp/workflow/workitem.py +++ b/openerp/workflow/workitem.py @@ -44,12 +44,10 @@ def create(cr, act_datas, inst_id, ident, stack): def process(cr, workitem, ident, signal=None, force_running=False, stack=None): assert stack is not None + cr.execute('select * from wkf_activity where id=%s', (workitem['act_id'],)) activity = cr.dictfetchone() - if workitem['state'] == 'running': - return True - triggers = False if workitem['state'] == 'active': triggers = True