diff --git a/addons/base_module_quality/base_module_quality.py b/addons/base_module_quality/base_module_quality.py index ab46c3b44be..2a49f301b87 100644 --- a/addons/base_module_quality/base_module_quality.py +++ b/addons/base_module_quality/base_module_quality.py @@ -23,5 +23,31 @@ import netsvc from osv import fields, osv +class quality_check(object): + ''' + This Class provide... + ''' + + _score = 0.0 + _result = "" + _result_details = "" + + def __init__(self, module_path=""): + ''' + this method should do the test and fill the _score, _result and _result_details var + ''' + raise 'Not Implemented' + + #~ def __get_result__(self, cr, uid, module_ids): + #~ ''' + #~ ''' + #~ return _result + + #~ def __get_detailed_result__(self, cr, uid, module_ids): + #~ ''' + #~ ''' + #~ return _result_details + + # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/base_module_quality/pylint_test/__init__.py b/addons/base_module_quality/pylint_test/__init__.py new file mode 100644 index 00000000000..00dce4b7e0b --- /dev/null +++ b/addons/base_module_quality/pylint_test/__init__.py @@ -0,0 +1,26 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2008 Tiny SPRL (). All Rights Reserved +# $Id$ +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +############################################################################## + +import pylint_test + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: + diff --git a/addons/base_module_quality/pylint_test/pylint_test.py b/addons/base_module_quality/pylint_test/pylint_test.py new file mode 100644 index 00000000000..1402c211923 --- /dev/null +++ b/addons/base_module_quality/pylint_test/pylint_test.py @@ -0,0 +1,100 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2008 Tiny SPRL (). All Rights Reserved +# $Id$ +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +############################################################################## + +import netsvc +from osv import fields, osv +import os + +#~ class _test_pylint(quality_check): + + #~ def __init__(self, url, add_folder=None): + #~ print "dans le test" + #~ list_files = os.listdir(url) + #~ new_list = [] + #~ subfolder = {} + #~ for i in list_files: + #~ if os.path.isdir(i): + #~ path = os.path.join(url, i) + #~ new_list.append(os.listdir(path)) + #~ res = _test_pylint(self, path, add_folder=i) + #~ subfolder.update(res) + #~ dict_files = {} + #~ for file in list_files: + #~ if file.split('.')[-1] == 'py' and not file.startswith('__init__'): + #~ file_path = os.path.join(url, file) + #~ res = os.popen('pylint '+file_path+' | tail -4').read() + #~ if res.startswith('Global'): + #~ if add_folder: + #~ dict_files[add_folder + '/' + file] = res + #~ else: + #~ dict_files[file] = res + #~ dict_files.update(subfolder) + #~ print "dict_files", dict_files + #~ return dict_files + +class _test_pylint(base_module_quality.quality_check): + + def __init__(self, module_path): + + self._result = """ +Pylint Test: +------------ + + This test checks if the module satisfy the current coding standard used by OpenERP. + + +""" + list_files = os.listdir(module_path) + new_list = [] + subfolder = {} + for i in list_files: + path = os.path.join(module_path, i) + if os.path.isdir(path): + for j in os.listdir(path): + list_files.append(os.path.join(i, j)) + + dict_files = {} + n =0 + score = 0.0 + print list_files + for file in list_files: + if file.split('.')[-1] == 'py' and not file.endswith('__init__.py') and not file.endswith('__terp__.py'): +#--rcfile= Specify a configuration file. + file_path = os.path.join(module_path, file) + res = os.popen('pylint --persistent=n '+file_path).read() + n += 1 + leftchar = -1 + while res[leftchar:leftchar+1] != ' ' and leftchar-1 <= 0: + leftchar -=1 + rightchar = -10 + while res[rightchar:rightchar+1] != '/' and rightchar+1 <= 0: + rightchar +=1 + + score += float(res[leftchar+1:rightchar]) + self._result_details += res + self._result += file+": "+ res[leftchar+1:rightchar]+"/10\n" + self._score = score / n + return None + + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: + diff --git a/addons/base_module_quality/wizard/module_quality_check.py b/addons/base_module_quality/wizard/module_quality_check.py index de3f333338a..41d7aed7e1c 100644 --- a/addons/base_module_quality/wizard/module_quality_check.py +++ b/addons/base_module_quality/wizard/module_quality_check.py @@ -28,6 +28,7 @@ import sys import tools import os import pylint +import base_module_quality form_check = '''
@@ -41,30 +42,65 @@ fields_check = { 'default': lambda *args: 'pylint' }, } + view_form = """ - + + + + + """ +#TODO: utiliser les nouveaux wizards pour heriter la vue et rajouter un onglet par test? +#TODO: remove the first screen which is unused view_field = { - "module_info": {'type': 'text', 'string': 'check quality', 'readonly':True}, + "general_info": {'type': 'text', 'string': 'General Info', 'readonly':True}, } + + + class wiz_quality_check(wizard.interface): - def _check(self, cr, uid, data, context): - if data['form']['test'] == 'pylint': - pool=pooler.get_pool(cr.dbname) - module_data = pool.get('ir.module.module').browse(cr, uid, data['ids']) - from pylint_test import pylint_test - ad = tools.config['addons_path'] - url = os.path.join(ad, module_data[0].name) - result = pylint_test._test_pylint(self, url) - string_ret = '' - for i in result: - string_ret = string_ret + i + ':\n' + result[i] - return {'module_info':string_ret} + def _check(self, cr, uid, data, context): + string_ret = "" + from tools import config + list_folders=os.listdir(config['addons_path']+'/base_module_quality/') + for item in list_folders: + path = config['addons_path']+'/base_module_quality/wizard/'+item + if os.path.exists(path+'/'+item+'.py') and item not in ['report','wizard', 'security']: + pool=pooler.get_pool(cr.dbname) + module_data = pool.get('ir.module.module').browse(cr, uid, data['ids']) + + ad = tools.config['addons_path'] + module_path = os.path.join(ad, module_data[0].name) + #import pylint_test + x = __import__(item) + val = x.__init__(module_path) + string_ret += val._result + + return {'general_info':string_ret} + + + #mra version + #~ result = pylint_test._test_pylint(self, url) + #~ string_ret = '' + #~ for i in result: + #~ string_ret = string_ret + i + ':\n' + result[i] + #~ string_ret = "" + #~ if data['form']['test'] == 'pylint': + #~ pool=pooler.get_pool(cr.dbname) + #~ module_data = pool.get('ir.module.module').browse(cr, uid, data['ids']) + #~ from pylint_test import pylint_test + #~ ad = tools.config['addons_path'] + #~ url = os.path.join(ad, module_data[0].name) + #~ result = pylint_test._test_pylint(self, url) + #~ string_ret = '' + #~ for i in result: + #~ string_ret = string_ret + i + ':\n' + result[i] + states = { 'init': { 'actions': [], diff --git a/addons/base_module_quality/wizard/pylint_test/pylint_test.py b/addons/base_module_quality/wizard/pylint_test/pylint_test.py index a640e37e96c..6e80e136865 100644 --- a/addons/base_module_quality/wizard/pylint_test/pylint_test.py +++ b/addons/base_module_quality/wizard/pylint_test/pylint_test.py @@ -24,28 +24,60 @@ import netsvc from osv import fields, osv import os -def _test_pylint(self, url, add_folder=None): - list_files = os.listdir(url) - new_list = [] - subfolder = {} - for i in list_files: - if os.path.isdir(i): - path = os.path.join(url, i) - new_list.append(os.listdir(path)) - res = _test_pylint(self, path, add_folder=i) - subfolder.update(res) - dict_files = {} - for file in list_files: - if file.split('.')[-1] == 'py' and not file.startswith('__init__'): - file_path = os.path.join(url, file) - res = os.popen('pylint '+file_path+' | tail -4').read() - if res.startswith('Global'): - if add_folder: - dict_files[add_folder + '/' + file] = res - else: - dict_files[file] = res - dict_files.update(subfolder) - return dict_files + + +class _test_pylint(quality_check): + + def __init__(self, url, add_folder=None): + print "dans le test" + list_files = os.listdir(url) + new_list = [] + subfolder = {} + for i in list_files: + if os.path.isdir(i): + path = os.path.join(url, i) + new_list.append(os.listdir(path)) + res = _test_pylint(self, path, add_folder=i) + subfolder.update(res) + dict_files = {} + for file in list_files: + if file.split('.')[-1] == 'py' and not file.startswith('__init__'): + file_path = os.path.join(url, file) + res = os.popen('pylint '+file_path+' | tail -4').read() + if res.startswith('Global'): + if add_folder: + dict_files[add_folder + '/' + file] = res + else: + dict_files[file] = res + dict_files.update(subfolder) + print "dict_files", dict_files + return dict_files + +_test_pylint() + + +#~ def _test_pylint(self, url, add_folder=None): + #~ list_files = os.listdir(url) + #~ new_list = [] + #~ subfolder = {} + #~ for i in list_files: + #~ if os.path.isdir(i): + #~ path = os.path.join(url, i) + #~ new_list.append(os.listdir(path)) + #~ res = _test_pylint(self, path, add_folder=i) + #~ subfolder.update(res) + #~ dict_files = {} + #~ for file in list_files: + #~ if file.split('.')[-1] == 'py' and not file.startswith('__init__'): + #~ file_path = os.path.join(url, file) + #~ res = os.popen('pylint '+file_path+' | tail -4').read() + #~ if res.startswith('Global'): + #~ if add_folder: + #~ dict_files[add_folder + '/' + file] = res + #~ else: + #~ dict_files[file] = res + #~ dict_files.update(subfolder) + #~ return dict_files # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: