quality module
[odoo/odoo.git] / addons / base_module_quality / base_module_quality.py
1 # -*- encoding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
6 #    $Id$
7 #
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.
12 #
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.
17 #
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/>.
20 #
21 ##############################################################################
22 import pooler
23 import os
24 from tools import config
25
26 class abstract_quality_check(object):
27     '''
28         This Class provide...
29     '''
30
31 #    #This float have to store the rating of the module.
32 #    #Used to compute the final score (average of all scores).
33 #    score = 0.0
34 #
35 #    #This char have to store the result.
36 #    #Used to display the result of the test.
37 #    result = ""
38 #
39 #    #This char have to store the result with more details.
40 #    #Used to provide more details if necessary.
41 #    result_details = ""
42 #
43 #    #This bool defines if the test can be run only if the module is installed.
44 #    #True => the module have to be installed.
45 #    #False => the module can be uninstalled.
46 #    bool_installed_only = True
47
48     def __init__(self):
49         '''
50         this method should initialize the var
51         '''
52         #This float have to store the rating of the module.
53         #Used to compute the final score (average of all scores).
54         self.score = 0.0
55
56         #This char have to store the result.
57         #Used to display the result of the test.
58         self.result = ""
59
60         #This char have to store the result with more details.
61         #Used to provide more details if necessary.
62         self.result_details = ""
63
64         #This bool defines if the test can be run only if the module is installed.
65         #True => the module have to be installed.
66         #False => the module can be uninstalled.
67         self.bool_installed_only = True
68
69
70         #This variable is use to make result of test should have more weight (Some tests are more critical than others)
71         self.ponderation = 0.0
72
73         #Specify test got an error on module
74         self.error = False
75
76         self.tests = []
77         self.list_folders = os.listdir(config['addons_path']+'/base_module_quality/')
78         for item in self.list_folders:
79             self.item = item
80             path = config['addons_path']+'/base_module_quality/'+item
81             if os.path.exists(path+'/'+item+'.py') and item not in ['report', 'wizard', 'security']:
82                 item2 = 'base_module_quality.' + item +'.' + item
83                 x = __import__(item2)
84                 x2 = getattr(x, item)
85                 x3 = getattr(x2, item)
86                 self.tests.append(x3)
87 #        raise 'Not Implemented'
88
89     def run_test(self, cr, uid, module_path="", module_state=""):
90         '''
91         this method should do the test and fill the score, result and result_details var
92         '''
93 #        raise 'Not Implemented'
94
95     def get_objects(self, cr, uid, module):
96         # This function returns all object of the given module..
97         pool = pooler.get_pool(cr.dbname)
98         ids2 = pool.get('ir.model.data').search(cr, uid, [('module','=', module), ('model','=','ir.model')])
99         model_list = []
100         model_data = pool.get('ir.model.data').browse(cr, uid, ids2)
101         for model in model_data:
102             model_list.append(model.res_id)
103         obj_list = []
104         for mod in pool.get('ir.model').browse(cr, uid, model_list):
105             obj_list.append(str(mod.model))
106         return obj_list
107
108     def get_ids(self, cr, uid, object_list):
109         #This method return dictionary with ids of records of object for module
110         pool = pooler.get_pool(cr.dbname)
111         result_ids = {}
112         for obj in object_list:
113             ids = pool.get(obj).search(cr, uid, [])
114             result_ids[obj] = ids
115         return result_ids
116
117     def format_table(self, test='', header=[], data_list=[]):
118         res_format = {}
119         if test=='method':
120             detail = ""
121             detail += "\n===Method Test===\n"
122             res_format['detail'] = detail
123             if not data_list[2]:
124                 detail += ('{| border="1" cellspacing="0" cellpadding="5" align="left" \n! %-40s \n! %-16s \n! %-20s \n! %-16s ') % (header[0].ljust(40), header[1].ljust(16), header[2].ljust(20), header[3].ljust(16))
125                 for res in data_list[1]:
126                     detail += ('\n|-\n| %s \n| %s \n| %s \n| %s ') % (res, data_list[1][res][0], data_list[1][res][1], data_list[1][res][2])
127                 res_format['detail'] = detail + '\n|}'
128             res_format['summary'] = data_list[0]
129         elif test=='pylint':
130             res_format['summary'] = data_list[0]
131             res_format['detail'] = data_list[1]
132         elif test=='speed':
133             detail = ""
134             detail += "\n===Speed Test===\n"
135             res_format['detail'] = detail
136             if not data_list[2]:
137                 detail += ('{| border="1" cellspacing="0" cellpadding="5" align="left" \n! %-40s \n! %-10s \n! %-10s \n! %-10s \n! %-10s \n! %-20s') % (header[0].ljust(40), header[1].ljust(10), header[2].ljust(10), header[3].ljust(10), header[4].ljust(10), header[5].ljust(20))
138                 for data in data_list[1]:
139                     detail +=  ('\n|-\n| %s \n| %s \n| %s \n| %s \n| %s \n| %s ') % (data[0], data[1], data[2], data[3], data[4], data[5])
140                     res_format['detail'] = detail  + '\n|}\n'
141             res_format['summary'] = data_list[0]
142         elif test=='terp':
143             res_format['summary'] = data_list[0]
144             res_format['detail'] = data_list[1]
145         return res_format
146
147     def add_quatation(self, x, y):
148         return x/y
149
150
151
152 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
153