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
73 #Specify test got an error on module
77 self.list_folders = os.listdir(config['addons_path']+'/base_module_quality/')
78 for item in self.list_folders:
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
85 x3 = getattr(x2, item)
87 # raise 'Not Implemented'
89 def run_test(self, cr, uid, module_path="", module_state=""):
91 this method should do the test and fill the score, result and result_details var
93 # raise 'Not Implemented'
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')])
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)
104 for mod in pool.get('ir.model').browse(cr, uid, model_list):
105 obj_list.append(str(mod.model))
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)
112 for obj in object_list:
113 ids = pool.get(obj).search(cr, uid, [])
114 result_ids[obj] = ids
117 def format_table(self, test='', header=[], data_list=[]):
121 detail += "\n===Method Test===\n"
122 res_format['detail'] = detail
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]
130 res_format['summary'] = data_list[0]
131 res_format['detail'] = data_list[1]
134 detail += "\n===Speed Test===\n"
135 res_format['detail'] = detail
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]
143 res_format['summary'] = data_list[0]
144 res_format['detail'] = data_list[1]
147 def add_quatation(self, x, y):
152 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: