1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# This module Copyright (C) 2012 OpenUpgrade community
6
# https://launchpad.net/~openupgrade-committers
9
# Therp BV <http://therp.nl>
11
# This program is free software: you can redistribute it and/or modify
12
# it under the terms of the GNU Affero General Public License as
13
# published by the Free Software Foundation, either version 3 of the
14
# License, or (at your option) any later version.
16
# This program is distributed in the hope that it will be useful,
17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
# GNU Affero General Public License for more details.
21
# You should have received a copy of the GNU Affero General Public License
22
# along with this program. If not, see <http://www.gnu.org/licenses/>.
24
##############################################################################
27
from osv import osv, fields
30
from openerp.addons.openupgrade_records.lib import compare
31
from openerp.openupgrade_records.lib import apriori
32
from openerp.addons import get_module_path
34
from openupgrade_records.lib import compare
35
from openupgrade_records.lib import apriori
36
from addons import get_module_path
38
class openupgrade_analysis_wizard(osv.osv_memory):
39
_name = 'openupgrade.analysis.wizard'
40
_description = 'OpenUpgrade Analysis Wizard'
42
'server_config': fields.many2one(
43
'openupgrade.comparison.config',
44
'Configuration', required=True),
45
'state': fields.selection(
46
[('init', 'Init'), ('ready', 'Ready')], 'State',
48
'log': fields.text('Log'),
49
'write': fields.boolean(
51
help='Write analysis files to the module directories'
55
'state': lambda *a: 'init',
56
'write': lambda *a: True,
59
def get_communication(self, cr, uid, ids, context=None):
61
Retrieve both sets of database representations,
62
perform the comparison and register the resulting
66
module, version, contents, filename='openupgrade_analysis.txt'):
67
module_path = get_module_path(module)
69
return "ERROR: could not find module path:\n"
70
full_path = os.path.join(
71
module_path, 'migrations', version)
72
if not os.path.exists(full_path):
74
os.makedirs(full_path)
76
return "ERROR: could not create migrations directory:\n"
77
logfile = os.path.join(full_path, filename)
79
f = open(logfile, 'w')
81
return "ERROR: could not open file %s for writing:\n" % logfile
86
wizard = self.browse(cr, uid, ids[0], context=context)
87
# Retrieve connection and access methods
88
conf_obj = self.pool.get('openupgrade.comparison.config')
89
connection = conf_obj.get_connection(
90
cr, uid, [wizard.server_config.id], context=context)
91
remote_record_obj = connection.get_model('openupgrade.record')
92
local_record_obj = self.pool.get('openupgrade.record')
94
# Retrieve field representations and compare
95
remote_records = remote_record_obj.field_dump(context)
96
local_records = local_record_obj.field_dump(cr, uid, context)
97
res = compare.compare_sets(remote_records, local_records)
99
# Retrieve xml id representations and compare
100
fields = ['module', 'model', 'name']
101
local_xml_record_ids = local_record_obj.search(
102
cr, uid, [('type', '=', 'xmlid')])
103
remote_xml_record_ids = remote_record_obj.search(
104
[('type', '=', 'xmlid')])
105
local_xml_records = [
106
dict([(field, x[field]) for field in fields])
107
for x in local_record_obj.read(
108
cr, uid, local_xml_record_ids, fields)
110
remote_xml_records = [
111
dict([(field, x[field]) for field in fields])
112
for x in remote_record_obj.read(
113
remote_xml_record_ids, fields)
115
res_xml = compare.compare_xml_sets(
116
remote_xml_records, local_xml_records)
118
# reorder and output the result
119
keys = list(set(res.keys() + res_xml.keys()))
120
keys.remove('general')
121
keys = ['general'] + keys
122
module_obj = self.pool.get('ir.module.module')
123
module_ids = module_obj.search(
124
cr, uid, [('state', '=', 'installed')])
125
modules = dict([(x['name'], x) for x in module_obj.read(cr, uid, module_ids)])
128
contents = "---%s---\n" % key
130
contents += '\n'.join([unicode(line) for line in sorted(res[key])])
134
contents += '\n'.join([unicode(line) for line in sorted(res_xml[key])])
140
if key not in modules:
142
"ERROR: module not in list of installed modules:\n"
147
key, modules[key]['installed_version'], contents)
154
# Store the general log in as many places as possible ;-)
155
if wizard.write and 'base' in modules:
157
'base', modules['base']['installed_version'], general,
158
'openupgrade_general_log.txt')
159
self.pool.get('openupgrade.comparison.config').write(
160
cr, uid, wizard.server_config.id,
161
{'last_log': general})
162
self.write(cr, uid, ids, {'state': 'ready', 'log': general})
165
'name': self._description,
168
'res_model': 'openupgrade.analysis.wizard',
171
'type': 'ir.actions.act_window',
177
openupgrade_analysis_wizard()