[ Index ] |
|
Code source de Dolibarr 2.0.1 |
1 #!/usr/bin/env python 2 # 3 # Glasnost 4 # By: Odile Bénassy <obenassy@entrouvert.com> 5 # Thierry Dulieu <tdulieu@easter-eggs.com> 6 # Frédéric Péters <fpeters@theridion.com> 7 # Benjamin Poussin <poussin@codelutin.com> 8 # Emmanuel Raviart <eraviart@entrouvert.com> 9 # Emmanuel Saracco <esaracco@easter-eggs.com> 10 # 11 # Copyright (C) 2000, 2001 Easter-eggs & Emmanuel Raviart 12 # Copyright (C) 2002 Odile Bénassy, Code Lutin, Thierry Dulieu, Easter-eggs, 13 # Entr'ouvert, Frédéric Péters, Benjamin Poussin, Emmanuel Raviart, 14 # Emmanuel Saracco & Théridion 15 # Copyright (C) 2003 Odile Bénassy, Code Lutin, Thierry Dulieu, Easter-eggs, 16 # Entr'ouvert, Ouvaton, Frédéric Péters, Benjamin Poussin, Rodolphe 17 # Quiédeville, Emmanuel Raviart, Emmanuel Saracco, Théridion & Vecam 18 # 19 # This program is free software; you can redistribute it and/or 20 # modify it under the terms of the GNU General Public License 21 # as published by the Free Software Foundation; either version 2 22 # of the License, or (at your option) any later version. 23 # 24 # This program is distributed in the hope that it will be useful, 25 # but WITHOUT ANY WARRANTY; without even the implied warranty of 26 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 27 # GNU General Public License for more details. 28 # 29 # You should have received a copy of the GNU General Public License 30 # along with this program; if not, write to the Free Software 31 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 32 33 34 __doc__ = """Sample showing how to handle people with XML-RPC""" 35 36 __version__ = '$Revision: 1.1 $'[11:-2] 37 38 39 import xmlrpclib # Requires Python >= 2.2. 40 41 42 # Every calls to a Glasnost server is handled by a Glasnost XML-RPC gateway. 43 glasnostServerName = 'localhost' ### YOU MAY NEED TO CHANGE THIS!!! 44 glasnostGatewayPort = 8001 45 46 # The login & password of a Glasnost user who has the rights to add people to 47 # the server. 48 login = 'login' ### CHANGE THIS!!! 49 password = 'password' ### CHANGE THIS!!! 50 51 # Each Glasnost server is uniquely identified by its server id. 52 authenticationServerId = 'glasnost://%s/authentication' % glasnostServerName 53 peopleServerId = 'glasnost://%s/people' % glasnostServerName 54 55 # This sample application doesn't need an application token. 56 applicationToken = '' 57 58 # First, establish a connection to the gateway. 59 gateway = xmlrpclib.ServerProxy('http://%s:%d' % ( 60 glasnostServerName, glasnostGatewayPort)) 61 62 # Call the authentication server to give him your login & password and to 63 # receive a user id and token. 64 userId, userToken = gateway.callGateway( 65 authenticationServerId, 66 'getUserIdAndToken', 67 [authenticationServerId, applicationToken, login, password]) 68 print 'Login = %s' % login 69 print 'User ID = %s' % userId 70 print 'User Token = %s' % userToken 71 72 # Create a new person. 73 # Note: The attributes of people are described in shared/common/PeopleCommon.py 74 person = { 75 # Don't touch the next two lines. 76 '__thingCategory__': 'object', 77 '__thingName__': 'Person', 78 79 'firstName': 'John', 80 'lastName': 'Doe', 81 'login': 'jdoe', 82 'email': 'root@localhost', ### CHANGE THIS!!! 83 } 84 85 # Call the method addObject of the people server. 86 # Note: The available functions of the people server are defined in the class 87 # PeopleServer, which is defined in servers/PeopleServer/PeopleServer.py. 88 # The class PeopleServer inherits from the class ObjectsServer, which is 89 # defined in shared/server/ObjectsServer.py 90 personId = gateway.callGateway( 91 peopleServerId, 92 'addObject' , 93 [peopleServerId, applicationToken, userToken, person]) 94 print 'Person created with id = %s' % personId 95 96 # Give a person id and get its infos. 97 person = gateway.callGateway( 98 peopleServerId, 99 'getObject' , 100 [peopleServerId, applicationToken, userToken, personId]) 101 print 'Got a new person = %s' % person 102 103 # Change the nickname of that person. 104 person['nickname'] = 'jd' 105 gateway.callGateway( 106 peopleServerId, 107 'modifyObject' , 108 [peopleServerId, applicationToken, userToken, person]) 109 110 # Get the new infos of the person. 111 person = gateway.callGateway( 112 peopleServerId, 113 'getObject' , 114 [peopleServerId, applicationToken, userToken, personId]) 115 print 'Got a modified person = %s' % person 116 117 # Remove the person. 118 gateway.callGateway( 119 peopleServerId, 120 'deleteObject' , 121 [peopleServerId, applicationToken, userToken, personId]) 122 print 'Person deleted'
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 12:29:37 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |