Attachment 'moin_xmlrpc_get.py'
Download 1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 """
5 Inkscape extension for reading files from a MoinMoin wiki by xmlrpc get
6
7 @copyright: 2009 MoinMoin:ReimarBauer
8
9 @license: GNU GPL, see COPYING for details.
10 """
11
12 import sys
13 sys.path.append('/usr/share/inkscape/extensions')
14
15 # We will use the inkex module with the predefined Effect base class.
16 import inkex
17 import xmlrpclib
18
19 class MoinXmlrpcGet(inkex.Effect):
20 """
21 Creates a new layer with the retrieved image
22 """
23 def __init__(self):
24 """
25 Constructor.
26 """
27 # Call the base class constructor.
28 inkex.Effect.__init__(self)
29
30 # Define string option "--url" with "-u" shortcut and default value
31 self.OptionParser.add_option('-u', '--url', action='store',
32 type='string', dest='url', default='http://',
33 help='What would wiki url you like to access?')
34
35 self.OptionParser.add_option('-n', '--username', action='store',
36 type='string', dest='name', default='',
37 help='Your name to log in?')
38
39 self.OptionParser.add_option('-p', '--password', action='store',
40 type='string', dest='password', default='',
41 help='Your password for your name to log in?')
42
43 self.OptionParser.add_option('-w', '--pagename', action='store',
44 type='string', dest='wikipage', default='WikiSandBox',
45 help='The wikipage you want to access')
46
47 self.OptionParser.add_option('-a', '--attachment', action='store',
48 type='string', dest='attachment', default='whiteboard.svg',
49 help='The attchment you want to access')
50
51
52 def effect(self):
53 """
54 Effect behaviour.
55 Overrides base class' method and inserts SVG graphic from moin wiki into SVG document.
56 """
57
58 url = self.options.url
59 name = self.options.name
60 password = self.options.password
61 pagename = self.options.wikipage
62 attachment = self.options.attachment
63
64 homewiki = xmlrpclib.ServerProxy(url + "?action=xmlrpc2", allow_none=True)
65 mc = xmlrpclib.MultiCall(homewiki)
66 auth_token = homewiki.getAuthToken(name, password)
67 mc.applyAuthToken(auth_token)
68
69 mc.getAttachment(pagename, attachment)
70 result = mc()
71 msg, data = tuple(result)
72 sys.stdout.write(data.data)
73 sys.exit(0)
74
75 # Create effect instance and apply it.
76 effect = MoinXmlrpcGet()
77 effect.affect()
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.