changeset 1303:a0b8e78621d0

Preliminary support for items of different mime types.
author Alexander Schremmer <alex AT alexanderweb DOT de>
date Wed, 16 Aug 2006 22:09:22 +0200
parents 7e0faeed44bc
children f103cf7c371e
files MoinMoin/action/SyncPages.py MoinMoin/wikisync.py docs/CHANGES.aschremmer
diffstat 3 files changed, 40 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/action/SyncPages.py	Wed Aug 16 00:03:29 2006 +0200
+++ b/MoinMoin/action/SyncPages.py	Wed Aug 16 22:09:22 2006 +0200
@@ -25,7 +25,7 @@
 from MoinMoin.Page import Page
 from MoinMoin.wikidicts import Dict, Group
 from MoinMoin.wikisync import TagStore, UnsupportedWikiException, SyncPage
-from MoinMoin.wikisync import MoinLocalWiki, MoinRemoteWiki, UP, DOWN, BOTH
+from MoinMoin.wikisync import MoinLocalWiki, MoinRemoteWiki, UP, DOWN, BOTH, MIMETYPE_MOIN
 from MoinMoin.util.bdiff import decompress, patch, compress, textdiff
 from MoinMoin.util import diff3
 
@@ -162,9 +162,12 @@
                           | matching |
                           | tags     |
                 ----------+----------+-------------------------------
+                exists    | exists   | already handled.
         """
         _ = self.request.getText
         direction = params["direction"]
+        local_full_iwid = packLine([local.get_iwid(), local.get_interwiki_name()])
+        remote_full_iwid = packLine([remote.get_iwid(), remote.get_interwiki_name()])
 
         l_pages = local.get_pages()
         r_pages = remote.get_pages(exclude_non_writable=direction != DOWN)
@@ -221,6 +224,12 @@
                 remote_rev = newest_tag.remote_rev
                 if remote_rev == rp.remote_rev and (direction == DOWN or local_rev == current_rev):
                     continue # no changes done, next page
+                if rp.local_mime_type != MIMETYPE_MOIN and not (remote_rev == rp.remote_rev ^ local_rev == current_rev):
+                    self.log_status(ActionClass.WARN, _("The item %(pagename)s cannot be merged but was changed in both wikis. Please delete it in one of both wikis and try again.") % {"pagename": rp.name})
+                    continue
+                if rp.local_mime_type != rp.remote_mime_type:
+                    self.log_status(ActionClass.WARN, _("The item %(pagename)s has different mime types in both wikis and cannot be merged. Please delete it in one of both wikis or unify the mime type, and try again.") % {"pagename": rp.name})
+                    continue
                 old_contents = Page(self.request, local_pagename, rev=local_rev).get_raw_body_str() # YYY direct access
 
             self.log_status(ActionClass.INFO, _("Synchronising page %(pagename)s with remote page %(remotepagename)s ...") % {"pagename": local_pagename, "remotepagename": rp.remote_name})
@@ -239,12 +248,15 @@
                 current_remote_rev = diff_result["current"]
             else:
                 current_remote_rev = remote_rev
-                is_remote_conflict = wikiutil.containsConflictMarker(old_contents.decode("utf-8"))
+                if rp.local_mime_type == MIMETYPE_MOIN:
+                    is_remote_conflict = wikiutil.containsConflictMarker(old_contents.decode("utf-8"))
+                else:
+                    is_remote_conflict = NotImplemented
                 diff = None
 
             # do not sync if the conflict is remote and local, or if it is local
             # and the page has never been syncronised
-            if (wikiutil.containsConflictMarker(current_page.get_raw_body())
+            if (rp.local_mime_type == MIMETYPE_MOIN and wikiutil.containsConflictMarker(current_page.get_raw_body())
                 and (remote_rev is None or is_remote_conflict)):
                 self.log_status(ActionClass.WARN, _("Skipped page %(pagename)s because of a locally or remotely unresolved conflict.") % {"pagename": local_pagename})
                 continue
@@ -253,18 +265,23 @@
                 self.log_status(ActionClass.INFO, _("This is the first synchronisation between this page and the remote wiki."))
 
             if diff is None:
-                new_contents = old_contents.decode("utf-8")
+                new_contents = old_contents
             else:
-                new_contents = patch(patch_base_contents, decompress(diff)).decode("utf-8")
+                new_contents = patch(patch_base_contents, decompress(diff))
 
-            # here, the actual merge happens
-            # XXX print "Merging %r, %r and %r" % (old_contents.decode("utf-8"), new_contents, current_page.get_raw_body())
-            verynewtext = diff3.text_merge(old_contents.decode("utf-8"), new_contents, current_page.get_raw_body(), 2, *conflict_markers)
+            if rp.local_mime_type == MIMETYPE_MOIN:
+                new_contents_unicode = new_contents.decode("utf-8")
+                # here, the actual merge happens
+                # XXX print "Merging %r, %r and %r" % (old_contents.decode("utf-8"), new_contents, current_page.get_raw_body())
+                verynewtext = diff3.text_merge(old_contents.decode("utf-8"), new_contents_unicode, current_page.get_raw_body(), 2, *conflict_markers)
+                verynewtext_raw = verynewtext.encode("utf-8")
+            else:
+                if diff is None:
+                    verynewtext_raw = new_contents
+                else:
+                    verynewtext_raw = current_page.get_raw_body_str()
 
-            local_full_iwid = packLine([local.get_iwid(), local.get_interwiki_name()])
-            remote_full_iwid = packLine([remote.get_iwid(), remote.get_interwiki_name()])
-
-            diff = textdiff(new_contents.encode("utf-8"), verynewtext.encode("utf-8"))
+            diff = textdiff(new_contents, verynewtext_raw)
             #print "Diff against %r" % new_contents.encode("utf-8")
 
             comment = u"Local Merge - %r" % (remote.get_interwiki_name() or remote.get_iwid())
@@ -289,7 +306,7 @@
 
             tags.add(remote_wiki=remote_full_iwid, remote_rev=very_current_remote_rev, current_rev=new_local_rev, direction=direction, normalised_name=rp.name)
 
-            if not wikiutil.containsConflictMarker(verynewtext):
+            if rp.local_mime_type != MIMETYPE_MOIN or not wikiutil.containsConflictMarker(verynewtext):
                 self.log_status(ActionClass.INFO, _("Page successfully merged."))
             else:
                 self.log_status(ActionClass.WARN, _("Page merged with conflicts."))
--- a/MoinMoin/wikisync.py	Wed Aug 16 00:03:29 2006 +0200
+++ b/MoinMoin/wikisync.py	Wed Aug 16 22:09:22 2006 +0200
@@ -21,6 +21,7 @@
 from MoinMoin.packages import unpackLine, packLine
 
 
+MIMETYPE_MOIN = "text/wiki"
 # sync directions
 UP, DOWN, BOTH = range(3)
 
@@ -58,6 +59,8 @@
         self.remote_name = remote_name
         assert local_rev or remote_rev
         assert local_name or remote_name
+        self.local_mime_type = MIMETYPE_MOIN   # XXX no usable storage API yet
+        self.remote_mime_type = MIMETYPE_MOIN
 
     def __repr__(self):
         return repr("<Remote Page %r>" % unicode(self))
@@ -107,6 +110,7 @@
             if sp in d:
                 d[sp].remote_rev = sp.remote_rev
                 d[sp].remote_name = sp.remote_name
+                # XXX merge mime type here
             else:
                 d[sp] = sp
         return d.keys()
--- a/docs/CHANGES.aschremmer	Wed Aug 16 00:03:29 2006 +0200
+++ b/docs/CHANGES.aschremmer	Wed Aug 16 22:09:22 2006 +0200
@@ -13,14 +13,14 @@
     * Reduce round-trip times by caching queries and using MultiCall objects (coroutines?)
     * Attach the status information to the job page.
     * Show tags in an action=info view?
+    * Check what needs to be documented on MoinMaster.
+    * Search for XXX
+    * Maybe refactor YYY into MoinLocalWiki
+    * Remove amount of "very" in the code
     * Implement a cross-site authentication system, i.e. mainly an
       identity storage. (does OpenID make sense?)
     * Clean up trailing whitespace.
     * Add page locking, i.e. use the one in the new storage layer.
-    * Check what needs to be documented on MoinMaster.
-    * Search for XXX
-    * Maybe refactor YYY into MoinLocalWiki
-    * Remove amount of "very" in the code
     * Do older tags of one wiki site have to be stored as well? Why don't we
       keep just one tag?
     * Put author names into the comment field, transmit mimetypes.
@@ -107,7 +107,8 @@
          either of both components when searching for tags. Ignore underlay pages. Filter the remote page list by
          the prefix and the pageList on the remote side. Finished the direction==DOWN mode.
          Started designing the solutions for the other sync cases. Store and transmit the
-         normalised name.
+         normalised name. Implemented preliminary mime type support, only transmission of the mime type
+         and the new storage API is missing.
 
 2006-07-18: the requested daily entry is missing here, see http://moinmoin.wikiwikiweb.de/GoogleSoc2006/BetterProgress
 2006-07-19: the requested daily entry is missing here, see http://moinmoin.wikiwikiweb.de/GoogleSoc2006/BetterProgress