changeset 1041:f9568edf1ff0

Introduced MoinLocalWiki class, added code that compares page lists for testing.
author Alexander Schremmer <alex AT alexanderweb DOT de>
date Sat, 22 Jul 2006 02:34:03 +0200
parents ad101845642b
children 9e5749f46b74
files MoinMoin/action/SyncPages.py
diffstat 1 files changed, 58 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/action/SyncPages.py	Sat Jul 22 02:33:00 2006 +0200
+++ b/MoinMoin/action/SyncPages.py	Sat Jul 22 02:34:03 2006 +0200
@@ -14,20 +14,36 @@
 import xmlrpclib
 from datetime import datetime
 
+# Compatiblity to Python 2.3
+try:
+    set
+except NameError:
+    from sets import Set as set
+
+
 from MoinMoin import wikiutil, config, user
 from MoinMoin.packages import unpackLine
 from MoinMoin.PageEditor import PageEditor
 from MoinMoin.Page import Page
 from MoinMoin.wikidicts import Dict
 
+
 class ActionStatus(Exception): pass
 
+
 class RemotePage(object):
     """ This class represents a page in (another) wiki. """
     def __init__(self, name, revno):
         self.name = name
         self.revno = revno
 
+    def __repr__(self):
+        return u"%s<%i>" % (self.name, self.revno)
+
+    def __lt__(self, other):
+        return self.name > other.name
+
+
 class RemoteWiki(object):
     """ This class should be the base for all implementations of remote wiki
         classes. """
@@ -40,12 +56,15 @@
         """ Returns the interwiki name of the other wiki. """
         return NotImplemented
 
-    def getRemotePages(self):
+    def getPages(self):
         """ Returns a list of RemotePage instances. """
         return NotImplemented
 
-class MoinWiki(RemoteWiki):
-    def __init__(self, interwikiname):
+
+class MoinRemoteWiki(RemoteWiki):
+    """ Used for MoinMoin wikis reachable via XMLRPC. """
+    def __init__(self, request, interwikiname):
+        self.request = request
         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
@@ -54,18 +73,39 @@
         # XXX add version and interwiki name checking!
 
     def createConnection(self):
-        return xmlrpclib.ServerProxy(self.xmlrpc_url, allow_none=True)
+        if self.valid:
+            return xmlrpclib.ServerProxy(self.xmlrpc_url, allow_none=True)
+        else:
+            return None
 
     # Methods implementing the RemoteWiki interface
     def getInterwikiName(self):
         return self.connection.interwikiName()
 
-    def getRemotePages(self):
-        pages = self.connection.getAllPagesEx({"include_revno": True})
+    def getPages(self):
+        pages = self.connection.getAllPagesEx({"include_revno": True, "include_deleted": True})
         return [RemotePage(unicode(name), revno) for name, revno in pages]
 
     def __repr__(self):
-        return "<RemoteWiki wiki_url=%r valid=%r>" % (self.valid, self.wiki_url)
+        return "<MoinRemoteWiki wiki_url=%r valid=%r>" % (self.wiki_url, self.valid)
+
+
+class MoinLocalWiki(RemoteWiki):
+    """ Used for the current MoinMoin wiki. """
+    def __init__(self, request):
+        self.request = request
+
+    # Methods implementing the RemoteWiki interface
+    def getInterwikiName(self):
+        return self.request.cfg.interwikiname
+
+    def getPages(self):
+        l_pages = [[x, Page(self.request, x).get_real_rev()] for x in self.request.rootpage.getPageList(exists=0)]
+        return [RemotePage(unicode(name), revno) for name, revno in l_pages]
+
+    def __repr__(self):
+        return "<MoinLocalWiki>"
+
 
 class ActionClass:
     def __init__(self, pagename, request):
@@ -126,21 +166,28 @@
             if not params["remoteWiki"]:
                 raise ActionStatus(_("Incorrect parameters. Please supply at least the ''remoteWiki'' parameter."))
 
-            remote = MoinWiki(params["remoteWiki"])
+            remote = MoinRemoteWiki(self.request, params["remoteWiki"])
+            local = MoinLocalWiki(self.request)
 
             if not remote.valid:
                 raise ActionStatus(_("The ''remoteWiki'' is unknown."))
 
-            self.sync(params, remote)
+            self.sync(params, local, remote)
         except ActionStatus, e:
             return self.page.send_page(self.request, msg=u'<p class="error">%s</p>\n' % (e.args[0], ))
 
         return self.page.send_page(self.request, msg=_("Syncronisation finished."))
     
-    def sync(self, params, remote):
+    def sync(self, params, local, remote):
         """ This method does the syncronisation work. """
         
-        r_pages = remote.getRemotePages()
+        r_pages = remote.getPages()
+        l_pages = local.getPages()
+
+        # some initial test code
+        r_new_pages = u",".join(set([repr(x) for x in r_pages]) - set([repr(x) for x in l_pages]))
+        raise ActionStatus("These pages are in the remote wiki, but not local: " + r_new_pages)
+
 
 def execute(pagename, request):
     ActionClass(pagename, request).render()