[IMP] locate the migration server elsewhere than localhost
[odoo/odoo.git] / bin / tools / maintenance.py
1 # -*- encoding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution   
5 #    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
6 #    $Id$
7 #
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.
12 #
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.
17 #
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/>.
20 #
21 ##############################################################################
22
23 import xmlrpclib
24
25 class RemoteContractException(Exception): pass
26
27 class remote_contract(object):
28     def __init__(self, contract_id, contract_password, modules=None):
29         self.__server = 'http://192.168.0.127:8072/xmlrpc/'
30         self.__db = "maintenance"
31         self.__password = "admin"
32         self.__login = "admin"
33         
34         rpc = xmlrpclib.ServerProxy(self.__server + 'common')
35         try:
36             self.__userid = rpc.login(self.__db, self.__login, self.__password)
37         except:
38             raise RemoteContractException("Unable to contact the migration server")
39
40         self.__rpc = xmlrpclib.ServerProxy(self.__server + 'object')
41         
42
43         contract = {
44             'name': contract_id,
45             'password': contract_password,
46         }
47         if modules is None:
48             modules = []
49
50         info = self.check_contract(modules, contract)
51         for n in info:
52             setattr(self, n, info[n])
53         
54         self.name = contract_id
55         self.contract_id = self.name
56         self.password = contract_password
57         
58     def __getattr__(self, fun):
59         def remote_call(*args, **kwargs):
60             return self.__rpc.execute(self.__db, self.__userid, self.__password, 'maintenance.maintenance', fun, *args, **kwargs)
61         return remote_call
62
63     def __getitem__(self, item):
64         return getattr(self, item)
65
66 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
67