~openupgrade-committers/openupgrade-server/5.0

« back to all changes in this revision

Viewing changes to bin/addons/openupgrade_records/model/comparison_config.py

  • Committer: Stefan Rijnhart
  • Date: 2012-05-27 12:24:43 UTC
  • mfrom: (2175.1.3 openupgrade-server)
  • Revision ID: stefan@therp.nl-20120527122443-7lh1cvrm26wt8u6e
[MRG] Add openupgrade development module for easy analysis file generation

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    OpenERP, Open Source Management Solution
 
5
#    This module Copyright (C) 2012 OpenUpgrade community
 
6
#    https://launchpad.net/~openupgrade-committers
 
7
#
 
8
#    Contributors:
 
9
#    Therp BV <http://therp.nl>
 
10
#
 
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.
 
15
#
 
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.
 
20
#
 
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/>.
 
23
#
 
24
##############################################################################
 
25
 
 
26
from osv import osv, fields
 
27
import openerplib
 
28
from tools.translate import _
 
29
 
 
30
class openupgrade_comparison_config(osv.osv):
 
31
    _name = 'openupgrade.comparison.config'
 
32
    _columns = {
 
33
        'name': fields.char('Name', size=64),
 
34
        'server': fields.char('Server', size=64, required=True),
 
35
        'port': fields.integer('Port', required=True),
 
36
        'protocol': fields.selection(
 
37
            [('http://', 'XML-RPC')],
 
38
            # ('https://', 'XML-RPC Secure')], not supported by libopenerp
 
39
            'Protocol', required=True),
 
40
        'database': fields.char('Database', size=64, required=True),
 
41
        'username': fields.char('Username', size=24, required=True),
 
42
        'password': fields.char('Password', size=24, required=True, password=True),
 
43
        'last_log': fields.text('Last log'),
 
44
        }
 
45
    _defaults = {
 
46
        'port': lambda *a: 8069,
 
47
        'protocol': lambda *a: 'http://',
 
48
        }
 
49
 
 
50
    def get_connection(self, cr, uid, ids, context=None):
 
51
        if not ids:
 
52
            raise osv.except_osv(
 
53
                _("Cannot connect"), _("Invalid id passed."))
 
54
        conf = self.read(cr, uid, ids[0], context=None)
 
55
        return openerplib.get_connection(
 
56
           hostname=conf['server'],
 
57
           database=conf['database'],
 
58
           login=conf['username'],
 
59
           password=conf['password'],
 
60
           port=conf['port'],
 
61
           )
 
62
 
 
63
    def test_connection(self, cr, uid, ids, context=None):
 
64
        try:
 
65
            connection = self.get_connection(cr, uid, [ids[0]], context)
 
66
            user_model = connection.get_model("res.users")
 
67
            ids = user_model.search([("login", "=", "admin")])
 
68
            user_info = user_model.read(ids[0], ["name"])
 
69
        except Exception, e:
 
70
            raise osv.except_osv(
 
71
                _("Connection failed."), unicode(e))
 
72
        raise osv.except_osv(
 
73
            _("Connection succesful."),
 
74
            _("%s is connected.") % user_info["name"]
 
75
            )
 
76
    
 
77
    def analyze(self, cr, uid, ids, context=None):
 
78
        """
 
79
        Run the analysis wizard
 
80
        """
 
81
        wizard_obj = self.pool.get('openupgrade.analysis.wizard')
 
82
        wizard_id = wizard_obj.create(
 
83
            cr, uid, {'server_config': ids[0]}, context)
 
84
        result = {
 
85
            'name': wizard_obj._description,
 
86
            'view_type': 'form',
 
87
            'view_mode': 'form',
 
88
            'res_model': 'openupgrade.analysis.wizard',
 
89
            'domain': [],
 
90
            'context': context,
 
91
            'type': 'ir.actions.act_window',
 
92
            'target': 'new',
 
93
            'res_id': wizard_id,
 
94
            'nodestroy': True,
 
95
            }
 
96
        return result
 
97
 
 
98
openupgrade_comparison_config()