Short description

Because for mass data upload I need further methods in MoinMoin xmlrpc base.

Patch

   1 diff -r f992fed6e94a MoinMoin/xmlrpc/__init__.py
   2 --- a/MoinMoin/xmlrpc/__init__.py	Sun Dec 06 00:29:33 2009 +0100
   3 +++ b/MoinMoin/xmlrpc/__init__.py	Tue Dec 08 09:16:34 2009 +0100
   4 @@ -555,6 +555,25 @@
   5  
   6          return xmlrpclib.Boolean(1)
   7  
   8 +    def xmlrpc_renamePage(self, pagename, newpagename):
   9 +        """Renames a page to newpagename
  10 +
  11 +        @param pagename: the page name (unicode or utf-8)
  12 +        @param newpagename: then new pagename (unicode or utf-8)
  13 +        @rtype bool
  14 +        @return true on success
  15 +        """
  16 +        if not (self.request.user.may.delete(pagename) and self.request.user.may.write(newpagename)):
  17 +            return xmlrpclib.Fault(1, "You are not allowed to rename this page")
  18 +        editor = PageEditor(self.request, pagename)
  19 +
  20 +        try:
  21 +            editor.renamePage(newpagename)
  22 +        except PageEditor.SaveError, error:
  23 +            return xmlrpclib.Fault(1, "Rename failed: %s" % (str(error), ))
  24 +
  25 +        return xmlrpclib.Boolean(1)
  26 +
  27      def xmlrpc_revertPage(self, pagename, revision):
  28          """Revert a page to previous revision
  29  
  30 @@ -981,9 +1000,41 @@
  31          AttachFile._addLogEntry(self.request, 'ATTNEW', pagename, attachname)
  32          return xmlrpclib.Boolean(1)
  33  
  34 +    def xmlrpc_delAttachment(self, pagename, attachname):
  35 +        """ deletes Attachment from pagename
  36 +
  37 +        @param pagename: pagename (utf-8)
  38 +        @param attachname: attachment name (utf-8)
  39 +        @rtype boolean
  40 +        @return True if attachment was delted
  41 +        """
  42 +        pagename = self._instr(pagename)
  43 +
  44 +        if not self.request.user.may.delete(pagename):
  45 +            return xmlrpclib.Fault(1, 'You are not allowed to delete attachments on this page.')
  46 +
  47 +        attachname = wikiutil.taintfilename(attachname)
  48 +        filename = AttachFile.getFilename(self.request, pagename, attachname)
  49 +        AttachFile.remove_attachment(self.request, pagename, attachname)
  50 +        return xmlrpclib.Boolean(1)
  51 +
  52 +    def xmlrpc_unzipAttachment(self, pagename):
  53 +        """ unzips attachname associated with pagename
  54 +
  55 +        @param pagename: pagename (utf-8)
  56 +        @rtype base64
  57 +        @return base64 data
  58 +        """
  59 +        pagename = self._instr(pagename)
  60 +        #
  61 +        if not (self.request.user.may.delete(pagename) and self.request.user.may.read(pagename) and self.request.user.may.write(pagename)):
  62 +            return xmlrpclib.Fault(1, 'You are not allowed to unzip attachments of this page.')
  63 +
  64 +        AttachFile._do_unzip(pagename, self.request, overwrite=False)
  65 +        return xmlrpclib.Boolean(1)
  66 +
  67      # XXX END WARNING XXX
  68  
  69 -
  70      def xmlrpc_getBotTranslations(self):
  71          """ Return translations to be used by notification bot
  72  

xmlrpc.patch

Examples how to call xmlrpc features

   1 #!/usr/bin/env python
   2 # -*- coding: iso-8859-1 -*-
   3 
   4 """
   5 Just examples for using the xmlrpc calls.
   6 
   7 """
   8 import getpass
   9 import os
  10 import time
  11 import xmlrpclib
  12 
  13 NAME = os.environ.get("WIKIUSER", "")
  14 PAGENAME = u"ExampleTestPage"
  15 ATTACHNAME = u"example.zip"
  16 PASSWORD = getpass.getpass()
  17 WIKIURL = "http://localhost:8080/"
  18 
  19 def get_filelist():
  20     """"
  21     this script creates a page PAGENAME
  22     currently the pagename is hard coded
  23     username NAME is read from an env var WIKIUSER
  24     """
  25     if NAME and PASSWORD:
  26         xmlrpc_url = "%s?action=xmlrpc2" % WIKIURL
  27         homewiki = xmlrpclib.ServerProxy(xmlrpc_url, allow_none=True)
  28         multicall = xmlrpclib.MultiCall(homewiki)
  29         auth_token = homewiki.getAuthToken(NAME, PASSWORD)
  30         if auth_token:
  31             multicall.applyAuthToken(auth_token)
  32             multicall.listAttachments(PAGENAME)
  33             result = multicall()
  34             if tuple(result)[0] == "SUCCESS":
  35                 return tuple(result)[1]
  36     return []
  37 
  38 def put_page():
  39     """"
  40     this script creates a page PAGENAME
  41     currently the pagename is hard coded
  42     username NAME is read from an env var WIKIUSER
  43     """
  44     filelist = get_filelist()
  45     filelist = [txt for txt in filelist if txt.endswith('.png')]
  46 
  47     if NAME and PASSWORD and ATTACHNAME.endswith('.zip'):
  48         xmlrpc_url = "%s?action=xmlrpc2" % WIKIURL
  49         homewiki = xmlrpclib.ServerProxy(xmlrpc_url, allow_none=True)
  50         multicall = xmlrpclib.MultiCall(homewiki)
  51         auth_token = homewiki.getAuthToken(NAME, PASSWORD)
  52         if auth_token:
  53             multicall.applyAuthToken(auth_token)
  54             text = [' * {{attachment:%s}} ' % txt for txt in filelist]
  55             multicall.putPage(PAGENAME, '\n'.join(text))
  56             result = multicall()
  57             if isinstance(result, tuple) and tuple(result)[0] == "SUCCESS":
  58                 print "page '%s' created: %s" % (PAGENAME, tuple(result)[0])
  59             else:
  60                 print 'You did not change the page content, not saved!'
  61 
  62 def rename_page():
  63     """"
  64     this script renames a page PAGENAME hardcoded to a prefix of Trash_ 
  65     and a time stamp
  66     currently the pagename is hard coded
  67     username NAME is read from an env var WIKIUSER
  68     """
  69     if NAME and PASSWORD:
  70         xmlrpc_url = "%s?action=xmlrpc2" % WIKIURL
  71         homewiki = xmlrpclib.ServerProxy(xmlrpc_url, allow_none=True)
  72         multicall = xmlrpclib.MultiCall(homewiki)
  73         auth_token = homewiki.getAuthToken(NAME, PASSWORD)
  74         if auth_token:
  75             multicall.applyAuthToken(auth_token)
  76             trash_name = 'Trash_%d_%s' % (time.time(), PAGENAME)
  77             multicall.renamePage(PAGENAME, trash_name)
  78             result = multicall()
  79             if tuple(result)[0] == "SUCCESS":
  80                 print "page '%s' renamed to %s: %s" % (PAGENAME,
  81                 trash_name, tuple(result)[0])
  82             else:
  83                 print tuple(result)[1]
  84 
  85 def unzip_attachment():
  86     """"
  87     this script unzips an attachment ATTACHNME on a page
  88     currently the attachment name and the pagename is hard coded
  89     username NAME is read from an env var WIKIUSER
  90     """
  91     if NAME and PASSWORD and ATTACHNAME.endswith('.zip'):
  92         xmlrpc_url = "%s?action=xmlrpc2&target=%s" % (WIKIURL, ATTACHNAME)
  93         homewiki = xmlrpclib.ServerProxy(xmlrpc_url, allow_none=True)
  94         multicall = xmlrpclib.MultiCall(homewiki)
  95         auth_token = homewiki.getAuthToken(NAME, PASSWORD)
  96         if auth_token:
  97             multicall.applyAuthToken(auth_token)
  98             multicall.unzipAttachment(PAGENAME)
  99             result = multicall()
 100             print "zip file '%s' on page '%s' unpacked: %s" % (ATTACHNAME,
 101                   PAGENAME, tuple(result)[0])
 102 
 103 def put_attachment():
 104     """"
 105     this script adds an attachment ATTACHNANE to a page
 106     currently the attachment name and the pagename is hard coded
 107     username NAME is read from an env var WIKIUSER
 108     """
 109     if NAME and PASSWORD and ATTACHNAME:
 110         xmlrpc_url = "%s?action=xmlrpc2" % WIKIURL
 111         homewiki = xmlrpclib.ServerProxy(xmlrpc_url, allow_none=True)
 112         multicall = xmlrpclib.MultiCall(homewiki)
 113         auth_token = homewiki.getAuthToken(NAME, PASSWORD)
 114         if auth_token:
 115             multicall.applyAuthToken(auth_token)
 116             text = file(ATTACHNAME, 'rb+').read()
 117             data = xmlrpclib.Binary(text)
 118             multicall.putAttachment(PAGENAME, ATTACHNAME, data)
 119             result = multicall()
 120             print "zip file '%s' on page '%s' saved: %s" % (ATTACHNAME,
 121                 PAGENAME, tuple(result)[0])
 122         else:
 123             print 'Wrong name: "%s" or password entered!' % NAME
 124     else:
 125         print 'Missing name or password'
 126 
 127 def del_attachment():
 128     """"
 129     this script deletes the ATTACHNAME from the wiki
 130     currently the attachment name and the pagename is hard coded
 131     username NAME is read from an env var WIKIUSER
 132     """
 133     if NAME and PASSWORD:
 134         xmlrpc_url = "%s?action=xmlrpc2" % WIKIURL
 135         homewiki = xmlrpclib.ServerProxy(xmlrpc_url, allow_none=True)
 136         multicall = xmlrpclib.MultiCall(homewiki)
 137         auth_token = homewiki.getAuthToken(NAME, PASSWORD)
 138         if auth_token:
 139             multicall.applyAuthToken(auth_token)
 140             multicall.delAttachment(PAGENAME, ATTACHNAME)
 141             result = multicall()
 142             print "file '%s' on page '%s' deleted: %s" % (ATTACHNAME,
 143                  PAGENAME, tuple(result)[0])
 144         else:
 145             print 'Wrong name: "%s" or password entered!' % NAME
 146     else:
 147         print 'Missing name or password'
 148 
 149 if __name__ == "__main__":
 150     put_attachment()
 151     unzip_attachment()
 152     put_page()
 153     del_attachment()
 154     rename_page()

xmlrpc_collection_scripts.py

slightly different implemented in http://hg.moinmo.in/moin/1.9/rev/a5bd554abd87


CategoryFeatureImplemented

MoinMoin: FeatureRequests/Extend XMLRPC (last edited 2009-12-08 14:04:04 by ReimarBauer)