annotate MoinMoin/action/SyncPages.py @ 4397:64d9d0f74a6a

SyncPages: improve code readability
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Wed, 29 Oct 2008 05:25:29 +0100
parents a1a9ac307c0e
children 1c373ce7f3a4
rev   line source
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
2 """
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
3 MoinMoin - SyncPages action
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
4
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
5 This action allows you to synchronise pages of two wikis.
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
6
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
7 @copyright: 2006 MoinMoin:AlexanderSchremmer
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
8 @license: GNU GPL, see COPYING for details.
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
9 """
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
10
1030
807f80c76d81 Work on SyncPages. Fixed a few bugs, added new method to RemoteWiki, build regexes from the RemotePageList.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 977
diff changeset
11 import re
1410
107ca03adb3c Added transaction support and traceback recovery support to the action. In Python 2.5, we could use finally around yield ... but not in 2.3.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1407
diff changeset
12 import traceback
107ca03adb3c Added transaction support and traceback recovery support to the action. In Python 2.5, we could use finally around yield ... but not in 2.3.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1407
diff changeset
13 import StringIO # not relevant for speed, so we do not need cStringIO
107ca03adb3c Added transaction support and traceback recovery support to the action. In Python 2.5, we could use finally around yield ... but not in 2.3.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1407
diff changeset
14
1041
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
15
1791
6dd2e29acffe Eclipse PyDev Check: fixed lots of its errors and warnings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1777
diff changeset
16 from MoinMoin import wikiutil
1096
33927b0256ce Changed marshalling format of the full IWID, load full IWID into the RemoteWiki object.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1095
diff changeset
17 from MoinMoin.packages import unpackLine, packLine
1141
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
18 from MoinMoin.PageEditor import PageEditor, conflict_markers
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
19 from MoinMoin.Page import Page
1793
2a4caa295346 Eclipse PyDev Check: fixed lots of its errors and warnings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1792
diff changeset
20 from MoinMoin.wikidicts import Dict
1385
8bf6e48c6236 Added rollback and exception logging to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1352
diff changeset
21 from MoinMoin.wikisync import TagStore, UnsupportedWikiException, SyncPage, NotAllowedException
1303
a0b8e78621d0 Preliminary support for items of different mime types.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1299
diff changeset
22 from MoinMoin.wikisync import MoinLocalWiki, MoinRemoteWiki, UP, DOWN, BOTH, MIMETYPE_MOIN
2595
5e7b45489430 moved python2.3/2.4 compatibility code to MoinMoin.support.python_compatibility (thanks to Heinrich Wendel)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2252
diff changeset
23 from MoinMoin.support.python_compatibility import set
1141
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
24 from MoinMoin.util.bdiff import decompress, patch, compress, textdiff
1404
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
25 from MoinMoin.util import diff3, rpc_aggregator
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
26
1264
064778edb38c Started integration of direction DOWN support.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1263
diff changeset
27
1410
107ca03adb3c Added transaction support and traceback recovery support to the action. In Python 2.5, we could use finally around yield ... but not in 2.3.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1407
diff changeset
28 debug = False
1330
df88b475c1f0 Reworked debugging.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1329
diff changeset
29
1332
16a854a172c9 Implemented support for deleted pages, finished support for pages that are just in one wiki.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1330
diff changeset
30
1267
eb9e5e21b0e5 Implemented the DOWN direction, refactored direction handling. The synctags of older syncs are invalid now, you have to delete them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1266
diff changeset
31 # map sync directions
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
32 directions_map = {"up": UP, "down": DOWN, "both": BOTH}
1041
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
33
1135
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
34
1920
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1888
diff changeset
35 class ActionStatus(Exception):
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1888
diff changeset
36 pass
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
37
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
38
1320
a36c70e5f0dd Reworked i18n and logging support, from now on, the log is attached to the job page.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1304
diff changeset
39 class ActionClass(object):
a36c70e5f0dd Reworked i18n and logging support, from now on, the log is attached to the job page.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1304
diff changeset
40 INFO, WARN, ERROR = zip(range(3), ("", "<!>", "/!\\")) # used for logging
1158
353c493dfb77 Added local conflict detection, logging support to SyncPages, updated my CHANGES file.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1141
diff changeset
41
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
42 def __init__(self, pagename, request):
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
43 self.request = request
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
44 self.pagename = pagename
1320
a36c70e5f0dd Reworked i18n and logging support, from now on, the log is attached to the job page.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1304
diff changeset
45 self.page = PageEditor(request, pagename)
1158
353c493dfb77 Added local conflict detection, logging support to SyncPages, updated my CHANGES file.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1141
diff changeset
46 self.status = []
1410
107ca03adb3c Added transaction support and traceback recovery support to the action. In Python 2.5, we could use finally around yield ... but not in 2.3.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1407
diff changeset
47 self.rollback = set()
1158
353c493dfb77 Added local conflict detection, logging support to SyncPages, updated my CHANGES file.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1141
diff changeset
48
1332
16a854a172c9 Implemented support for deleted pages, finished support for pages that are just in one wiki.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1330
diff changeset
49 def log_status(self, level, message="", substitutions=(), raw_suffix=""):
1159
0432e8a9ba2f Added docstrings.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1158
diff changeset
50 """ Appends the message with a given importance level to the internal log. """
1320
a36c70e5f0dd Reworked i18n and logging support, from now on, the log is attached to the job page.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1304
diff changeset
51 self.status.append((level, message, substitutions, raw_suffix))
a36c70e5f0dd Reworked i18n and logging support, from now on, the log is attached to the job page.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1304
diff changeset
52
1410
107ca03adb3c Added transaction support and traceback recovery support to the action. In Python 2.5, we could use finally around yield ... but not in 2.3.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1407
diff changeset
53 def register_rollback(self, func):
107ca03adb3c Added transaction support and traceback recovery support to the action. In Python 2.5, we could use finally around yield ... but not in 2.3.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1407
diff changeset
54 self.rollback.add(func)
107ca03adb3c Added transaction support and traceback recovery support to the action. In Python 2.5, we could use finally around yield ... but not in 2.3.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1407
diff changeset
55
107ca03adb3c Added transaction support and traceback recovery support to the action. In Python 2.5, we could use finally around yield ... but not in 2.3.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1407
diff changeset
56 def remove_rollback(self, func):
107ca03adb3c Added transaction support and traceback recovery support to the action. In Python 2.5, we could use finally around yield ... but not in 2.3.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1407
diff changeset
57 self.rollback.remove(func)
107ca03adb3c Added transaction support and traceback recovery support to the action. In Python 2.5, we could use finally around yield ... but not in 2.3.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1407
diff changeset
58
107ca03adb3c Added transaction support and traceback recovery support to the action. In Python 2.5, we could use finally around yield ... but not in 2.3.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1407
diff changeset
59 def call_rollback_funcs(self):
107ca03adb3c Added transaction support and traceback recovery support to the action. In Python 2.5, we could use finally around yield ... but not in 2.3.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1407
diff changeset
60 _ = lambda x: x
107ca03adb3c Added transaction support and traceback recovery support to the action. In Python 2.5, we could use finally around yield ... but not in 2.3.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1407
diff changeset
61
107ca03adb3c Added transaction support and traceback recovery support to the action. In Python 2.5, we could use finally around yield ... but not in 2.3.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1407
diff changeset
62 for func in self.rollback:
107ca03adb3c Added transaction support and traceback recovery support to the action. In Python 2.5, we could use finally around yield ... but not in 2.3.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1407
diff changeset
63 try:
107ca03adb3c Added transaction support and traceback recovery support to the action. In Python 2.5, we could use finally around yield ... but not in 2.3.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1407
diff changeset
64 page_name = func()
107ca03adb3c Added transaction support and traceback recovery support to the action. In Python 2.5, we could use finally around yield ... but not in 2.3.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1407
diff changeset
65 self.log_status(self.INFO, _("Rolled back changes to the page %s."), (page_name, ))
1805
ebcebba1afb3 removed some unused attributes, used 'dummy' for dummies
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1799
diff changeset
66 except Exception:
1410
107ca03adb3c Added transaction support and traceback recovery support to the action. In Python 2.5, we could use finally around yield ... but not in 2.3.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1407
diff changeset
67 temp_file = StringIO.StringIO()
107ca03adb3c Added transaction support and traceback recovery support to the action. In Python 2.5, we could use finally around yield ... but not in 2.3.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1407
diff changeset
68 traceback.print_exc(file=temp_file)
107ca03adb3c Added transaction support and traceback recovery support to the action. In Python 2.5, we could use finally around yield ... but not in 2.3.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1407
diff changeset
69 self.log_status(self.ERROR, _("Exception while calling rollback function:"), raw_suffix=temp_file.getvalue())
107ca03adb3c Added transaction support and traceback recovery support to the action. In Python 2.5, we could use finally around yield ... but not in 2.3.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1407
diff changeset
70
1320
a36c70e5f0dd Reworked i18n and logging support, from now on, the log is attached to the job page.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1304
diff changeset
71 def generate_log_table(self):
a36c70e5f0dd Reworked i18n and logging support, from now on, the log is attached to the job page.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1304
diff changeset
72 """ Transforms self.status into a user readable table. """
a36c70e5f0dd Reworked i18n and logging support, from now on, the log is attached to the job page.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1304
diff changeset
73 table_line = u"|| %(smiley)s || %(message)s%(raw_suffix)s ||"
a36c70e5f0dd Reworked i18n and logging support, from now on, the log is attached to the job page.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1304
diff changeset
74 table = []
a36c70e5f0dd Reworked i18n and logging support, from now on, the log is attached to the job page.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1304
diff changeset
75
a36c70e5f0dd Reworked i18n and logging support, from now on, the log is attached to the job page.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1304
diff changeset
76 for line in self.status:
4397
64d9d0f74a6a SyncPages: improve code readability
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3690
diff changeset
77 level, message, substitutions, raw_suffix = line
64d9d0f74a6a SyncPages: improve code readability
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3690
diff changeset
78 if message:
64d9d0f74a6a SyncPages: improve code readability
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3690
diff changeset
79 if substitutions:
64d9d0f74a6a SyncPages: improve code readability
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3690
diff changeset
80 macro_args = [message] + list(substitutions)
2725
388204baf00f change [[macro]] to <<macro>> in all built-in markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2595
diff changeset
81 message = u"<<GetText2(|%s)>>" % (packLine(macro_args), )
1393
e6e054247a58 Disabled debug mode, output GetText as well if GetText2 is not necessary, refactored my CHANGES file.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1391
diff changeset
82 else:
4397
64d9d0f74a6a SyncPages: improve code readability
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3690
diff changeset
83 message = u"<<GetText(%s)>>" % (message, )
1393
e6e054247a58 Disabled debug mode, output GetText as well if GetText2 is not necessary, refactored my CHANGES file.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1391
diff changeset
84 else:
e6e054247a58 Disabled debug mode, output GetText as well if GetText2 is not necessary, refactored my CHANGES file.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1391
diff changeset
85 message = u""
4397
64d9d0f74a6a SyncPages: improve code readability
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3690
diff changeset
86 table.append(table_line % {"smiley": level[1],
1393
e6e054247a58 Disabled debug mode, output GetText as well if GetText2 is not necessary, refactored my CHANGES file.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1391
diff changeset
87 "message": message,
4397
64d9d0f74a6a SyncPages: improve code readability
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3690
diff changeset
88 "raw_suffix": raw_suffix.replace("\n", "<<BR>>")})
1320
a36c70e5f0dd Reworked i18n and logging support, from now on, the log is attached to the job page.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1304
diff changeset
89
a36c70e5f0dd Reworked i18n and logging support, from now on, the log is attached to the job page.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1304
diff changeset
90 return "\n".join(table)
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
91
1030
807f80c76d81 Work on SyncPages. Fixed a few bugs, added new method to RemoteWiki, build regexes from the RemotePageList.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 977
diff changeset
92 def parse_page(self):
1159
0432e8a9ba2f Added docstrings.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1158
diff changeset
93 """ Parses the parameter page and returns the read arguments. """
1030
807f80c76d81 Work on SyncPages. Fixed a few bugs, added new method to RemoteWiki, build regexes from the RemotePageList.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 977
diff changeset
94 options = {
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
95 "remotePrefix": "",
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
96 "localPrefix": "",
1030
807f80c76d81 Work on SyncPages. Fixed a few bugs, added new method to RemoteWiki, build regexes from the RemotePageList.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 977
diff changeset
97 "remoteWiki": "",
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
98 "pageMatch": None,
1030
807f80c76d81 Work on SyncPages. Fixed a few bugs, added new method to RemoteWiki, build regexes from the RemotePageList.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 977
diff changeset
99 "pageList": None,
807f80c76d81 Work on SyncPages. Fixed a few bugs, added new method to RemoteWiki, build regexes from the RemotePageList.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 977
diff changeset
100 "groupList": None,
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
101 "direction": "foo", # is defaulted below
1799
06ce4843b9b5 remove some XXX strings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1793
diff changeset
102 "user": None, # XXX should be refactored into a password agent or OpenID like solution
06ce4843b9b5 remove some XXX strings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1793
diff changeset
103 "password": None,
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
104 }
1030
807f80c76d81 Work on SyncPages. Fixed a few bugs, added new method to RemoteWiki, build regexes from the RemotePageList.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 977
diff changeset
105
2252
ece659592dd9 wikidicts: refactoring, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2032
diff changeset
106 options.update(Dict(self.request, self.pagename))
1030
807f80c76d81 Work on SyncPages. Fixed a few bugs, added new method to RemoteWiki, build regexes from the RemotePageList.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 977
diff changeset
107
807f80c76d81 Work on SyncPages. Fixed a few bugs, added new method to RemoteWiki, build regexes from the RemotePageList.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 977
diff changeset
108 # Convert page and group list strings to lists
807f80c76d81 Work on SyncPages. Fixed a few bugs, added new method to RemoteWiki, build regexes from the RemotePageList.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 977
diff changeset
109 if options["pageList"] is not None:
807f80c76d81 Work on SyncPages. Fixed a few bugs, added new method to RemoteWiki, build regexes from the RemotePageList.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 977
diff changeset
110 options["pageList"] = unpackLine(options["pageList"], ",")
807f80c76d81 Work on SyncPages. Fixed a few bugs, added new method to RemoteWiki, build regexes from the RemotePageList.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 977
diff changeset
111 if options["groupList"] is not None:
807f80c76d81 Work on SyncPages. Fixed a few bugs, added new method to RemoteWiki, build regexes from the RemotePageList.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 977
diff changeset
112 options["groupList"] = unpackLine(options["groupList"], ",")
807f80c76d81 Work on SyncPages. Fixed a few bugs, added new method to RemoteWiki, build regexes from the RemotePageList.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 977
diff changeset
113
1267
eb9e5e21b0e5 Implemented the DOWN direction, refactored direction handling. The synctags of older syncs are invalid now, you have to delete them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1266
diff changeset
114 options["direction"] = directions_map.get(options["direction"].lower(), BOTH)
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
115
1030
807f80c76d81 Work on SyncPages. Fixed a few bugs, added new method to RemoteWiki, build regexes from the RemotePageList.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 977
diff changeset
116 return options
807f80c76d81 Work on SyncPages. Fixed a few bugs, added new method to RemoteWiki, build regexes from the RemotePageList.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 977
diff changeset
117
807f80c76d81 Work on SyncPages. Fixed a few bugs, added new method to RemoteWiki, build regexes from the RemotePageList.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 977
diff changeset
118 def fix_params(self, params):
807f80c76d81 Work on SyncPages. Fixed a few bugs, added new method to RemoteWiki, build regexes from the RemotePageList.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 977
diff changeset
119 """ Does some fixup on the parameters. """
1415
6c017035a7f2 Implemented a password dialog in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1410
diff changeset
120 # Load the password
6c017035a7f2 Implemented a password dialog in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1410
diff changeset
121 if "password" in self.request.form:
6c017035a7f2 Implemented a password dialog in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1410
diff changeset
122 params["password"] = self.request.form["password"][0]
1030
807f80c76d81 Work on SyncPages. Fixed a few bugs, added new method to RemoteWiki, build regexes from the RemotePageList.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 977
diff changeset
123
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
124 # merge the pageList case into the pageMatch case
1030
807f80c76d81 Work on SyncPages. Fixed a few bugs, added new method to RemoteWiki, build regexes from the RemotePageList.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 977
diff changeset
125 if params["pageList"] is not None:
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
126 params["pageMatch"] = u'|'.join([r'^%s$' % re.escape(name)
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
127 for name in params["pageList"]])
1030
807f80c76d81 Work on SyncPages. Fixed a few bugs, added new method to RemoteWiki, build regexes from the RemotePageList.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 977
diff changeset
128
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
129 if params["pageMatch"] is not None:
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
130 params["pageMatch"] = re.compile(params["pageMatch"], re.U)
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
131
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
132 # we do not support matching or listing pages if there is a group of pages
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
133 if params["groupList"]:
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
134 params["pageMatch"] = None
1266
ff08338e67fe Filter the pagelists by pageList on both sides (speedup). Marked a few operations as direct API accesses.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1264
diff changeset
135 params["pageList"] = None
1030
807f80c76d81 Work on SyncPages. Fixed a few bugs, added new method to RemoteWiki, build regexes from the RemotePageList.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 977
diff changeset
136
807f80c76d81 Work on SyncPages. Fixed a few bugs, added new method to RemoteWiki, build regexes from the RemotePageList.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 977
diff changeset
137 return params
807f80c76d81 Work on SyncPages. Fixed a few bugs, added new method to RemoteWiki, build regexes from the RemotePageList.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 977
diff changeset
138
1415
6c017035a7f2 Implemented a password dialog in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1410
diff changeset
139 def show_password_form(self):
6c017035a7f2 Implemented a password dialog in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1410
diff changeset
140 _ = self.request.getText
3122
a1322262398a refactored _() getText calls to match new api
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2966
diff changeset
141 d = {"message": _(r"Please enter your password of your account at the remote wiki below. <<BR>> /!\ You should trust both wikis because the password could be read by the particular administrators.", wiki=True),
1415
6c017035a7f2 Implemented a password dialog in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1410
diff changeset
142 "passwordlabel": _("Password"),
6c017035a7f2 Implemented a password dialog in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1410
diff changeset
143 "submit": _("Login"),
6c017035a7f2 Implemented a password dialog in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1410
diff changeset
144 "cancel": _("Cancel"),
6c017035a7f2 Implemented a password dialog in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1410
diff changeset
145 }
6c017035a7f2 Implemented a password dialog in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1410
diff changeset
146 html_form = """
6c017035a7f2 Implemented a password dialog in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1410
diff changeset
147 %(message)s
6c017035a7f2 Implemented a password dialog in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1410
diff changeset
148 <form method="post">
6c017035a7f2 Implemented a password dialog in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1410
diff changeset
149 <div>
6c017035a7f2 Implemented a password dialog in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1410
diff changeset
150 <input type="hidden" name="action" value="SyncPages">
6c017035a7f2 Implemented a password dialog in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1410
diff changeset
151 <label for="iPassword" style="font-weight: bold;">%(passwordlabel)s:</label>
1422
16a334acdd40 Use a password input field to hide the entered characters.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1421
diff changeset
152 <input type="password" name="password" id="iPassword" size="20">
1415
6c017035a7f2 Implemented a password dialog in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1410
diff changeset
153 </div>
6c017035a7f2 Implemented a password dialog in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1410
diff changeset
154 <div style="margin-top:1em; margin-bottom:1em;">
6c017035a7f2 Implemented a password dialog in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1410
diff changeset
155 <div style="float:left">
6c017035a7f2 Implemented a password dialog in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1410
diff changeset
156 <input type="submit" value="%(submit)s">
6c017035a7f2 Implemented a password dialog in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1410
diff changeset
157 </div>
6c017035a7f2 Implemented a password dialog in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1410
diff changeset
158 <div style="margin-left: 10em; margin-right: 10em;">
6c017035a7f2 Implemented a password dialog in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1410
diff changeset
159 <input type="submit" value="%(cancel)s" name="cancel">
6c017035a7f2 Implemented a password dialog in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1410
diff changeset
160 </div>
6c017035a7f2 Implemented a password dialog in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1410
diff changeset
161 </div>
6c017035a7f2 Implemented a password dialog in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1410
diff changeset
162 </form>
6c017035a7f2 Implemented a password dialog in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1410
diff changeset
163 """ % d
2966
ba14d391c2ba Refactor all modules to use the new add_msg interface in 1.7 (done by Frederico Lorenzi). Should not be backported to 1.6 but
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 2725
diff changeset
164 self.request.theme.add_msg(html_form, "dialog")
ba14d391c2ba Refactor all modules to use the new add_msg interface in 1.7 (done by Frederico Lorenzi). Should not be backported to 1.6 but
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 2725
diff changeset
165 self.page.send_page()
1415
6c017035a7f2 Implemented a password dialog in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1410
diff changeset
166
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
167 def render(self):
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
168 """ Render action
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
169
1030
807f80c76d81 Work on SyncPages. Fixed a few bugs, added new method to RemoteWiki, build regexes from the RemotePageList.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 977
diff changeset
170 This action returns a status message.
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
171 """
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
172 _ = self.request.getText
1030
807f80c76d81 Work on SyncPages. Fixed a few bugs, added new method to RemoteWiki, build regexes from the RemotePageList.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 977
diff changeset
173
807f80c76d81 Work on SyncPages. Fixed a few bugs, added new method to RemoteWiki, build regexes from the RemotePageList.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 977
diff changeset
174 params = self.fix_params(self.parse_page())
807f80c76d81 Work on SyncPages. Fixed a few bugs, added new method to RemoteWiki, build regexes from the RemotePageList.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 977
diff changeset
175
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
176 try:
1415
6c017035a7f2 Implemented a password dialog in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1410
diff changeset
177 if "cancel" in self.request.form:
2966
ba14d391c2ba Refactor all modules to use the new add_msg interface in 1.7 (done by Frederico Lorenzi). Should not be backported to 1.6 but
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 2725
diff changeset
178 raise ActionStatus(_("Operation was canceled."), "error")
1415
6c017035a7f2 Implemented a password dialog in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1410
diff changeset
179
1263
e313c2187271 Show an error message for the direction UP.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1262
diff changeset
180 if params["direction"] == UP:
2966
ba14d391c2ba Refactor all modules to use the new add_msg interface in 1.7 (done by Frederico Lorenzi). Should not be backported to 1.6 but
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 2725
diff changeset
181 raise ActionStatus(_("The only supported directions are BOTH and DOWN."), "error")
1263
e313c2187271 Show an error message for the direction UP.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1262
diff changeset
182
976
a442ed63b165 Reordered class hierachy of remote wikis, enhanced RemoteWiki interface
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 971
diff changeset
183 if not self.request.cfg.interwikiname:
3122
a1322262398a refactored _() getText calls to match new api
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2966
diff changeset
184 raise ActionStatus(_("Please set an interwikiname in your wikiconfig (see HelpOnConfiguration) to be able to use this action.", wiki=True), "error")
976
a442ed63b165 Reordered class hierachy of remote wikis, enhanced RemoteWiki interface
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 971
diff changeset
185
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
186 if not params["remoteWiki"]:
3122
a1322262398a refactored _() getText calls to match new api
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2966
diff changeset
187 raise ActionStatus(_("Incorrect parameters. Please supply at least the ''remoteWiki'' parameter. Refer to HelpOnSynchronisation for help.", wiki=True), "error")
1030
807f80c76d81 Work on SyncPages. Fixed a few bugs, added new method to RemoteWiki, build regexes from the RemotePageList.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 977
diff changeset
188
1266
ff08338e67fe Filter the pagelists by pageList on both sides (speedup). Marked a few operations as direct API accesses.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1264
diff changeset
189 local = MoinLocalWiki(self.request, params["localPrefix"], params["pageList"])
1095
e2cc6b5bed96 Added detection of anonymous wikis to the SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1092
diff changeset
190 try:
1386
0559fa036536 Added authentication support, fixed a few messages (added pagename).
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1385
diff changeset
191 remote = MoinRemoteWiki(self.request, params["remoteWiki"], params["remotePrefix"], params["pageList"], params["user"], params["password"], verbose=debug)
0559fa036536 Added authentication support, fixed a few messages (added pagename).
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1385
diff changeset
192 except (UnsupportedWikiException, NotAllowedException), (msg, ):
3414
898a544b8f74 make syncpages not crash on remote errors
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3122
diff changeset
193 raise ActionStatus(msg, "error")
1030
807f80c76d81 Work on SyncPages. Fixed a few bugs, added new method to RemoteWiki, build regexes from the RemotePageList.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 977
diff changeset
194
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
195 if not remote.valid:
3122
a1322262398a refactored _() getText calls to match new api
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2966
diff changeset
196 raise ActionStatus(_("The ''remoteWiki'' is unknown.", wiki=True), "error")
1415
6c017035a7f2 Implemented a password dialog in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1410
diff changeset
197 # if only the username is supplied, we ask for the password
6c017035a7f2 Implemented a password dialog in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1410
diff changeset
198 if params["user"] and not params["password"]:
6c017035a7f2 Implemented a password dialog in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1410
diff changeset
199 return self.show_password_form()
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
200 except ActionStatus, e:
3414
898a544b8f74 make syncpages not crash on remote errors
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3122
diff changeset
201 self.request.theme.add_msg(*e.args)
1407
e1419b1f9679 Fixed parameter checking code, now it evens gives you a warning instead of a traceback, fixed two minor typos (thanks to birkenfeld!), introduced prepare_multicall support in order to get authentication working and actually added the RPC-Aggregator.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1404
diff changeset
202 else:
1385
8bf6e48c6236 Added rollback and exception logging to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1352
diff changeset
203 try:
1407
e1419b1f9679 Fixed parameter checking code, now it evens gives you a warning instead of a traceback, fixed two minor typos (thanks to birkenfeld!), introduced prepare_multicall support in order to get authentication working and actually added the RPC-Aggregator.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1404
diff changeset
204 try:
e1419b1f9679 Fixed parameter checking code, now it evens gives you a warning instead of a traceback, fixed two minor typos (thanks to birkenfeld!), introduced prepare_multicall support in order to get authentication working and actually added the RPC-Aggregator.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1404
diff changeset
205 self.sync(params, local, remote)
e1419b1f9679 Fixed parameter checking code, now it evens gives you a warning instead of a traceback, fixed two minor typos (thanks to birkenfeld!), introduced prepare_multicall support in order to get authentication working and actually added the RPC-Aggregator.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1404
diff changeset
206 except Exception, e:
1410
107ca03adb3c Added transaction support and traceback recovery support to the action. In Python 2.5, we could use finally around yield ... but not in 2.3.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1407
diff changeset
207 temp_file = StringIO.StringIO()
107ca03adb3c Added transaction support and traceback recovery support to the action. In Python 2.5, we could use finally around yield ... but not in 2.3.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1407
diff changeset
208 traceback.print_exc(file=temp_file)
3122
a1322262398a refactored _() getText calls to match new api
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2966
diff changeset
209 self.log_status(self.ERROR, _("A severe error occurred:"), raw_suffix=temp_file.getvalue())
1407
e1419b1f9679 Fixed parameter checking code, now it evens gives you a warning instead of a traceback, fixed two minor typos (thanks to birkenfeld!), introduced prepare_multicall support in order to get authentication working and actually added the RPC-Aggregator.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1404
diff changeset
210 raise
e1419b1f9679 Fixed parameter checking code, now it evens gives you a warning instead of a traceback, fixed two minor typos (thanks to birkenfeld!), introduced prepare_multicall support in order to get authentication working and actually added the RPC-Aggregator.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1404
diff changeset
211 else:
2966
ba14d391c2ba Refactor all modules to use the new add_msg interface in 1.7 (done by Frederico Lorenzi). Should not be backported to 1.6 but
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 2725
diff changeset
212 self.request.theme.add_msg(u"%s" % (_("Synchronisation finished. Look below for the status messages."), ), "info")
1407
e1419b1f9679 Fixed parameter checking code, now it evens gives you a warning instead of a traceback, fixed two minor typos (thanks to birkenfeld!), introduced prepare_multicall support in order to get authentication working and actually added the RPC-Aggregator.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1404
diff changeset
213 finally:
1415
6c017035a7f2 Implemented a password dialog in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1410
diff changeset
214 self.call_rollback_funcs()
1407
e1419b1f9679 Fixed parameter checking code, now it evens gives you a warning instead of a traceback, fixed two minor typos (thanks to birkenfeld!), introduced prepare_multicall support in order to get authentication working and actually added the RPC-Aggregator.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1404
diff changeset
215 # XXX aquire readlock on self.page
e1419b1f9679 Fixed parameter checking code, now it evens gives you a warning instead of a traceback, fixed two minor typos (thanks to birkenfeld!), introduced prepare_multicall support in order to get authentication working and actually added the RPC-Aggregator.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1404
diff changeset
216 self.page.saveText(self.page.get_raw_body() + "\n\n" + self.generate_log_table(), 0)
e1419b1f9679 Fixed parameter checking code, now it evens gives you a warning instead of a traceback, fixed two minor typos (thanks to birkenfeld!), introduced prepare_multicall support in order to get authentication working and actually added the RPC-Aggregator.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1404
diff changeset
217 # XXX release readlock on self.page
1320
a36c70e5f0dd Reworked i18n and logging support, from now on, the log is attached to the job page.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1304
diff changeset
218
2032
cf883a6917ea better xmlrpc auth token handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1920
diff changeset
219 remote.delete_auth_token()
cf883a6917ea better xmlrpc auth token handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1920
diff changeset
220
2966
ba14d391c2ba Refactor all modules to use the new add_msg interface in 1.7 (done by Frederico Lorenzi). Should not be backported to 1.6 but
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 2725
diff changeset
221 return self.page.send_page()
1344
564cc2b53ea9 Reworded a docstring in SyncPages.sync, whitespace cleanup.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1343
diff changeset
222
1041
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
223 def sync(self, params, local, remote):
1511
fe417a0903fd Uncronified code.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1422
diff changeset
224 """ This method does the synchronisation work.
1344
564cc2b53ea9 Reworded a docstring in SyncPages.sync, whitespace cleanup.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1343
diff changeset
225 Currently, it handles nearly all cases.
564cc2b53ea9 Reworded a docstring in SyncPages.sync, whitespace cleanup.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1343
diff changeset
226 The major missing part is rename handling.
564cc2b53ea9 Reworded a docstring in SyncPages.sync, whitespace cleanup.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1343
diff changeset
227 There are a few other cases left that have to be implemented:
1271
bb2f70fc9734 Have been thinking about a solution for the remaining sync cases, put the thoughts into a docstring."
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1267
diff changeset
228 Wiki A | Wiki B | Remark
bb2f70fc9734 Have been thinking about a solution for the remaining sync cases, put the thoughts into a docstring."
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1267
diff changeset
229 ----------+----------+------------------------------
bb2f70fc9734 Have been thinking about a solution for the remaining sync cases, put the thoughts into a docstring."
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1267
diff changeset
230 exists | non- | Now the wiki knows that the page was renamed.
1407
e1419b1f9679 Fixed parameter checking code, now it evens gives you a warning instead of a traceback, fixed two minor typos (thanks to birkenfeld!), introduced prepare_multicall support in order to get authentication working and actually added the RPC-Aggregator.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1404
diff changeset
231 with tags | existing | There should be an RPC method that asks
1271
bb2f70fc9734 Have been thinking about a solution for the remaining sync cases, put the thoughts into a docstring."
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1267
diff changeset
232 | | for the new name (which could be recorded
bb2f70fc9734 Have been thinking about a solution for the remaining sync cases, put the thoughts into a docstring."
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1267
diff changeset
233 | | on page rename). Then the page is
bb2f70fc9734 Have been thinking about a solution for the remaining sync cases, put the thoughts into a docstring."
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1267
diff changeset
234 | | renamed in Wiki A as well and the sync
bb2f70fc9734 Have been thinking about a solution for the remaining sync cases, put the thoughts into a docstring."
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1267
diff changeset
235 | | is done normally.
1272
e85ad6a95ae5 Documented new ideas in the docstring, changed tag format (store normalised name), transmit normalised name in mergeDiff.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1271
diff changeset
236 | | Every wiki retains a dict that maps
e85ad6a95ae5 Documented new ideas in the docstring, changed tag format (store normalised name), transmit normalised name in mergeDiff.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1271
diff changeset
237 | | (IWID, oldname) => newname and that is
e85ad6a95ae5 Documented new ideas in the docstring, changed tag format (store normalised name), transmit normalised name in mergeDiff.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1271
diff changeset
238 | | updated on every rename. oldname refers
e85ad6a95ae5 Documented new ideas in the docstring, changed tag format (store normalised name), transmit normalised name in mergeDiff.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1271
diff changeset
239 | | to the pagename known by the old wiki (can be
e85ad6a95ae5 Documented new ideas in the docstring, changed tag format (store normalised name), transmit normalised name in mergeDiff.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1271
diff changeset
240 | | gathered from tags).
1271
bb2f70fc9734 Have been thinking about a solution for the remaining sync cases, put the thoughts into a docstring."
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1267
diff changeset
241 ----------+----------+-------------------------------
1272
e85ad6a95ae5 Documented new ideas in the docstring, changed tag format (store normalised name), transmit normalised name in mergeDiff.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1271
diff changeset
242 exists | any case | Try a rename search first, then
e85ad6a95ae5 Documented new ideas in the docstring, changed tag format (store normalised name), transmit normalised name in mergeDiff.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1271
diff changeset
243 | | do a sync without considering tags
1271
bb2f70fc9734 Have been thinking about a solution for the remaining sync cases, put the thoughts into a docstring."
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1267
diff changeset
244 with tags | with non | to ensure data integrity.
1304
f103cf7c371e Detect renamed pages. Changed the getDiff interface.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1303
diff changeset
245 | matching | Hmm, how do we detect this
1336
bf59bd23289b Some cleanup, fixed packages test because the default test user is not allowed to delete pages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1335
diff changeset
246 | tags | case if the unmatching tags are only
bf59bd23289b Some cleanup, fixed packages test because the default test user is not allowed to delete pages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1335
diff changeset
247 | | on the remote side?
1271
bb2f70fc9734 Have been thinking about a solution for the remaining sync cases, put the thoughts into a docstring."
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1267
diff changeset
248 ----------+----------+-------------------------------
bb2f70fc9734 Have been thinking about a solution for the remaining sync cases, put the thoughts into a docstring."
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1267
diff changeset
249 """
1320
a36c70e5f0dd Reworked i18n and logging support, from now on, the log is attached to the job page.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1304
diff changeset
250 _ = lambda x: x # we will translate it later
a36c70e5f0dd Reworked i18n and logging support, from now on, the log is attached to the job page.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1304
diff changeset
251
1264
064778edb38c Started integration of direction DOWN support.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1263
diff changeset
252 direction = params["direction"]
1322
cd150467ee30 Minor cleanups.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1321
diff changeset
253 if direction == BOTH:
cd150467ee30 Minor cleanups.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1321
diff changeset
254 match_direction = direction
cd150467ee30 Minor cleanups.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1321
diff changeset
255 else:
cd150467ee30 Minor cleanups.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1321
diff changeset
256 match_direction = None
cd150467ee30 Minor cleanups.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1321
diff changeset
257
1303
a0b8e78621d0 Preliminary support for items of different mime types.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1299
diff changeset
258 local_full_iwid = packLine([local.get_iwid(), local.get_interwiki_name()])
3690
a1a9ac307c0e SyncPages, xmlrpc.process: bug fix for WikiSyncMissingInterWikiNameOnRemoteSide (thanks to Alexander Schremmer)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3418
diff changeset
259 remote_full_iwid = remote.iwid_full
1136
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
260
2725
388204baf00f change [[macro]] to <<macro>> in all built-in markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2595
diff changeset
261 self.log_status(self.INFO, _("Synchronisation started -"), raw_suffix=" <<DateTime(%s)>>" % self.page._get_local_timestamp())
1320
a36c70e5f0dd Reworked i18n and logging support, from now on, the log is attached to the job page.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1304
diff changeset
262
1136
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
263 l_pages = local.get_pages()
1264
064778edb38c Started integration of direction DOWN support.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1263
diff changeset
264 r_pages = remote.get_pages(exclude_non_writable=direction != DOWN)
1092
f80e88b33c9d Added processing of local- and remoteMatch options to the SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1053
diff changeset
265
f80e88b33c9d Added processing of local- and remoteMatch options to the SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1053
diff changeset
266 if params["groupList"]:
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
267 pages_from_groupList = set(local.getGroupItems(params["groupList"]))
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
268 r_pages = SyncPage.filter(r_pages, pages_from_groupList.__contains__)
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
269 l_pages = SyncPage.filter(l_pages, pages_from_groupList.__contains__)
1041
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
270
1141
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
271 m_pages = [elem.add_missing_pagename(local, remote) for elem in SyncPage.merge(l_pages, r_pages)]
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
272
3418
60e0a3979520 Changed status message to "This results in %s pages to process.". It is not necessary to backport this changeset because it changes a translated string.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 3414
diff changeset
273 self.log_status(self.INFO, _("Got a list of %s local and %s remote pages. This results in %s pages to process."),
1320
a36c70e5f0dd Reworked i18n and logging support, from now on, the log is attached to the job page.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1304
diff changeset
274 (str(len(l_pages)), str(len(r_pages)), str(len(m_pages))))
1262
16bed977b054 Added support for underlay page ignore and prefix filtering in getAllPagesEx,
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1261
diff changeset
275
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
276 if params["pageMatch"]:
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
277 m_pages = SyncPage.filter(m_pages, params["pageMatch"].match)
1320
a36c70e5f0dd Reworked i18n and logging support, from now on, the log is attached to the job page.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1304
diff changeset
278 self.log_status(self.INFO, _("After filtering: %s pages"), (str(len(m_pages)), ))
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
279
1404
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
280 class handle_page(rpc_aggregator.RPCYielder):
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
281 def run(yielder, sp):
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
282 # XXX add locking, acquire read-lock on sp
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
283 if debug:
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
284 self.log_status(ActionClass.INFO, raw_suffix="Processing %r" % sp)
1884
da6479b19bd2 SyncPages:bug fixed for saving write protected page
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1805
diff changeset
285
1404
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
286 local_pagename = sp.local_name
1884
da6479b19bd2 SyncPages:bug fixed for saving write protected page
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1805
diff changeset
287 if not self.request.user.may.write(local_pagename):
da6479b19bd2 SyncPages:bug fixed for saving write protected page
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1805
diff changeset
288 self.log_status(ActionClass.WARN, _("Skipped page %s because of no write access to local page."), (local_pagename, ))
da6479b19bd2 SyncPages:bug fixed for saving write protected page
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1805
diff changeset
289 return
da6479b19bd2 SyncPages:bug fixed for saving write protected page
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1805
diff changeset
290
1404
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
291 current_page = PageEditor(self.request, local_pagename) # YYY direct access
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
292 comment = u"Local Merge - %r" % (remote.get_interwiki_name() or remote.get_iwid())
1332
16a854a172c9 Implemented support for deleted pages, finished support for pages that are just in one wiki.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1330
diff changeset
293
1404
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
294 tags = TagStore(current_page)
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
295
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
296 matching_tags = tags.fetch(iwid_full=remote.iwid_full, direction=match_direction)
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
297 matching_tags.sort()
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
298 if debug:
2725
388204baf00f change [[macro]] to <<macro>> in all built-in markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2595
diff changeset
299 self.log_status(ActionClass.INFO, raw_suffix="Tags: %r <<BR>> All: %r" % (matching_tags, tags.tags))
1404
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
300
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
301 # some default values for non matching tags
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
302 normalised_name = None
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
303 remote_rev = None
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
304 local_rev = sp.local_rev # merge against the newest version
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
305 old_contents = ""
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
306
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
307 if matching_tags:
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
308 newest_tag = matching_tags[-1]
1888
ffe2e789a7c6 SyncPages: fixed direction both from cgi server to standalone server and immutable pages on both servers.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1884
diff changeset
309
1404
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
310 local_change = newest_tag.current_rev != sp.local_rev
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
311 remote_change = newest_tag.remote_rev != sp.remote_rev
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
312
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
313 # handle some cases where we cannot continue for this page
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
314 if not remote_change and (direction == DOWN or not local_change):
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
315 return # no changes done, next page
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
316 if sp.local_deleted and sp.remote_deleted:
1335
2cd1b40ea3e7 Added support for deletion of local pages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1332
diff changeset
317 return
1404
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
318 if sp.remote_deleted and not local_change:
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
319 msg = local.delete_page(sp.local_name, comment)
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
320 if not msg:
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
321 self.log_status(ActionClass.INFO, _("Deleted page %s locally."), (sp.name, ))
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
322 else:
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
323 self.log_status(ActionClass.ERROR, _("Error while deleting page %s locally:"), (sp.name, ), msg)
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
324 return
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
325 if sp.local_deleted and not remote_change:
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
326 if direction == DOWN:
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
327 return
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
328 yield remote.delete_page_pre(sp.remote_name, sp.remote_rev, local_full_iwid)
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
329 msg = remote.delete_page_post(yielder.fetch_result())
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
330 if not msg:
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
331 self.log_status(ActionClass.INFO, _("Deleted page %s remotely."), (sp.name, ))
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
332 else:
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
333 self.log_status(ActionClass.ERROR, _("Error while deleting page %s remotely:"), (sp.name, ), msg)
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
334 return
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
335 if sp.local_mime_type != MIMETYPE_MOIN and not (local_change ^ remote_change):
1519
cc27f2c82cde Fixed core merging logic to handle cases where changes only happened on one side, added some comments, reworded some messages. (SyncPages)
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1511
diff changeset
336 self.log_status(ActionClass.WARN, _("The item %s cannot be merged automatically but was changed in both wikis. Please delete it in one of both wikis and try again."), (sp.name, ))
1404
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
337 return
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
338 if sp.local_mime_type != sp.remote_mime_type:
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
339 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, ))
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
340 return
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
341 if newest_tag.normalised_name != sp.name:
1511
fe417a0903fd Uncronified code.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1422
diff changeset
342 self.log_status(ActionClass.WARN, _("The item %s was renamed locally. This is not implemented yet. Therefore the full synchronisation history is lost for this page."), (sp.name, )) # XXX implement renames
1343
144c3281e88f Now the deletion of remote pages is working.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1336
diff changeset
343 else:
1404
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
344 normalised_name = newest_tag.normalised_name
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
345 local_rev = newest_tag.current_rev
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
346 remote_rev = newest_tag.remote_rev
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
347 old_contents = Page(self.request, local_pagename, rev=newest_tag.current_rev).get_raw_body_str() # YYY direct access
1304
f103cf7c371e Detect renamed pages. Changed the getDiff interface.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1303
diff changeset
348 else:
1404
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
349 if (sp.local_deleted and not sp.remote_rev) or (
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
350 sp.remote_deleted and not sp.local_rev):
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
351 return
1158
353c493dfb77 Added local conflict detection, logging support to SyncPages, updated my CHANGES file.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1141
diff changeset
352
1404
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
353 self.log_status(ActionClass.INFO, _("Synchronising page %s with remote page %s ..."), (local_pagename, sp.remote_name))
1267
eb9e5e21b0e5 Implemented the DOWN direction, refactored direction handling. The synctags of older syncs are invalid now, you have to delete them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1266
diff changeset
354
1404
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
355 if direction == DOWN:
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
356 remote_rev = None # always fetch the full page, ignore remote conflict check
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
357 patch_base_contents = ""
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
358 else:
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
359 patch_base_contents = old_contents
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
360
1519
cc27f2c82cde Fixed core merging logic to handle cases where changes only happened on one side, added some comments, reworded some messages. (SyncPages)
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1511
diff changeset
361 # retrieve remote contents diff
1404
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
362 if remote_rev != sp.remote_rev:
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
363 if sp.remote_deleted: # ignore remote changes
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
364 current_remote_rev = sp.remote_rev
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
365 is_remote_conflict = False
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
366 diff = None
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
367 self.log_status(ActionClass.WARN, _("The page %s was deleted remotely but changed locally."), (sp.name, ))
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
368 else:
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
369 yield remote.get_diff_pre(sp.remote_name, remote_rev, None, normalised_name)
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
370 diff_result = remote.get_diff_post(yielder.fetch_result())
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
371 if diff_result is None:
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
372 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, ))
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
373 return
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
374 is_remote_conflict = diff_result["conflict"]
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
375 assert diff_result["diffversion"] == 1
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
376 diff = diff_result["diff"]
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
377 current_remote_rev = diff_result["current"]
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
378 else:
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
379 current_remote_rev = remote_rev
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
380 if sp.local_mime_type == MIMETYPE_MOIN:
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
381 is_remote_conflict = wikiutil.containsConflictMarker(old_contents.decode("utf-8"))
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
382 else:
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
383 is_remote_conflict = NotImplemented
1332
16a854a172c9 Implemented support for deleted pages, finished support for pages that are just in one wiki.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1330
diff changeset
384 diff = None
1041
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
385
1404
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
386 # do not sync if the conflict is remote and local, or if it is local
1511
fe417a0903fd Uncronified code.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1422
diff changeset
387 # and the page has never been synchronised
1404
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
388 if (sp.local_mime_type == MIMETYPE_MOIN and wikiutil.containsConflictMarker(current_page.get_raw_body()) # YYY direct access
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
389 and (remote_rev is None or is_remote_conflict)):
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
390 self.log_status(ActionClass.WARN, _("Skipped page %s because of a locally or remotely unresolved conflict."), (local_pagename, ))
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
391 return
1260
5d555ec6b40a Fixed a bug that was hard to track down in SyncPages (some hours spent :-/).
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1259
diff changeset
392
1404
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
393 if remote_rev is None and direction == BOTH:
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
394 self.log_status(ActionClass.INFO, _("This is the first synchronisation between the local and the remote wiki for the page %s."), (sp.name, ))
1261
ae9eb32b6899 Refactored code, cleaned up some parts of the code, moved some classes to wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1260
diff changeset
395
1519
cc27f2c82cde Fixed core merging logic to handle cases where changes only happened on one side, added some comments, reworded some messages. (SyncPages)
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1511
diff changeset
396 # calculate remote page contents from diff
1404
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
397 if sp.remote_deleted:
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
398 remote_contents = ""
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
399 elif diff is None:
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
400 remote_contents = old_contents
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
401 else:
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
402 remote_contents = patch(patch_base_contents, decompress(diff))
1385
8bf6e48c6236 Added rollback and exception logging to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1352
diff changeset
403
1519
cc27f2c82cde Fixed core merging logic to handle cases where changes only happened on one side, added some comments, reworded some messages. (SyncPages)
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1511
diff changeset
404 if diff is None: # only a local change
cc27f2c82cde Fixed core merging logic to handle cases where changes only happened on one side, added some comments, reworded some messages. (SyncPages)
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1511
diff changeset
405 if debug:
cc27f2c82cde Fixed core merging logic to handle cases where changes only happened on one side, added some comments, reworded some messages. (SyncPages)
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1511
diff changeset
406 self.log_status(ActionClass.INFO, raw_suffix="Only local changes for %r" % sp.name)
cc27f2c82cde Fixed core merging logic to handle cases where changes only happened on one side, added some comments, reworded some messages. (SyncPages)
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1511
diff changeset
407 merged_text_raw = current_page.get_raw_body_str()
cc27f2c82cde Fixed core merging logic to handle cases where changes only happened on one side, added some comments, reworded some messages. (SyncPages)
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1511
diff changeset
408 if sp.local_mime_type == MIMETYPE_MOIN:
cc27f2c82cde Fixed core merging logic to handle cases where changes only happened on one side, added some comments, reworded some messages. (SyncPages)
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1511
diff changeset
409 merged_text = merged_text_raw.decode("utf-8")
cc27f2c82cde Fixed core merging logic to handle cases where changes only happened on one side, added some comments, reworded some messages. (SyncPages)
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1511
diff changeset
410 elif local_rev == sp.local_rev:
cc27f2c82cde Fixed core merging logic to handle cases where changes only happened on one side, added some comments, reworded some messages. (SyncPages)
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1511
diff changeset
411 if debug:
cc27f2c82cde Fixed core merging logic to handle cases where changes only happened on one side, added some comments, reworded some messages. (SyncPages)
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1511
diff changeset
412 self.log_status(ActionClass.INFO, raw_suffix="Only remote changes for %r" % sp.name)
cc27f2c82cde Fixed core merging logic to handle cases where changes only happened on one side, added some comments, reworded some messages. (SyncPages)
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1511
diff changeset
413 merged_text_raw = remote_contents
cc27f2c82cde Fixed core merging logic to handle cases where changes only happened on one side, added some comments, reworded some messages. (SyncPages)
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1511
diff changeset
414 if sp.local_mime_type == MIMETYPE_MOIN:
cc27f2c82cde Fixed core merging logic to handle cases where changes only happened on one side, added some comments, reworded some messages. (SyncPages)
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1511
diff changeset
415 merged_text = merged_text_raw.decode("utf-8")
cc27f2c82cde Fixed core merging logic to handle cases where changes only happened on one side, added some comments, reworded some messages. (SyncPages)
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1511
diff changeset
416 else:
cc27f2c82cde Fixed core merging logic to handle cases where changes only happened on one side, added some comments, reworded some messages. (SyncPages)
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1511
diff changeset
417 # this is guaranteed by a check above
cc27f2c82cde Fixed core merging logic to handle cases where changes only happened on one side, added some comments, reworded some messages. (SyncPages)
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1511
diff changeset
418 assert sp.local_mime_type == MIMETYPE_MOIN
1404
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
419 remote_contents_unicode = remote_contents.decode("utf-8")
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
420 # here, the actual 3-way merge happens
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
421 merged_text = diff3.text_merge(old_contents.decode("utf-8"), remote_contents_unicode, current_page.get_raw_body(), 1, *conflict_markers) # YYY direct access
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
422 if debug:
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
423 self.log_status(ActionClass.INFO, raw_suffix="Merging %r, %r and %r into %r" % (old_contents.decode("utf-8"), remote_contents_unicode, current_page.get_raw_body(), merged_text))
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
424 merged_text_raw = merged_text.encode("utf-8")
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
425
1519
cc27f2c82cde Fixed core merging logic to handle cases where changes only happened on one side, added some comments, reworded some messages. (SyncPages)
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1511
diff changeset
426 # generate binary diff
1404
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
427 diff = textdiff(remote_contents, merged_text_raw)
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
428 if debug:
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
429 self.log_status(ActionClass.INFO, raw_suffix="Diff against %r" % remote_contents)
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
430
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
431 # XXX upgrade to write lock
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
432 try:
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
433 local_change_done = True
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
434 current_page.saveText(merged_text, sp.local_rev or 0, comment=comment) # YYY direct access
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
435 except PageEditor.Unchanged:
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
436 local_change_done = False
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
437 except PageEditor.EditConflict:
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
438 local_change_done = False
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
439 assert False, "You stumbled on a problem with the current storage system - I cannot lock pages"
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
440
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
441 new_local_rev = current_page.get_real_rev() # YYY direct access
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
442
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
443 def rollback_local_change(): # YYY direct local access
1642
0101edf9d308 Delete page in the rollback case if it was deleted before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1519
diff changeset
444 comment = u"Wikisync rollback"
1404
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
445 rev = new_local_rev - 1
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
446 revstr = '%08d' % rev
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
447 oldpg = Page(self.request, sp.local_name, rev=rev)
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
448 pg = PageEditor(self.request, sp.local_name)
1642
0101edf9d308 Delete page in the rollback case if it was deleted before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1519
diff changeset
449 if not oldpg.exists():
0101edf9d308 Delete page in the rollback case if it was deleted before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1519
diff changeset
450 pg.deletePage(comment)
0101edf9d308 Delete page in the rollback case if it was deleted before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1519
diff changeset
451 else:
0101edf9d308 Delete page in the rollback case if it was deleted before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1519
diff changeset
452 try:
0101edf9d308 Delete page in the rollback case if it was deleted before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1519
diff changeset
453 savemsg = pg.saveText(oldpg.get_raw_body(), 0, comment=comment, extra=revstr, action="SAVE/REVERT")
0101edf9d308 Delete page in the rollback case if it was deleted before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1519
diff changeset
454 except PageEditor.Unchanged:
0101edf9d308 Delete page in the rollback case if it was deleted before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1519
diff changeset
455 pass
1410
107ca03adb3c Added transaction support and traceback recovery support to the action. In Python 2.5, we could use finally around yield ... but not in 2.3.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1407
diff changeset
456 return sp.local_name
107ca03adb3c Added transaction support and traceback recovery support to the action. In Python 2.5, we could use finally around yield ... but not in 2.3.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1407
diff changeset
457
107ca03adb3c Added transaction support and traceback recovery support to the action. In Python 2.5, we could use finally around yield ... but not in 2.3.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1407
diff changeset
458 if local_change_done:
107ca03adb3c Added transaction support and traceback recovery support to the action. In Python 2.5, we could use finally around yield ... but not in 2.3.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1407
diff changeset
459 self.register_rollback(rollback_local_change)
1404
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
460
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
461 if direction == BOTH:
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
462 yield remote.merge_diff_pre(sp.remote_name, compress(diff), new_local_rev, current_remote_rev, current_remote_rev, local_full_iwid, sp.name)
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
463 try:
1410
107ca03adb3c Added transaction support and traceback recovery support to the action. In Python 2.5, we could use finally around yield ... but not in 2.3.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1407
diff changeset
464 very_current_remote_rev = remote.merge_diff_post(yielder.fetch_result())
107ca03adb3c Added transaction support and traceback recovery support to the action. In Python 2.5, we could use finally around yield ... but not in 2.3.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1407
diff changeset
465 except NotAllowedException:
107ca03adb3c Added transaction support and traceback recovery support to the action. In Python 2.5, we could use finally around yield ... but not in 2.3.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1407
diff changeset
466 self.log_status(ActionClass.ERROR, _("The page %s could not be merged because you are not allowed to modify the page in the remote wiki."), (sp.name, ))
107ca03adb3c Added transaction support and traceback recovery support to the action. In Python 2.5, we could use finally around yield ... but not in 2.3.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1407
diff changeset
467 return
1385
8bf6e48c6236 Added rollback and exception logging to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1352
diff changeset
468 else:
8bf6e48c6236 Added rollback and exception logging to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1352
diff changeset
469 very_current_remote_rev = current_remote_rev
8bf6e48c6236 Added rollback and exception logging to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1352
diff changeset
470
1888
ffe2e789a7c6 SyncPages: fixed direction both from cgi server to standalone server and immutable pages on both servers.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1884
diff changeset
471
1410
107ca03adb3c Added transaction support and traceback recovery support to the action. In Python 2.5, we could use finally around yield ... but not in 2.3.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1407
diff changeset
472 if local_change_done:
107ca03adb3c Added transaction support and traceback recovery support to the action. In Python 2.5, we could use finally around yield ... but not in 2.3.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1407
diff changeset
473 self.remove_rollback(rollback_local_change)
107ca03adb3c Added transaction support and traceback recovery support to the action. In Python 2.5, we could use finally around yield ... but not in 2.3.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1407
diff changeset
474
1888
ffe2e789a7c6 SyncPages: fixed direction both from cgi server to standalone server and immutable pages on both servers.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1884
diff changeset
475 # this is needed at least for direction both and cgi sync to standalone for immutable pages on both
ffe2e789a7c6 SyncPages: fixed direction both from cgi server to standalone server and immutable pages on both servers.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1884
diff changeset
476 # servers. It is not needed for the opposite direction
ffe2e789a7c6 SyncPages: fixed direction both from cgi server to standalone server and immutable pages on both servers.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1884
diff changeset
477 try:
ffe2e789a7c6 SyncPages: fixed direction both from cgi server to standalone server and immutable pages on both servers.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1884
diff changeset
478 tags.add(remote_wiki=remote_full_iwid, remote_rev=very_current_remote_rev, current_rev=new_local_rev, direction=direction, normalised_name=sp.name)
ffe2e789a7c6 SyncPages: fixed direction both from cgi server to standalone server and immutable pages on both servers.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1884
diff changeset
479 except:
ffe2e789a7c6 SyncPages: fixed direction both from cgi server to standalone server and immutable pages on both servers.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1884
diff changeset
480 self.log_status(ActionClass.ERROR, _("The page %s could not be merged because you are not allowed to modify the page in the remote wiki."), (sp.name, ))
ffe2e789a7c6 SyncPages: fixed direction both from cgi server to standalone server and immutable pages on both servers.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1884
diff changeset
481 return
1158
353c493dfb77 Added local conflict detection, logging support to SyncPages, updated my CHANGES file.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1141
diff changeset
482
1404
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
483 if sp.local_mime_type != MIMETYPE_MOIN or not wikiutil.containsConflictMarker(merged_text):
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
484 self.log_status(ActionClass.INFO, _("Page %s successfully merged."), (sp.name, ))
1410
107ca03adb3c Added transaction support and traceback recovery support to the action. In Python 2.5, we could use finally around yield ... but not in 2.3.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1407
diff changeset
485 elif is_remote_conflict:
107ca03adb3c Added transaction support and traceback recovery support to the action. In Python 2.5, we could use finally around yield ... but not in 2.3.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1407
diff changeset
486 self.log_status(ActionClass.WARN, _("Page %s contains conflicts that were introduced on the remote side."), (sp.name, ))
1404
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
487 else:
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
488 self.log_status(ActionClass.WARN, _("Page %s merged with conflicts."), (sp.name, ))
1158
353c493dfb77 Added local conflict detection, logging support to SyncPages, updated my CHANGES file.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1141
diff changeset
489
1404
e6bf86b4a735 Migrated code to new RPC-Aggregator technology. Fixed merging bug that affected deleted pages in scenarios where the page was not synced before.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1393
diff changeset
490 # XXX release lock
1030
807f80c76d81 Work on SyncPages. Fixed a few bugs, added new method to RemoteWiki, build regexes from the RemotePageList.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 977
diff changeset
491
1407
e1419b1f9679 Fixed parameter checking code, now it evens gives you a warning instead of a traceback, fixed two minor typos (thanks to birkenfeld!), introduced prepare_multicall support in order to get authentication working and actually added the RPC-Aggregator.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1404
diff changeset
492 rpc_aggregator.scheduler(remote.create_multicall_object, handle_page, m_pages, 8, remote.prepare_multicall)
1324
2e29ef86be26 Reordered SyncPages, preparing for new modes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1322
diff changeset
493
2e29ef86be26 Reordered SyncPages, preparing for new modes.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1322
diff changeset
494
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
495 def execute(pagename, request):
971
d24f2b1d606a Refactoring, fixed Fault codes, fixed return format of the getdiff method.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 970
diff changeset
496 ActionClass(pagename, request).render()
1344
564cc2b53ea9 Reworded a docstring in SyncPages.sync, whitespace cleanup.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1343
diff changeset
497