diff MoinMoin/action/SyncPages.py @ 976:a442ed63b165

Reordered class hierachy of remote wikis, enhanced RemoteWiki interface
author Alexander Schremmer <alex AT alexanderweb DOT de>
date Sat, 15 Jul 2006 19:46:58 +0200
parents d24f2b1d606a
children b258156f1288
line wrap: on
line diff
--- a/MoinMoin/action/SyncPages.py	Sat Jul 15 19:33:12 2006 +0200
+++ b/MoinMoin/action/SyncPages.py	Sat Jul 15 19:46:58 2006 +0200
@@ -10,6 +10,7 @@
 
 import os
 import zipfile
+import xmlrpclib
 from datetime import datetime
 
 from MoinMoin import wikiutil, config, user
@@ -20,11 +21,30 @@
 class ActionStatus(Exception): pass
 
 class RemoteWiki(object):
+    """ This class should be the base for all implementations of remote wiki
+        classes. """
+    def getInterwikiName(self):
+        """ Returns the interwiki name of the other wiki. """
+        return NotImplemented
+    
+    def __repr__(self):
+        """ Returns a representation of the instance for debugging purposes. """
+        return NotImplemented
+
+class MoinWiki(RemoteWiki):
     def __init__(self, interwikiname):
         wikitag, wikiurl, wikitail, wikitag_bad = wikiutil.resolve_wiki(self.request, '%s:""' % (interwikiname, ))
         self.wiki_url = wikiutil.mapURL(self.request, wikiurl)
         self.valid = not wikitag_bad
         self.xmlrpc_url = self.wiki_url + "?action=xmlrpc2"
+        self.connection = self.createConnection()
+
+    def createConnection(self):
+        return xmlrpclib.ServerProxy(self.xmlrpc_url, allow_none=True)
+
+    # Methods implementing the RemoteWiki interface
+    def getInterwikiName(self):
+        return self.connection.interwikiName()
 
     def __repr__(self):
         return "<RemoteWiki wiki_url=%r valid=%r>" % (self.valid, self.wiki_url)
@@ -56,10 +76,13 @@
         params = self.parsePage()
         
         try:
+            if not self.request.cfg.interwikiname:
+                raise ActionStatus(_("Please set an interwikiname in your wikiconfig (see HelpOnConfiguration) to be able to use this action."))
+
             if not params["remoteWiki"]:
                 raise ActionStatus(_("Incorrect parameters. Please supply at least the ''remoteWiki'' parameter."))
             
-            remote = RemoteWiki(params["remoteWiki"])
+            remote = MoinWiki(params["remoteWiki"])
             
             if not remote.valid:
                 raise ActionStatus(_("The ''remoteWiki'' is unknown."))