1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
27 _logger = logging.getLogger(__name__)
29 class RemoteConnectionException(Exception):
32 class RemoteConnection:
34 def __init__(self, server, db, login, password):
35 self._server = server.strip()
36 if not self._server.endswith("/"):
40 self._password = password
42 rpc = xmlrpclib.ServerProxy(self._server + "xmlrpc/common")
44 self._userid = rpc.login(self._db, self._login, self._password)
46 raise RemoteConnectionException("Unable to contact the remote server")
49 raise RemoteConnectionException("Unable to contact the remote server")
51 self._rpc = xmlrpclib.ServerProxy(self._server + "xmlrpc/object")
53 def get_remote_object(self, object):
54 return RemoteObject(self, object)
56 class RemoteObject(object):
58 def __init__(self, connection, object):
62 def __getattr__(self, fun):
63 def remote_call(*args, **kwargs):
64 return self._c._rpc.execute(self._c._db, self._c._userid,
65 self._c._password, self._object, fun, *args, **kwargs)
68 def __getitem__(self, item):
69 return getattr(self, item)
71 class RemoteContractException(Exception): pass
73 def remote_contract(cr, uid, contract_id):
74 pool = pooler.get_pool(cr.dbname)
75 dbuuid = pool.get('ir.config_parameter').get_param(cr, uid, 'database.uuid')
78 ro = RemoteConnection(config.config.get("maintenance_server"), config.config.get("maintenance_db"),
79 config.config.get("maintenance_login"), config.config.get("maintenance_password")
80 ).get_remote_object('maintenance.maintenance')
82 _logger.exception("Exception")
83 raise RemoteContractException("Unable to contact the migration server")
85 info = ro.check_contract_6({
86 "contract_name": contract_id,
90 setattr(ro, n, info[n])
95 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: