Attachment 'moin_xmlrpc_put.py'

Download

   1 #!/usr/bin/env python
   2 # -*- coding: utf-8 -*-
   3 """
   4 Inkscape extension for storing files in a MoinMoin wiki by xmlrpc put
   5 
   6 @copyright: 2009 MoinMoin:ReimarBauer
   7 
   8 @license: GNU GPL, see COPYING for details.
   9 """
  10 import sys
  11 sys.path.append('/usr/share/inkscape/extensions')
  12 
  13 # We will use the inkex module with the predefined Effect base class.
  14 import inkex
  15 import xmlrpclib
  16 
  17 class MoinXmlrpcPut(inkex.Effect):
  18     """
  19     Stores an image to a moinmoin wiki page
  20     """
  21     def __init__(self):
  22         """
  23         Constructor.
  24         """
  25         # Call the base class constructor.
  26         inkex.Effect.__init__(self)
  27 
  28         # Define string option "--url" with "-u" shortcut and default value
  29         self.OptionParser.add_option('-u', '--url', action='store',
  30           type='string', dest='url', default='http://',
  31           help='What would wiki url you like to access?')
  32 
  33         self.OptionParser.add_option('-n', '--username', action='store',
  34           type='string', dest='name', default='',
  35           help='Your name to log in?')
  36 
  37         self.OptionParser.add_option('-p', '--password', action='store',
  38           type='string', dest='password', default='',
  39           help='Your password for your name to log in?')
  40 
  41         self.OptionParser.add_option('-w', '--pagename', action='store',
  42           type='string', dest='wikipage', default='WikiSandBox',
  43           help='The wikipage you want to access')
  44 
  45         self.OptionParser.add_option('-a', '--attachment', action='store',
  46           type='string', dest='attachment', default='whiteboard.svg',
  47           help='The attchment you want to access')
  48 
  49 
  50     def effect(self):
  51         """
  52         Effect behaviour.
  53         Overrides base class' method and inserts SVG graphic from moin wiki into SVG document.
  54         """
  55         ttmp_orig = self.document.getroot()
  56         docname = ttmp_orig.get(inkex.addNS('docname',u'sodipodi'))
  57 
  58         data = open('/tmp/'+docname, 'rb').read() # where is that path hidded
  59 
  60         url = self.options.url
  61         name = self.options.name
  62         password = self.options.password
  63         pagename = self.options.wikipage
  64         attachment = self.options.attachment
  65 
  66         homewiki = xmlrpclib.ServerProxy(url + "?action=xmlrpc2", allow_none=True)
  67         mc = xmlrpclib.MultiCall(homewiki)
  68         auth_token = homewiki.getAuthToken(name, password)
  69         mc.applyAuthToken(auth_token)
  70 
  71         data = xmlrpclib.Binary(data)
  72         mc.putAttachment(pagename, attachment, data)
  73         result = mc()
  74         sys.exit(0)
  75 
  76 # Create effect instance and apply it.
  77 effect = MoinXmlrpcPut()
  78 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.
  • [get | view] (2009-05-17 10:14:48, 3.2 KB) [[attachment:inkscape_moin_xmlrpc.zip]]
  • [get | view] (2009-05-17 10:14:53, 0.9 KB) [[attachment:moin_xmlrpc_get.inx]]
  • [get | view] (2009-05-17 10:14:56, 2.4 KB) [[attachment:moin_xmlrpc_get.py]]
  • [get | view] (2009-05-17 10:15:00, 0.9 KB) [[attachment:moin_xmlrpc_put.inx]]
  • [get | view] (2009-05-17 10:15:04, 2.5 KB) [[attachment:moin_xmlrpc_put.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.