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-2009 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     def __init__(self):
32         '''
33         this method should initialize the var
34         '''
35         #This float have to store the rating of the module.
36         #Used to compute the final score (average of all scores).
37         #0 <= self.score <= 1
38         self.score = 0.0
39
40         #This char have to store the name of the test.
41         self.name = ""
42
43         #This char have to store the result.
44         #Used to display the result of the test.
45         self.result = ""
46
47         #This char have to store the result with more details.
48         #Used to provide more details if necessary.
49         self.result_details = ""
50
51         #This bool defines if the test can be run only if the module is installed.
52         #True => the module have to be installed.
53         #False => the module can be uninstalled.
54         self.bool_installed_only = True
55
56         #This variable is use to make result of test should have more weight (Some tests are more critical than others)
57         self.ponderation = 1.0
58
59         #Specify test got an error on module
60         self.error = False
61
62         #The tests have to subscribe itselfs in this list, that contains all the test that have to be performed.
63         self.tests = []
64         self.list_folders = os.listdir(config['addons_path']+'/base_module_quality/')
65         for item in self.list_folders:
66             self.item = item
67             path = config['addons_path']+'/base_module_quality/'+item
68             if os.path.exists(path+'/'+item+'.py') and item not in ['report', 'wizard', 'security']:
69                 item2 = 'base_module_quality.' + item +'.' + item
70                 x = __import__(item2)
71                 x2 = getattr(x, item)
72                 x3 = getattr(x2, item)
73                 self.tests.append(x3)
74 #        raise 'Not Implemented'
75
76     def run_test(self, cr, uid, module_path=""):
77         '''
78         this method should do the test and fill the score, result and result_details var
79         '''
80         raise 'Not Implemented'
81
82     def get_objects(self, cr, uid, module):
83         # This function returns all object of the given module..
84         pool = pooler.get_pool(cr.dbname)
85         ids2 = pool.get('ir.model.data').search(cr, uid, [('module','=', module), ('model','=','ir.model')])
86         model_list = []
87         model_data = pool.get('ir.model.data').browse(cr, uid, ids2)
88         for model in model_data:
89             model_list.append(model.res_id)
90         obj_list = []
91         for mod in pool.get('ir.model').browse(cr, uid, model_list):
92             obj_list.append(str(mod.model))
93         return obj_list
94
95     def get_ids(self, cr, uid, object_list):
96         #This method return dictionary with ids of records of object for module
97         pool = pooler.get_pool(cr.dbname)
98         result_ids = {}
99         for obj in object_list:
100             ids = pool.get(obj).search(cr, uid, [])
101             result_ids[obj] = ids
102         return result_ids
103
104     def format_table(self, header=[], data_list=[]):
105         detail = ""
106         header_list = []
107         final_list = []
108         for head in data_list[1]:
109             header_list.append(head)
110         detail += (header[0]) % tuple(header_list)
111         for res in data_list[0]:
112             data_list[0][res].append(res)
113             detail += (header[1]) % tuple(data_list[0][res])
114         detail = detail + '\n|}'
115         return detail
116
117     def add_quatation(self, x, y):
118         return x/y
119
120 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
121