changeset 1020:86f141856d2b

Finished first version of the mergeChanges method.
author Alexander Schremmer <alex AT alexanderweb DOT de>
date Wed, 19 Jul 2006 00:59:02 +0200
parents f56db9746839
children 05629312d4d7
files MoinMoin/xmlrpc/__init__.py docs/CHANGES.aschremmer
diffstat 2 files changed, 33 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/xmlrpc/__init__.py	Mon Jul 17 13:29:58 2006 +0200
+++ b/MoinMoin/xmlrpc/__init__.py	Wed Jul 19 00:59:02 2006 +0200
@@ -498,6 +498,7 @@
         from MoinMoin import version
         return (version.project, version.release, version.revision)
 
+
     # authorization methods
     
     def xmlrpc_getAuthToken(self, username, password, *args):
@@ -518,7 +519,10 @@
             return "SUCCESS"
         else:
             return xmlrpclib.Fault("INVALID", "Invalid token.")
-    
+
+
+    # methods for wiki synchronization
+
     def xmlrpc_getDiff(self, pagename, from_rev, to_rev):
         """ Gets the binary difference between two page revisions. See MoinMoin:WikiSyncronisation. """
         from MoinMoin.util.bdiff import textdiff, compress
@@ -594,9 +598,13 @@
             @param interwiki_name: Used to build the interwiki tag.
         """
         from MoinMoin.util.bdiff import decompress, patch
+        from MoinMoin.wikisync import TagStore
+        LASTREV_INVALID = xmlrpclib.Fault("LASTREV_INVALID", "The page was changed")
         
         pagename = self._instr(pagename)
        
+        comment = u"Remote - %r" % interwiki_name
+        
         # User may read page?
         if not self.request.user.may.read(pagename) or not self.request.user.may.write(pagename):
             return self.notAllowedFault()
@@ -604,10 +612,10 @@
         # XXX add locking here!
         
         # current version of the page
-        currentpage = Page(self.request, pagename)
+        currentpage = PageEditor(self.request, pagename, do_editor_backup=0)
 
         if currentpage.get_real_rev() != last_remote_rev:
-            return xmlrpclib.Fault("LASTREV_INVALID", "The page was changed")
+            return LASTREV_INVALID
         
         if not currentpage.exists() and diff is None:
             return xmlrpclib.Fault("NOT_EXIST", "The page does not exist and no diff was supplied.")
@@ -619,13 +627,22 @@
         newcontents = patch(basepage.get_raw_body_str(), decompress(str(diff)))
         
         # write page
-        # XXX ...
+        try:
+            page.saveText(newcontents.encode("utf-8"), last_remote_rev, comment=comment)
+            page.clean_acl_cache()
+        except PageEditor.EditConflict:
+            return LASTREV_INVALID
+
+        current_rev = page.get_real_rev()
         
-        # XXX add a tag (interwiki_name, local_rev, current rev) to the page
-        # XXX return current rev
-        # XXX finished
-        
-        
+        tags = TagStore(currentpage)
+        tags.add(remote_wiki=interwiki_name, remote_rev=local_rev, current_rev=current_rev)
+
+        # XXX unlock page
+
+        return current_rev
+
+
     # XXX BEGIN WARNING XXX
     # All xmlrpc_*Attachment* functions have to be considered as UNSTABLE API -
     # they are neither standard nor are they what we need when we have switched
--- a/docs/CHANGES.aschremmer	Mon Jul 17 13:29:58 2006 +0200
+++ b/docs/CHANGES.aschremmer	Wed Jul 19 00:59:02 2006 +0200
@@ -2,7 +2,8 @@
 ===============================
 
   Known main issues:
-    * ...
+    * How will we store tags?
+    * How to handle renames/deletes?
 
   ToDo:
     * Implement actual syncronisation.
@@ -11,7 +12,6 @@
     * Clean up trailing whitespace.
     * Add page locking.
     * How about using unique IDs that just derive from the interwikiname?
-    * How to handle renames?
 
   New Features:
     * XMLRPC method to return the Moin version
@@ -20,7 +20,9 @@
     * XMLRPC Authentication System
     * Binary Diffing
     * XMLRPC method to get binary diffs
-    * 
+    * XMLRPC method to merge remote changes locally
+    * XMLRPC method to get the interwiki name
+    * TagStore class
 
   Bugfixes (only stuff that is buggy in moin/1.6 main branch):
     * Conflict resolution fixes.
@@ -58,6 +60,8 @@
 Week 28: Debian-Edu Developer Camp. Implemented getDiff XMLRPC method, added preliminary SyncPages action,
          added interwikiName XMLRPC method, added mergeChanges XMLRPC method. Started analysis of the moinupdate
          script written by Stefan Merten.
+Week 29: Finished first version of the mergeChanges method. Added preliminary
+         Tag and TagStore classes.
 
 Time plan
 =========