1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ##############################################################################
25 from tools import config
26 from tools.translate import _
28 from base_module_quality import base_module_quality
31 class quality_test(base_module_quality.abstract_quality_check):
34 super(quality_test, self).__init__()
35 self.name = _("Pylint Test")
36 self.note = _("""This test uses Pylint and checks if the module satisfies the coding standard of Python. See http://www.logilab.org/project/name/pylint for further info.\n """)
37 self.bool_installed_only = False
38 self.ponderation = 1.0
40 self.result_details = ""
43 def run_test(self, cr, uid, module_path):
44 config_file_path = config['addons_path']+'/base_module_quality/pylint_test/pylint_test_config.txt'
45 list_files = os.listdir(module_path)
47 path = os.path.join(module_path, i)
48 if os.path.isdir(path):
49 for j in os.listdir(path):
50 list_files.append(os.path.join(i, j))
55 self.result_details += '''<html>
57 <link rel="stylesheet" type="text/css" href="/tg_widgets/openerp/css/wiki.css" media="all">
60 for file in list_files:
61 if file.split('.')[-1] == 'py' and not file.endswith('__init__.py') and not file.endswith('__terp__.py'):
62 file_path = os.path.join(module_path, file)
64 res = os.popen('pylint --rcfile=' + config_file_path + ' ' + file_path).read()
66 self.result += _("Error. Is pylint correctly installed?")+"\n"
70 while res[leftchar:leftchar+1] != ' ' and leftchar-1 <= 0:
73 while res[rightchar:rightchar+1] != '/' and rightchar+1 <= 0:
76 score += float(res[leftchar+1:rightchar])
77 #self.result += file + ": " + res[leftchar+1:rightchar] + "/10\n"
78 dict[file] = [file, res[leftchar+1:rightchar]]
81 #self.result += file + ": "+_("Unable to parse the result. Check the details.")+"\n"
82 dict[file] = [file, _("Unable to parse the result. Check the details.")]
83 self.result_details += res.replace('''<div''', '''<div class="wikiwidget readonlyfield"''')
84 self.result_details += '</body></html>'
85 average_score = n and score / n or score
86 self.score = (max(average_score,0)) / 10
87 self.result = self.get_result(dict)
90 def get_result(self, dict):
91 header = ('{| border="1" cellspacing="0" cellpadding="5" align="left" \n! %-40s \n! %-10s \n', [_('File Name'), _('Result (/10)')])
93 return self.format_table(header, data_list=dict)
96 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: