1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2008 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 ##############################################################################
24 from tools import config
26 class abstract_quality_check(object):
31 # #This float have to store the rating of the module.
32 # #Used to compute the final score (average of all scores).
35 # #This char have to store the result.
36 # #Used to display the result of the test.
39 # #This char have to store the result with more details.
40 # #Used to provide more details if necessary.
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
50 this method should initialize the var
52 #This float have to store the rating of the module.
53 #Used to compute the final score (average of all scores).
56 #This char have to store the result.
57 #Used to display the result of the test.
60 #This char have to store the result with more details.
61 #Used to provide more details if necessary.
62 self.result_details = ""
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
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
74 self.list_folders = os.listdir(config['addons_path']+'/base_module_quality/')
75 for item in self.list_folders:
77 path = config['addons_path']+'/base_module_quality/'+item
78 if os.path.exists(path+'/'+item+'.py') and item not in ['report', 'wizard', 'security']:
79 item2 = 'base_module_quality.' + item +'.' + item
82 x3 = getattr(x2, item)
84 # raise 'Not Implemented'
86 def run_test(self, cr, uid, module_path="", module_state=""):
88 this method should do the test and fill the score, result and result_details var
90 # raise 'Not Implemented'
92 def get_objects(self, cr, uid, module):
93 # This function returns all object of the given module..
94 pool = pooler.get_pool(cr.dbname)
95 ids2 = pool.get('ir.model.data').search(cr, uid, [('module','=', module), ('model','=','ir.model')])
97 model_data = pool.get('ir.model.data').browse(cr, uid, ids2)
98 for model in model_data:
99 model_list.append(model.res_id)
101 for mod in pool.get('ir.model').browse(cr, uid, model_list):
102 obj_list.append(str(mod.model))
105 def get_ids(self, cr, uid, object_list):
106 #This method return dictionary with ids of records of object for module
107 pool = pooler.get_pool(cr.dbname)
109 for obj in object_list:
110 ids = pool.get(obj).search(cr, uid, [])
111 result_ids[obj] = ids
114 def format_table(self, test='', header=[], data_list=[]):
118 detail += "\n===Method Test===\n"
119 res_format['detail'] = detail
121 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))
122 for res in data_list[1]:
123 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])
124 res_format['detail'] = detail + '\n|}'
125 res_format['summary'] = data_list[0]
127 res_format['summary'] = data_list[0]
128 res_format['detail'] = data_list[1]
131 detail += "\n===Speed Test===\n"
132 res_format['detail'] = detail
134 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))
135 for data in data_list[1]:
136 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])
137 res_format['detail'] = detail + '\n|}\n'
138 res_format['summary'] = data_list[0]
140 res_format['summary'] = data_list[0]
141 res_format['detail'] = data_list[1]
144 def add_quatation(self, x, y):
149 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: