comparison MoinMoin/action/SyncPages.py @ 1330:df88b475c1f0

Reworked debugging.
author Alexander Schremmer <alex AT alexanderweb DOT de>
date Sat, 19 Aug 2006 16:18:19 +0200
parents 4a8c4849d162
children 16a854a172c9
comparison
equal deleted inserted replaced
1329:4a8c4849d162 1330:df88b475c1f0
27 from MoinMoin.wikisync import TagStore, UnsupportedWikiException, SyncPage 27 from MoinMoin.wikisync import TagStore, UnsupportedWikiException, SyncPage
28 from MoinMoin.wikisync import MoinLocalWiki, MoinRemoteWiki, UP, DOWN, BOTH, MIMETYPE_MOIN 28 from MoinMoin.wikisync import MoinLocalWiki, MoinRemoteWiki, UP, DOWN, BOTH, MIMETYPE_MOIN
29 from MoinMoin.util.bdiff import decompress, patch, compress, textdiff 29 from MoinMoin.util.bdiff import decompress, patch, compress, textdiff
30 from MoinMoin.util import diff3 30 from MoinMoin.util import diff3
31 31
32
33 debug = True
32 34
33 # map sync directions 35 # map sync directions
34 directions_map = {"up": UP, "down": DOWN, "both": BOTH} 36 directions_map = {"up": UP, "down": DOWN, "both": BOTH}
35 37
36 38
126 if not params["remoteWiki"]: 128 if not params["remoteWiki"]:
127 raise ActionStatus(_("Incorrect parameters. Please supply at least the ''remoteWiki'' parameter.")) 129 raise ActionStatus(_("Incorrect parameters. Please supply at least the ''remoteWiki'' parameter."))
128 130
129 local = MoinLocalWiki(self.request, params["localPrefix"], params["pageList"]) 131 local = MoinLocalWiki(self.request, params["localPrefix"], params["pageList"])
130 try: 132 try:
131 remote = MoinRemoteWiki(self.request, params["remoteWiki"], params["remotePrefix"], params["pageList"]) 133 remote = MoinRemoteWiki(self.request, params["remoteWiki"], params["remotePrefix"], params["pageList"], verbose=debug)
132 except UnsupportedWikiException, (msg, ): 134 except UnsupportedWikiException, (msg, ):
133 raise ActionStatus(msg) 135 raise ActionStatus(msg)
134 136
135 if not remote.valid: 137 if not remote.valid:
136 raise ActionStatus(_("The ''remoteWiki'' is unknown.")) 138 raise ActionStatus(_("The ''remoteWiki'' is unknown."))
213 215
214 def handle_page(rp): 216 def handle_page(rp):
215 # let's do the simple case first, can be refactored later to match all cases 217 # let's do the simple case first, can be refactored later to match all cases
216 # XXX handle deleted pages 218 # XXX handle deleted pages
217 # XXX add locking, acquire read-lock on rp 219 # XXX add locking, acquire read-lock on rp
218 # XXX print "Processing %r" % rp 220 if debug:
221 self.log_status(ActionClass.INFO, "Processing %r" % rp)
219 222
220 local_pagename = rp.local_name 223 local_pagename = rp.local_name
221 current_page = PageEditor(self.request, local_pagename) # YYY direct access 224 current_page = PageEditor(self.request, local_pagename) # YYY direct access
222 current_rev = current_page.get_real_rev() 225 current_rev = current_page.get_real_rev()
223 226
224 tags = TagStore(current_page) 227 tags = TagStore(current_page)
225 228
226 matching_tags = tags.fetch(iwid_full=remote.iwid_full, direction=match_direction) 229 matching_tags = tags.fetch(iwid_full=remote.iwid_full, direction=match_direction)
227 matching_tags.sort() 230 matching_tags.sort()
228 # print "------ TAGS: " + repr(matching_tags) + repr(tags.tags) XXX 231 if debug:
232 self.log_status(ActionClass.INFO, "Tags: %r [[BR]] All: %r" % (matching_tags, tags.tags))
229 233
230 # some default values for non matching tags 234 # some default values for non matching tags
231 normalised_name = None 235 normalised_name = None
232 remote_rev = None 236 remote_rev = None
233 local_rev = rp.local_rev # merge against the newest version 237 local_rev = rp.local_rev # merge against the newest version
294 new_contents = patch(patch_base_contents, decompress(diff)) 298 new_contents = patch(patch_base_contents, decompress(diff))
295 299
296 if rp.local_mime_type == MIMETYPE_MOIN: 300 if rp.local_mime_type == MIMETYPE_MOIN:
297 new_contents_unicode = new_contents.decode("utf-8") 301 new_contents_unicode = new_contents.decode("utf-8")
298 # here, the actual merge happens 302 # here, the actual merge happens
299 # XXX 303 if debug:
300 # print "Merging %r, %r and %r" % (old_contents.decode("utf-8"), new_contents, current_page.get_raw_body()) 304 self.log_status(ActionClass.INFO, "Merging %r, %r and %r" % (old_contents.decode("utf-8"), new_contents_unicode, current_page.get_raw_body()))
301 verynewtext = diff3.text_merge(old_contents.decode("utf-8"), new_contents_unicode, current_page.get_raw_body(), 2, *conflict_markers) 305 verynewtext = diff3.text_merge(old_contents.decode("utf-8"), new_contents_unicode, current_page.get_raw_body(), 2, *conflict_markers)
302 verynewtext_raw = verynewtext.encode("utf-8") 306 verynewtext_raw = verynewtext.encode("utf-8")
303 else: 307 else:
304 if diff is None: 308 if diff is None:
305 verynewtext_raw = new_contents 309 verynewtext_raw = new_contents
306 else: 310 else:
307 verynewtext_raw = current_page.get_raw_body_str() 311 verynewtext_raw = current_page.get_raw_body_str()
308 312
309 diff = textdiff(new_contents, verynewtext_raw) 313 diff = textdiff(new_contents, verynewtext_raw)
310 # print "Diff against %r" % new_contents.encode("utf-8") # XXX 314 if debug:
315 self.log_status(ActionClass.INFO, "Diff against %r" % new_contents.encode("utf-8"))
311 316
312 comment = u"Local Merge - %r" % (remote.get_interwiki_name() or remote.get_iwid()) 317 comment = u"Local Merge - %r" % (remote.get_interwiki_name() or remote.get_iwid())
313 318
314 # XXX upgrade to write lock 319 # XXX upgrade to write lock
315 try: 320 try:
336 else: 341 else:
337 self.log_status(ActionClass.WARN, _("Page merged with conflicts.")) 342 self.log_status(ActionClass.WARN, _("Page merged with conflicts."))
338 343
339 # XXX release lock 344 # XXX release lock
340 345
341 on_both_sides = list(SyncPage.iter_local_and_remote(m_pages)) 346 # XXX remove?
342 remote_but_not_local = list(SyncPage.iter_remote_only(m_pages)) 347 #on_both_sides = SyncPage.iter_local_and_remote(m_pages)
343 local_but_not_remote = list(SyncPage.iter_local_only(m_pages)) 348 #remote_but_not_local = SyncPage.iter_remote_only(m_pages)
349 #local_but_not_remote = SyncPage.iter_local_only(m_pages)
344 350
345 # some initial test code (XXX remove) 351 # some initial test code (XXX remove)
346 #r_new_pages = u", ".join([unicode(x) for x in remote_but_not_local]) 352 #r_new_pages = u", ".join([unicode(x) for x in remote_but_not_local])
347 #l_new_pages = u", ".join([unicode(x) for x in local_but_not_remote]) 353 #l_new_pages = u", ".join([unicode(x) for x in local_but_not_remote])
348 #raise ActionStatus("These pages are in the remote wiki, but not local: " + wikiutil.escape(r_new_pages) + "<br>These pages are in the local wiki, but not in the remote one: " + wikiutil.escape(l_new_pages)) 354 #raise ActionStatus("These pages are in the remote wiki, but not local: " + wikiutil.escape(r_new_pages) + "<br>These pages are in the local wiki, but not in the remote one: " + wikiutil.escape(l_new_pages))