diff options
Diffstat (limited to 'addons/base_module_quality/base_module_quality.py')
| -rw-r--r-- | addons/base_module_quality/base_module_quality.py | 50 |
1 files changed, 31 insertions, 19 deletions
diff --git a/addons/base_module_quality/base_module_quality.py b/addons/base_module_quality/base_module_quality.py index d6d67d448c8..d7ac2f77700 100644 --- a/addons/base_module_quality/base_module_quality.py +++ b/addons/base_module_quality/base_module_quality.py @@ -21,12 +21,10 @@ import os import pooler -import osv -import tools -from tools import config from tools.translate import _ from osv import osv, fields - +import logging +import addons class abstract_quality_check(object): ''' This Class is abstract class for all test @@ -80,22 +78,20 @@ class abstract_quality_check(object): #This variable used to give message if test result is good or not self.message = '' + self.log = logging.getLogger('module.quality') #The tests have to subscribe itselfs in this list, that contains #all the test that have to be performed. self.tests = [] - self.list_folders = os.listdir(config['addons_path'] + - '/base_module_quality/') - for item in self.list_folders: - self.item = item - path = config['addons_path']+'/base_module_quality/'+item - if os.path.exists(path + '/' + item + '.py') and item not in ['report', 'wizard', 'security']: + module_path = addons.get_module_path('base_module_quality') + for item in os.listdir(module_path): + path = module_path + '/' + item + if os.path.isdir(path) and os.path.exists(path + '/' + item + '.py') and item not in ['report', 'wizard', 'security']: item2 = 'base_module_quality.' + item +'.' + item x_module = __import__(item2) x_file = getattr(x_module, item) x_obj = getattr(x_file, item) self.tests.append(x_obj) -# raise 'Not Implemented' def run_test(self, cr, uid, module_path=""): ''' @@ -112,9 +108,11 @@ class abstract_quality_check(object): model_data = pool.get('ir.model.data').browse(cr, uid, ids2) for model in model_data: model_list.append(model.res_id) + self.log.debug('get_objects() model_list: %s', ','.join(map(str, model_list))) obj_list = [] for mod in pool.get('ir.model').browse(cr, uid, model_list): obj_list.append(str(mod.model)) + self.log.debug('get_objects() obj_list: %s', ','.join(obj_list)) return obj_list def get_model_ids(self, cr, uid, models=[]): @@ -122,6 +120,7 @@ class abstract_quality_check(object): if not models: return [] pool = pooler.get_pool(cr.dbname) + self.log.debug('get_model_ids([%s])', ', '.join(models)) return pool.get('ir.model').search(cr, uid, [('model', 'in', models)]) def get_ids(self, cr, uid, object_list): @@ -211,8 +210,8 @@ class module_quality_check(osv.osv): ..........]} So here the detail result is in html format and summary will be in text_wiki format. ''' - #list_folders = os.listdir(config['addons_path']+'/base_module_quality/') pool = pooler.get_pool(cr.dbname) + log = logging.getLogger('module.quality') obj_module = pool.get('ir.module.module') if not module_state: module_id = obj_module.search(cr, uid, [('name', '=', module_name)]) @@ -223,15 +222,22 @@ class module_quality_check(osv.osv): score_sum = 0.0 ponderation_sum = 0.0 create_ids = [] + module_path = addons.get_module_path(module_name) + log.info('Performing quality tests for %s', module_name) for test in abstract_obj.tests: - ad = tools.config['addons_path'] - if module_name == 'base': - ad = tools.config['root_path']+'/addons' - module_path = os.path.join(ad, module_name) val = test.quality_test() - if val.active: + if not val.active: + log.info('Skipping inactive step %s for %s', val.name, module_name) + continue + + log.info('Performing step %s for %s', val.name, module_name) + # Get a separate cursor per test, so that an SQL error in one + # will not block the others. + cr2 = pooler.get_db(cr.dbname).cursor() + + try: if not val.bool_installed_only or module_state == "installed": - val.run_test(cr, uid, str(module_path)) + val.run_test(cr2, uid, str(module_path)) if not val.error: data = { 'name': val.name, @@ -263,6 +269,12 @@ class module_quality_check(osv.osv): 'summary': _("The module has to be installed before running this test.") } create_ids.append((0, 0, data)) + log.info('Finished quality test step') + except Exception, e: + log.exception("Could not finish test step %s due to %s", val.name, e) + finally: + cr2.rollback() + cr2.close() final_score = ponderation_sum and '%.2f' % (score_sum / ponderation_sum * 100) or 0 data = { 'name': module_name, @@ -289,4 +301,4 @@ class module_quality_detail(osv.osv): module_quality_detail() -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
\ No newline at end of file +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: |
