comparison MoinMoin/script/xmlrpc/write.py @ 2939:6259bb49366c

trivial xmlrpc examples (scripts)
author Johannes Berg <johannes AT sipsolutions DOT net>
date Fri, 02 Nov 2007 12:43:42 +0000
parents
children ed1a433803c6
comparison
equal deleted inserted replaced
2938:bdd5df911941 2939:6259bb49366c
1 # -*- coding: iso-8859-1 -*-
2 """
3 MoinMoin - page contents writer
4
5 Commented example of how to edit a page with xmlrpc.
6
7 @copyright: 2007 MoinMoin:JohannesBerg
8 @license: GNU GPL, see COPYING for details.
9 """
10
11 import xmlrpclib
12 import sys
13
14 from MoinMoin.script import MoinScript
15 from MoinMoin.support.multicall import MultiCall
16
17 class PluginScript(MoinScript):
18 def __init__(self, argv, def_values):
19 MoinScript.__init__(self, argv, def_values)
20 self.argv = argv
21
22 # script entrypoint
23 def mainloop(self):
24 # grab parameters
25 url = self.argv[0]
26 user = self.argv[1]
27 passwd = self.argv[2]
28 pagename = self.argv[3]
29
30 # get auth token from server giving username/password
31 s = xmlrpclib.ServerProxy(url)
32 token = s.getAuthToken(user, passwd)
33
34 if token == '':
35 print 'Invalid username/password'
36 return
37
38 # Verify that the token is valid by using it
39 # and checking that the result is 'SUCCESS'.
40 # The token should be valid for 15 minutes.
41 assert s.applyAuthToken(token) == 'SUCCESS'
42
43 try:
44 # read new page contents
45 content = sys.stdin.read()
46
47 # build a multicall object that
48 mcall = MultiCall(s)
49 # first applies the token and
50 mcall.applyAuthToken(token)
51 # then edits the page
52 mcall.putPage(pagename, content)
53
54 # now execute the multicall
55 results = mcall()
56
57 # everything should have worked
58 # instead of the asserts you can have anything else
59 # but you should definitely access all the results
60 # once so that faults are checked and raised
61 assert results[0] == 'SUCCESS'
62 assert results[1] == True
63
64 finally:
65 # be nice to the server and clean up the token
66 # regardless of what happened
67 assert s.deleteAuthToken(token) == 'SUCCESS'