changeset 1349:4d2dd952a513

Refactoring: Renamed rp to sp in SyncPages.
author Alexander Schremmer <alex AT alexanderweb DOT de>
date Sun, 20 Aug 2006 16:10:16 +0200
parents baafe28d8037
children 650a2dc16b19
files MoinMoin/action/SyncPages.py docs/CHANGES.aschremmer
diffstat 2 files changed, 40 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/action/SyncPages.py	Sun Aug 20 15:58:49 2006 +0200
+++ b/MoinMoin/action/SyncPages.py	Sun Aug 20 16:10:16 2006 +0200
@@ -205,12 +205,12 @@
             m_pages = SyncPage.filter(m_pages, params["pageMatch"].match)
             self.log_status(self.INFO, _("After filtering: %s pages"), (str(len(m_pages)), ))
 
-        def handle_page(rp):
-            # XXX add locking, acquire read-lock on rp
+        def handle_page(sp):
+            # XXX add locking, acquire read-lock on sp
             if debug:
-                self.log_status(ActionClass.INFO, raw_suffix="Processing %r" % rp)
+                self.log_status(ActionClass.INFO, raw_suffix="Processing %r" % sp)
 
-            local_pagename = rp.local_name
+            local_pagename = sp.local_name
             current_page = PageEditor(self.request, local_pagename) # YYY direct access
             comment = u"Local Merge - %r" % (remote.get_interwiki_name() or remote.get_iwid())
 
@@ -224,51 +224,51 @@
             # some default values for non matching tags
             normalised_name = None
             remote_rev = None
-            local_rev = rp.local_rev # merge against the newest version
+            local_rev = sp.local_rev # merge against the newest version
             old_contents = ""
 
             if matching_tags:
                 newest_tag = matching_tags[-1]
 
-                local_change = newest_tag.current_rev != rp.local_rev
-                remote_change = newest_tag.remote_rev != rp.remote_rev
+                local_change = newest_tag.current_rev != sp.local_rev
+                remote_change = newest_tag.remote_rev != sp.remote_rev
 
                 # handle some cases where we cannot continue for this page
                 if not remote_change and (direction == DOWN or not local_change):
                     return # no changes done, next page
-                if rp.local_deleted and rp.remote_deleted:
+                if sp.local_deleted and sp.remote_deleted:
                     return
-                if rp.remote_deleted and not local_change:
-                    msg = local.delete_page(rp.local_name, comment)
+                if sp.remote_deleted and not local_change:
+                    msg = local.delete_page(sp.local_name, comment)
                     if not msg:
-                        self.log_status(ActionClass.INFO, _("Deleted page %s locally."), (rp.name, ))
+                        self.log_status(ActionClass.INFO, _("Deleted page %s locally."), (sp.name, ))
                     else:
-                        self.log_status(ActionClass.ERROR, _("Error while deleting page %s locally:"), (rp.name, ), msg)
+                        self.log_status(ActionClass.ERROR, _("Error while deleting page %s locally:"), (sp.name, ), msg)
                     return
-                if rp.local_deleted and not remote_change:
+                if sp.local_deleted and not remote_change:
                     if direction == DOWN:
                         return
-                    msg = remote.delete_page(rp.remote_name, rp.remote_rev, local_full_iwid)
+                    msg = remote.delete_page(sp.remote_name, sp.remote_rev, local_full_iwid)
                     if not msg:
-                        self.log_status(ActionClass.INFO, _("Deleted page %s remotely."), (rp.name, ))
+                        self.log_status(ActionClass.INFO, _("Deleted page %s remotely."), (sp.name, ))
                     else:
-                        self.log_status(ActionClass.ERROR, _("Error while deleting page %s remotely:"), (rp.name, ), msg)
+                        self.log_status(ActionClass.ERROR, _("Error while deleting page %s remotely:"), (sp.name, ), msg)
                     return
-                if rp.local_mime_type != MIMETYPE_MOIN and not (local_change ^ remote_change):
-                    self.log_status(ActionClass.WARN, _("The item %s cannot be merged but was changed in both wikis. Please delete it in one of both wikis and try again."), (rp.name, ))
+                if sp.local_mime_type != MIMETYPE_MOIN and not (local_change ^ remote_change):
+                    self.log_status(ActionClass.WARN, _("The item %s cannot be merged but was changed in both wikis. Please delete it in one of both wikis and try again."), (sp.name, ))
                     return
-                if rp.local_mime_type != rp.remote_mime_type:
-                    self.log_status(ActionClass.WARN, _("The item %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."), (rp.name, ))
+                if sp.local_mime_type != sp.remote_mime_type:
+                    self.log_status(ActionClass.WARN, _("The item %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."), (sp.name, ))
                     return
-                if newest_tag.normalised_name != rp.name:
-                    self.log_status(ActionClass.WARN, _("The item %s was renamed locally. This is not implemented yet. Therefore the full syncronisation history is lost for this page."), (rp.name, )) # XXX implement renames
+                if newest_tag.normalised_name != sp.name:
+                    self.log_status(ActionClass.WARN, _("The item %s was renamed locally. This is not implemented yet. Therefore the full syncronisation history is lost for this page."), (sp.name, )) # XXX implement renames
                 else:
                     normalised_name = newest_tag.normalised_name
                     local_rev = newest_tag.current_rev
                     remote_rev = newest_tag.remote_rev
                     old_contents = Page(self.request, local_pagename, rev=newest_tag.current_rev).get_raw_body_str() # YYY direct access
 
-            self.log_status(ActionClass.INFO, _("Synchronising page %s with remote page %s ..."), (local_pagename, rp.remote_name))
+            self.log_status(ActionClass.INFO, _("Synchronising page %s with remote page %s ..."), (local_pagename, sp.remote_name))
 
             if direction == DOWN:
                 remote_rev = None # always fetch the full page, ignore remote conflict check
@@ -276,16 +276,16 @@
             else:
                 patch_base_contents = old_contents
 
-            if remote_rev != rp.remote_rev:
-                if rp.remote_deleted: # ignore remote changes
-                    current_remote_rev = rp.remote_rev
+            if remote_rev != sp.remote_rev:
+                if sp.remote_deleted: # ignore remote changes
+                    current_remote_rev = sp.remote_rev
                     is_remote_conflict = False
                     diff = None
-                    self.log_status(ActionClass.WARN, _("The page %s was deleted remotely but changed locally."), (rp.name, ))
+                    self.log_status(ActionClass.WARN, _("The page %s was deleted remotely but changed locally."), (sp.name, ))
                 else:
-                    diff_result = remote.get_diff(rp.remote_name, remote_rev, None, normalised_name)
+                    diff_result = remote.get_diff(sp.remote_name, remote_rev, None, normalised_name)
                     if diff_result is None:
-                        self.log_status(ActionClass.ERROR, _("The page %s could not be synced. The remote page was renamed. This is not supported yet. You may want to delete one of the pages to get it synced."), (rp.remote_name, ))
+                        self.log_status(ActionClass.ERROR, _("The page %s could not be synced. The remote page was renamed. This is not supported yet. You may want to delete one of the pages to get it synced."), (sp.remote_name, ))
                         return
                     is_remote_conflict = diff_result["conflict"]
                     assert diff_result["diffversion"] == 1
@@ -293,7 +293,7 @@
                     current_remote_rev = diff_result["current"]
             else:
                 current_remote_rev = remote_rev
-                if rp.local_mime_type == MIMETYPE_MOIN:
+                if sp.local_mime_type == MIMETYPE_MOIN:
                     is_remote_conflict = wikiutil.containsConflictMarker(old_contents.decode("utf-8"))
                 else:
                     is_remote_conflict = NotImplemented
@@ -301,7 +301,7 @@
 
             # do not sync if the conflict is remote and local, or if it is local
             # and the page has never been syncronised
-            if (rp.local_mime_type == MIMETYPE_MOIN and wikiutil.containsConflictMarker(current_page.get_raw_body())
+            if (sp.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 %s because of a locally or remotely unresolved conflict."), (local_pagename, ))
                 return
@@ -309,14 +309,14 @@
             if remote_rev is None and direction == BOTH:
                 self.log_status(ActionClass.INFO, _("This is the first synchronisation between this page and the remote wiki."))
 
-            if rp.remote_deleted:
+            if sp.remote_deleted:
                 new_contents = ""
             elif diff is None:
                 new_contents = old_contents
             else:
                 new_contents = patch(patch_base_contents, decompress(diff))
 
-            if rp.local_mime_type == MIMETYPE_MOIN:
+            if sp.local_mime_type == MIMETYPE_MOIN:
                 new_contents_unicode = new_contents.decode("utf-8")
                 # here, the actual 3-way merge happens
                 if debug:
@@ -335,7 +335,7 @@
 
             # XXX upgrade to write lock
             try:
-                current_page.saveText(verynewtext, rp.local_rev, comment=comment) # YYY direct access
+                current_page.saveText(verynewtext, sp.local_rev, comment=comment) # YYY direct access
             except PageEditor.Unchanged:
                 pass
             except PageEditor.EditConflict:
@@ -345,23 +345,23 @@
 
             if direction == BOTH:
                 try:
-                    very_current_remote_rev = remote.merge_diff(rp.remote_name, compress(diff), new_local_rev, current_remote_rev, current_remote_rev, local_full_iwid, rp.name)
+                    very_current_remote_rev = remote.merge_diff(sp.remote_name, compress(diff), new_local_rev, current_remote_rev, current_remote_rev, local_full_iwid, sp.name)
                 except Exception, e:
                     raise # XXX rollback locally and do not tag locally
             else:
                 very_current_remote_rev = current_remote_rev
 
-            tags.add(remote_wiki=remote_full_iwid, remote_rev=very_current_remote_rev, current_rev=new_local_rev, direction=direction, normalised_name=rp.name)
+            tags.add(remote_wiki=remote_full_iwid, remote_rev=very_current_remote_rev, current_rev=new_local_rev, direction=direction, normalised_name=sp.name)
 
-            if rp.local_mime_type != MIMETYPE_MOIN or not wikiutil.containsConflictMarker(verynewtext):
+            if sp.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."))
 
             # XXX release lock
 
-        for rp in m_pages:
-            handle_page(rp)
+        for sp in m_pages:
+            handle_page(sp)
 
 
 def execute(pagename, request):
--- a/docs/CHANGES.aschremmer	Sun Aug 20 15:58:49 2006 +0200
+++ b/docs/CHANGES.aschremmer	Sun Aug 20 16:10:16 2006 +0200
@@ -16,7 +16,7 @@
     * Test with prefixes
     * Search for XXX
     * Maybe refactor YYY into MoinLocalWiki
-    * Remove amount of "very" in the code, rename rp into sp
+    * Remove amount of "very" in the code
 
     * Implement a cross-site authentication system, i.e. mainly an
       identity storage. (does OpenID make sense?)