annotate MoinMoin/action/SyncPages.py @ 1264:064778edb38c

Started integration of direction DOWN support.
author Alexander Schremmer <alex AT alexanderweb DOT de>
date Sat, 12 Aug 2006 23:54:14 +0200
parents e313c2187271
children ff08338e67fe
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
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
11 import os
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
12 import re
976
a442ed63b165 Reordered class hierachy of remote wikis, enhanced RemoteWiki interface
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 971
diff changeset
13 import xmlrpclib
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
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 # Compatiblity to Python 2.3
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
16 try:
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
17 set
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
18 except NameError:
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
19 from sets import Set as set
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
20
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
21
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
22 from MoinMoin import wikiutil, config, user
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
23 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
24 from MoinMoin.PageEditor import PageEditor, conflict_markers
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
25 from MoinMoin.Page import Page
1092
f80e88b33c9d Added processing of local- and remoteMatch options to the SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1053
diff changeset
26 from MoinMoin.wikidicts import Dict, Group
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
27 from MoinMoin.wikisync import TagStore, UnsupportedWikiException, SyncPage, MoinLocalWiki, MoinRemoteWiki
1141
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
28 from MoinMoin.util.bdiff import decompress, patch, compress, textdiff
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
29 from MoinMoin.util import diff3
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
30
1264
064778edb38c Started integration of direction DOWN support.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1263
diff changeset
31
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
32 # directions
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
33 UP, DOWN, BOTH = range(3)
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
34 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
35
1135
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
36
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
37 class ActionStatus(Exception): pass
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
38
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
39
971
d24f2b1d606a Refactoring, fixed Fault codes, fixed return format of the getdiff method.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 970
diff changeset
40 class ActionClass:
1164
32c936ab469e Made SyncPages working, first page could be syncronised.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1159
diff changeset
41 INFO, WARN, ERROR = 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
42
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
43 def __init__(self, pagename, request):
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
44 self.request = request
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
45 self.pagename = pagename
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
46 self.page = Page(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
47 self.status = []
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
353c493dfb77 Added local conflict detection, logging support to SyncPages, updated my CHANGES file.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1141
diff changeset
49 def log_status(self, level, message):
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. """
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
51 self.status.append((level, message))
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
52
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
53 def parse_page(self):
1159
0432e8a9ba2f Added docstrings.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1158
diff changeset
54 """ 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
55 options = {
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
56 "remotePrefix": "",
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
57 "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
58 "remoteWiki": "",
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
59 "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
60 "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
61 "groupList": None,
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
62 "direction": "foo", # is defaulted below
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
63 }
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
64
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
65 options.update(Dict(self.request, self.pagename).get_dict())
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
66
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
67 # 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
68 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
69 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
70 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
71 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
72
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
73 options["direction"] = directions_map.get(options["direction"], BOTH)
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
74
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
75 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
76
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
77 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
78 """ Does some fixup on the parameters. """
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
79
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
80 # 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
81 if params["pageList"] is not None:
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
82 params["pageMatch"] = u'|'.join([r'^%s$' % re.escape(name)
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
83 for name in params["pageList"]])
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
84 del 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
85
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
86 if params["pageMatch"] is not None:
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
87 params["pageMatch"] = re.compile(params["pageMatch"], re.U)
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
88
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
89 # 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
90 if params["groupList"]:
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
91 params["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
92
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
93 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
94
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
95 def render(self):
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
96 """ Render action
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
97
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
98 This action returns a status message.
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
99 """
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
100 _ = 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
101
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
102 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
103
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
104 try:
1263
e313c2187271 Show an error message for the direction UP.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1262
diff changeset
105 if params["direction"] == UP:
e313c2187271 Show an error message for the direction UP.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1262
diff changeset
106 raise ActionStatus(_("The only supported directions are BOTH and DOWN."))
e313c2187271 Show an error message for the direction UP.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1262
diff changeset
107
976
a442ed63b165 Reordered class hierachy of remote wikis, enhanced RemoteWiki interface
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 971
diff changeset
108 if not self.request.cfg.interwikiname:
a442ed63b165 Reordered class hierachy of remote wikis, enhanced RemoteWiki interface
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 971
diff changeset
109 raise ActionStatus(_("Please set an interwikiname in your wikiconfig (see HelpOnConfiguration) to be able to use this action."))
a442ed63b165 Reordered class hierachy of remote wikis, enhanced RemoteWiki interface
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 971
diff changeset
110
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
111 if not params["remoteWiki"]:
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
112 raise ActionStatus(_("Incorrect parameters. Please supply at least the ''remoteWiki'' parameter."))
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
113
1135
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
114 local = MoinLocalWiki(self.request, params["localPrefix"])
1095
e2cc6b5bed96 Added detection of anonymous wikis to the SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1092
diff changeset
115 try:
1135
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
116 remote = MoinRemoteWiki(self.request, params["remoteWiki"], params["remotePrefix"])
1097
e22024151c2c Fixed some bugs in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1096
diff changeset
117 except UnsupportedWikiException, (msg, ):
e22024151c2c Fixed some bugs in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1096
diff changeset
118 raise ActionStatus(msg)
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
119
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
120 if not remote.valid:
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
121 raise ActionStatus(_("The ''remoteWiki'' is unknown."))
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
122
1041
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
123 self.sync(params, local, remote)
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
124 except ActionStatus, e:
1164
32c936ab469e Made SyncPages working, first page could be syncronised.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1159
diff changeset
125 msg = u'<p class="error">%s</p><p>%s</p>\n' % (e.args[0], repr(self.status))
32c936ab469e Made SyncPages working, first page could be syncronised.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1159
diff changeset
126 else:
32c936ab469e Made SyncPages working, first page could be syncronised.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1159
diff changeset
127 msg = u"%s<p>%s</p>" % (_("Syncronisation finished."), repr(self.status))
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
128
1164
32c936ab469e Made SyncPages working, first page could be syncronised.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1159
diff changeset
129 # XXX append self.status to the job page
32c936ab469e Made SyncPages working, first page could be syncronised.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1159
diff changeset
130 return self.page.send_page(self.request, msg=msg)
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
131
1041
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
132 def sync(self, params, local, remote):
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
133 """ This method does the syncronisation work. """
1164
32c936ab469e Made SyncPages working, first page could be syncronised.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1159
diff changeset
134 _ = self.request.getText
1264
064778edb38c Started integration of direction DOWN support.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1263
diff changeset
135 direction = params["direction"]
1136
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
136
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
137 l_pages = local.get_pages()
1264
064778edb38c Started integration of direction DOWN support.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1263
diff changeset
138 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
139
f80e88b33c9d Added processing of local- and remoteMatch options to the SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1053
diff changeset
140 if params["groupList"]:
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
141 pages_from_groupList = set(local.getGroupItems(params["groupList"]))
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
142 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
143 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
144
1141
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
145 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
146
1262
16bed977b054 Added support for underlay page ignore and prefix filtering in getAllPagesEx,
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1261
diff changeset
147 print "Got %i local, %i remote pages, %i merged pages" % (len(l_pages), len(r_pages), len(m_pages)) # XXX remove
16bed977b054 Added support for underlay page ignore and prefix filtering in getAllPagesEx,
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1261
diff changeset
148
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
149 if params["pageMatch"]:
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
150 m_pages = SyncPage.filter(m_pages, params["pageMatch"].match)
1262
16bed977b054 Added support for underlay page ignore and prefix filtering in getAllPagesEx,
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1261
diff changeset
151 print "After filtering: Got %i merges pages" % (len(m_pages), ) # XXX remove
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
152
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
153 on_both_sides = list(SyncPage.iter_local_and_remote(m_pages))
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
154 remote_but_not_local = list(SyncPage.iter_remote_only(m_pages))
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
155 local_but_not_remote = list(SyncPage.iter_local_only(m_pages))
1098
cdd1ea31f00e Added sample code for set logic in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1097
diff changeset
156
1136
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
157 # some initial test code (XXX remove)
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
158 #r_new_pages = u", ".join([unicode(x) for x in remote_but_not_local])
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
159 #l_new_pages = u", ".join([unicode(x) for x in local_but_not_remote])
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
160 #raise ActionStatus("These pages are in the remote wiki, but not local: " + wikiutil.escape(r_new_pages) + "<br>These pages are in the local wiki, but not in the remote one: " + wikiutil.escape(l_new_pages))
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
161
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
162 # let's do the simple case first, can be refactored later to match all cases
1141
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
163 # XXX handle deleted pages
1136
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
164 for rp in on_both_sides:
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
165 # XXX add locking, acquire read-lock on rp
1164
32c936ab469e Made SyncPages working, first page could be syncronised.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1159
diff changeset
166 print "Processing %r" % rp
1136
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
167
1164
32c936ab469e Made SyncPages working, first page could be syncronised.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1159
diff changeset
168 local_pagename = rp.local_name
32c936ab469e Made SyncPages working, first page could be syncronised.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1159
diff changeset
169 current_page = PageEditor(self.request, local_pagename)
1141
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
170 current_rev = current_page.get_real_rev()
1136
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
171
1141
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
172 tags = TagStore(current_page)
1136
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
173 matching_tags = tags.fetch(iwid_full=remote.iwid_full)
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
174 matching_tags.sort()
1251
7b128ea29fc4 Further bug fixes in SyncPages and wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1164
diff changeset
175 #print "------ TAGS: " + repr(matching_tags) + repr(tags.tags)
1136
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
176
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
177 if not matching_tags:
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
178 remote_rev = None
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
179 local_rev = rp.local_rev # merge against the newest version
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
180 old_contents = ""
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
181 else:
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
182 newest_tag = matching_tags[-1]
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
183 local_rev = newest_tag.current_rev
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
184 remote_rev = newest_tag.remote_rev
1264
064778edb38c Started integration of direction DOWN support.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1263
diff changeset
185 if remote_rev == rp.remote_rev and (direction == DOWN or local_rev == current_rev):
1141
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
186 continue # no changes done, next page
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
187 old_page = Page(self.request, local_pagename, rev=local_rev)
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
188 old_contents = old_page.get_raw_body_str()
1136
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
189
1164
32c936ab469e Made SyncPages working, first page could be syncronised.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1159
diff changeset
190 self.log_status(ActionClass.INFO, _("Synchronising page %(pagename)s with remote page %(remotepagename)s ...") % {"pagename": local_pagename, "remotepagename": rp.remote_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
191
1259
a76ce7b95190 SyncPages fixes, allow for the case where only the local page is changed.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1254
diff changeset
192 if remote_rev != rp.remote_rev:
a76ce7b95190 SyncPages fixes, allow for the case where only the local page is changed.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1254
diff changeset
193 diff_result = remote.get_diff(rp.remote_name, remote_rev, None) # XXX might raise ALREADY_CURRENT
a76ce7b95190 SyncPages fixes, allow for the case where only the local page is changed.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1254
diff changeset
194 is_remote_conflict = diff_result["conflict"]
a76ce7b95190 SyncPages fixes, allow for the case where only the local page is changed.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1254
diff changeset
195 assert diff_result["diffversion"] == 1
a76ce7b95190 SyncPages fixes, allow for the case where only the local page is changed.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1254
diff changeset
196 diff = diff_result["diff"]
a76ce7b95190 SyncPages fixes, allow for the case where only the local page is changed.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1254
diff changeset
197 current_remote_rev = diff_result["current"]
a76ce7b95190 SyncPages fixes, allow for the case where only the local page is changed.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1254
diff changeset
198 else:
a76ce7b95190 SyncPages fixes, allow for the case where only the local page is changed.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1254
diff changeset
199 current_remote_rev = remote_rev
a76ce7b95190 SyncPages fixes, allow for the case where only the local page is changed.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1254
diff changeset
200 is_remote_conflict = wikiutil.containsConflictMarker(old_contents.decode("utf-8"))
a76ce7b95190 SyncPages fixes, allow for the case where only the local page is changed.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1254
diff changeset
201 diff = None
1141
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
202
1251
7b128ea29fc4 Further bug fixes in SyncPages and wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1164
diff changeset
203 # do not sync if the conflict is remote and local, or if it is local
7b128ea29fc4 Further bug fixes in SyncPages and wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1164
diff changeset
204 # and the page has never been syncronised
7b128ea29fc4 Further bug fixes in SyncPages and wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1164
diff changeset
205 if (wikiutil.containsConflictMarker(current_page.get_raw_body())
7b128ea29fc4 Further bug fixes in SyncPages and wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1164
diff changeset
206 and (remote_rev is None or is_remote_conflict)):
7b128ea29fc4 Further bug fixes in SyncPages and wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1164
diff changeset
207 self.log_status(ActionClass.WARN, _("Skipped page %(pagename)s because of a locally or remotely unresolved conflict.") % {"pagename": local_pagename})
7b128ea29fc4 Further bug fixes in SyncPages and wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1164
diff changeset
208 continue
7b128ea29fc4 Further bug fixes in SyncPages and wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1164
diff changeset
209
1141
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
210 if remote_rev is None: # set the remote_rev for the case without any tags
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
211 self.log_status(ActionClass.INFO, _("This is the first synchronisation between this page and the remote wiki."))
1141
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
212 remote_rev = current_remote_rev
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
213
1259
a76ce7b95190 SyncPages fixes, allow for the case where only the local page is changed.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1254
diff changeset
214 old_contents_dec = old_contents.decode("utf-8")
a76ce7b95190 SyncPages fixes, allow for the case where only the local page is changed.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1254
diff changeset
215 if diff is None:
a76ce7b95190 SyncPages fixes, allow for the case where only the local page is changed.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1254
diff changeset
216 new_contents = old_contents_dec
a76ce7b95190 SyncPages fixes, allow for the case where only the local page is changed.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1254
diff changeset
217 else:
a76ce7b95190 SyncPages fixes, allow for the case where only the local page is changed.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1254
diff changeset
218 new_contents = patch(old_contents, decompress(diff)).decode("utf-8")
a76ce7b95190 SyncPages fixes, allow for the case where only the local page is changed.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1254
diff changeset
219 old_contents = old_contents_dec
1041
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
220
1141
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
221 # here, the actual merge happens
1259
a76ce7b95190 SyncPages fixes, allow for the case where only the local page is changed.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1254
diff changeset
222 print "Merging %r, %r and %r" % (old_contents, new_contents, current_page.get_raw_body())
1253
9721b9e2a074 Use the new diff3 mode in SyncPages. Updated my CHANGES file.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1251
diff changeset
223 verynewtext = diff3.text_merge(old_contents, new_contents, current_page.get_raw_body(), 2, *conflict_markers)
1141
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
224
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
225 local_full_iwid = packLine([local.get_iwid(), local.get_interwiki_name()])
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
226 remote_full_iwid = packLine([remote.get_iwid(), remote.get_interwiki_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
227
1164
32c936ab469e Made SyncPages working, first page could be syncronised.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1159
diff changeset
228 diff = textdiff(new_contents.encode("utf-8"), verynewtext.encode("utf-8"))
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
229 #print "Diff against %r" % new_contents.encode("utf-8")
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
230
1141
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
231 comment = u"Local Merge - %r" % (remote.get_interwiki_name() or remote.get_iwid())
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
232
353c493dfb77 Added local conflict detection, logging support to SyncPages, updated my CHANGES file.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1141
diff changeset
233 # XXX upgrade to write lock
1141
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
234 try:
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
235 current_page.saveText(verynewtext, current_rev, comment=comment)
1259
a76ce7b95190 SyncPages fixes, allow for the case where only the local page is changed.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1254
diff changeset
236 except PageEditor.Unchanged:
a76ce7b95190 SyncPages fixes, allow for the case where only the local page is changed.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1254
diff changeset
237 pass
1141
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
238 except PageEditor.EditConflict:
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
239 assert False, "You stumbled on a problem with the current storage system - I cannot lock pages"
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
240
1259
a76ce7b95190 SyncPages fixes, allow for the case where only the local page is changed.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1254
diff changeset
241 new_local_rev = current_page.get_real_rev()
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
242
1259
a76ce7b95190 SyncPages fixes, allow for the case where only the local page is changed.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1254
diff changeset
243 try:
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
244 very_current_remote_rev = remote.merge_diff(rp.remote_name, compress(diff), new_local_rev, current_remote_rev, current_remote_rev, local_full_iwid)
1259
a76ce7b95190 SyncPages fixes, allow for the case where only the local page is changed.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1254
diff changeset
245 except Exception, e:
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
246 raise # XXX rollback locally
1259
a76ce7b95190 SyncPages fixes, allow for the case where only the local page is changed.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1254
diff changeset
247 else:
a76ce7b95190 SyncPages fixes, allow for the case where only the local page is changed.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1254
diff changeset
248 tags.add(remote_wiki=remote_full_iwid, remote_rev=very_current_remote_rev, current_rev=new_local_rev)
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
249
353c493dfb77 Added local conflict detection, logging support to SyncPages, updated my CHANGES file.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1141
diff changeset
250 if not wikiutil.containsConflictMarker(verynewtext):
353c493dfb77 Added local conflict detection, logging support to SyncPages, updated my CHANGES file.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1141
diff changeset
251 self.log_status(ActionClass.INFO, _("Page successfully merged."))
353c493dfb77 Added local conflict detection, logging support to SyncPages, updated my CHANGES file.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1141
diff changeset
252 else:
353c493dfb77 Added local conflict detection, logging support to SyncPages, updated my CHANGES file.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1141
diff changeset
253 self.log_status(ActionClass.WARN, _("Page merged with conflicts."))
353c493dfb77 Added local conflict detection, logging support to SyncPages, updated my CHANGES file.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1141
diff changeset
254
353c493dfb77 Added local conflict detection, logging support to SyncPages, updated my CHANGES file.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1141
diff changeset
255 # 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
256
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
257
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
258 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
259 ActionClass(pagename, request).render()