base module quality
[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
24 class abstract_quality_check(object):
25     '''
26         This Class provide...
27     '''
28
29 #    #This float have to store the rating of the module.
30 #    #Used to compute the final score (average of all scores).
31 #    score = 0.0
32 #
33 #    #This char have to store the result.
34 #    #Used to display the result of the test.
35 #    result = ""
36 #
37 #    #This char have to store the result with more details.
38 #    #Used to provide more details if necessary.
39 #    result_details = ""
40 #
41 #    #This bool defines if the test can be run only if the module is installed.
42 #    #True => the module have to be installed.
43 #    #False => the module can be uninstalled.
44 #    bool_installed_only = True
45
46     def __init__(self):
47         '''
48         this method should initialize the var
49         '''
50         #This float have to store the rating of the module.
51         #Used to compute the final score (average of all scores).
52         self.score = 0.0
53
54         #This char have to store the result.
55         #Used to display the result of the test.
56         self.result = ""
57
58         #This char have to store the result with more details.
59         #Used to provide more details if necessary.
60         self.result_details = ""
61
62         #This bool defines if the test can be run only if the module is installed.
63         #True => the module have to be installed.
64         #False => the module can be uninstalled.
65         self.bool_installed_only = True
66
67 #        raise 'Not Implemented'
68
69     def run_test(self, cr, uid, module_path=""):
70         '''
71         this method should do the test and fill the score, result and result_details var
72         '''
73 #        raise 'Not Implemented'
74
75     def get_objects(self, cr, uid, module):
76         # This function returns all object of the given module..
77         pool = pooler.get_pool(cr.dbname)
78         ids2 = pool.get('ir.model.data').search(cr, uid, [('module','=', module), ('model','=','ir.model')])
79         model_list = []
80         model_data = pool.get('ir.model.data').browse(cr, uid, ids2)
81         for model in model_data:
82             model_list.append(model.res_id)
83         obj_list = []
84         for mod in pool.get('ir.model').browse(cr, uid, model_list):
85             obj_list.append(str(mod.model))
86         return obj_list
87
88     def get_ids(self, cr, uid, object_list):
89         #This method return dictionary with ids of records of object for module
90         pool = pooler.get_pool(cr.dbname)
91         result_ids = {}
92         for obj in object_list:
93             ids = pool.get(obj).search(cr, uid, [])
94             result_ids[obj] = ids
95         return result_ids
96
97     def format_table(self, test='', header=[], data_list=[]):
98         res_format = {}
99         if test=='method':
100             detail = ""
101             detail += "\n===Method Test===\n"
102             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))
103             for res in data_list[1][0]:
104                 detail += ('\n|-\n| %s \n| %s \n| %s \n| %s ') % (res, data_list[1][0][res][0], data_list[1][0][res][1], data_list[1][0][res][2])
105             res_format['summary'] = [data_list[0][0]]
106             res_format['detail'] = [detail + '\n|}']
107         elif test=='pylint':
108             res_format['summary'] = data_list[0]
109             res_format['detail'] = data_list[1]
110         elif test=='speed':
111             detail = ""
112             detail += "\n===Speed Test===\n"
113             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))
114             for data in data_list[1]:
115                 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])
116             res_format['summary'] = data_list[0]
117             res_format['detail'] = [detail  + '\n|}\n']
118         return res_format
119
120
121
122 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
123