annotate MoinMoin/action/SyncPages.py @ 1260:5d555ec6b40a

Fixed a bug that was hard to track down in SyncPages (some hours spent :-/).
author Alexander Schremmer <alex AT alexanderweb DOT de>
date Fri, 11 Aug 2006 22:28:14 +0200
parents a76ce7b95190
children ae9eb32b6899
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
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
13 import zipfile
976
a442ed63b165 Reordered class hierachy of remote wikis, enhanced RemoteWiki interface
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 971
diff changeset
14 import xmlrpclib
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
15 from datetime import datetime
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
16
1041
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
17 # 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
18 try:
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
19 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 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
21 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
22
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
23
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
24 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
25 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
26 from MoinMoin.PageEditor import PageEditor, conflict_markers
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
27 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
28 from MoinMoin.wikidicts import Dict, Group
1136
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
29 from MoinMoin.wikisync import TagStore
1141
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
30 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
31 from MoinMoin.util import diff3
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
32
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
33 # directions
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
34 UP, DOWN, BOTH = range(3)
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
35 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
36
1135
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
37
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
38 def normalise_pagename(page_name, prefix):
1159
0432e8a9ba2f Added docstrings.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1158
diff changeset
39 """ Checks if the page_name starts with the prefix.
0432e8a9ba2f Added docstrings.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1158
diff changeset
40 Returns None if it does not, otherwise strips the prefix.
0432e8a9ba2f Added docstrings.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1158
diff changeset
41 """
1135
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
42 if prefix:
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
43 if not page_name.startswith(prefix):
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
44 return None
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
45 else:
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
46 return page_name[len(prefix):]
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
47 else:
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
48 return page_name
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
49
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
50
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
51 class ActionStatus(Exception): pass
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
52
1095
e2cc6b5bed96 Added detection of anonymous wikis to the SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1092
diff changeset
53 class UnsupportedWikiException(Exception): pass
e2cc6b5bed96 Added detection of anonymous wikis to the SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1092
diff changeset
54
1136
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
55 # XXX Move these classes to MoinMoin.wikisync
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
56 class SyncPage(object):
1141
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
57 """ This class represents a page in one or two wiki(s). """
1135
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
58 def __init__(self, name, local_rev=None, remote_rev=None, local_name=None, remote_name=None):
1159
0432e8a9ba2f Added docstrings.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1158
diff changeset
59 """ Creates a SyncPage instance.
0432e8a9ba2f Added docstrings.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1158
diff changeset
60 @param name: The canonical name of the page, without prefixes.
0432e8a9ba2f Added docstrings.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1158
diff changeset
61 @param local_rev: The revision of the page in the local wiki.
0432e8a9ba2f Added docstrings.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1158
diff changeset
62 @param remote_rev: The revision of the page in the remote wiki.
0432e8a9ba2f Added docstrings.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1158
diff changeset
63 @param local_name: The page name of the page in the local wiki.
0432e8a9ba2f Added docstrings.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1158
diff changeset
64 @param remote_name: The page name of the page in the remote wiki.
0432e8a9ba2f Added docstrings.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1158
diff changeset
65 """
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
66 self.name = name
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
67 self.local_rev = local_rev
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
68 self.remote_rev = remote_rev
1135
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
69 self.local_name = local_name
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
70 self.remote_name = remote_name
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
71 assert local_rev or remote_rev
1135
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
72 assert local_name or remote_name
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
73
1041
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
74 def __repr__(self):
1097
e22024151c2c Fixed some bugs in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1096
diff changeset
75 return repr("<Remote Page %r>" % unicode(self))
1092
f80e88b33c9d Added processing of local- and remoteMatch options to the SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1053
diff changeset
76
f80e88b33c9d Added processing of local- and remoteMatch options to the SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1053
diff changeset
77 def __unicode__(self):
1164
32c936ab469e Made SyncPages working, first page could be syncronised.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1159
diff changeset
78 return u"%s[%s|%s]<%r:%r>" % (self.name, self.local_name, self.remote_name, self.local_rev, self.remote_rev)
1041
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
79
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
80 def __lt__(self, other):
1042
9e5749f46b74 Minor bug in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1041
diff changeset
81 return self.name < other.name
1041
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
82
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
83 def __hash__(self):
1159
0432e8a9ba2f Added docstrings.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1158
diff changeset
84 """ Ensures that the hash value of this page only depends on the canonical name. """
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
85 return hash(self.name)
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
86
1097
e22024151c2c Fixed some bugs in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1096
diff changeset
87 def __eq__(self, other):
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
88 if not isinstance(other, SyncPage):
1097
e22024151c2c Fixed some bugs in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1096
diff changeset
89 return false
e22024151c2c Fixed some bugs in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1096
diff changeset
90 return self.name == other.name
e22024151c2c Fixed some bugs in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1096
diff changeset
91
1141
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
92 def add_missing_pagename(self, local, remote):
1159
0432e8a9ba2f Added docstrings.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1158
diff changeset
93 """ Checks if the particular concrete page names are unknown and fills
0432e8a9ba2f Added docstrings.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1158
diff changeset
94 them in.
0432e8a9ba2f Added docstrings.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1158
diff changeset
95 """
1141
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
96 if self.local_name is None:
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
97 n_name = normalise_pagename(self.remote_name, remote.prefix)
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
98 assert n_name is not None
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
99 self.local_name = (local.prefix or "") + n_name
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
100 elif self.remote_name is None:
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
101 n_name = normalise_pagename(self.local_name, local.prefix)
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
102 assert n_name is not None
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
103 self.remote_name = (local.prefix or "") + n_name
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
104
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
105 return self # makes using list comps easier
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
106
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
107 def filter(cls, sp_list, func):
1159
0432e8a9ba2f Added docstrings.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1158
diff changeset
108 """ Returns all pages in sp_list that let func return True
0432e8a9ba2f Added docstrings.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1158
diff changeset
109 for the canonical page name.
0432e8a9ba2f Added docstrings.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1158
diff changeset
110 """
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
111 return [x for x in sp_list if func(x.name)]
1092
f80e88b33c9d Added processing of local- and remoteMatch options to the SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1053
diff changeset
112 filter = classmethod(filter)
f80e88b33c9d Added processing of local- and remoteMatch options to the SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1053
diff changeset
113
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
114 def merge(cls, local_list, remote_list):
1159
0432e8a9ba2f Added docstrings.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1158
diff changeset
115 """ Merges two lists of SyncPages into one, migrating attributes like the names. """
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
116 # map page names to SyncPage objects :-)
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
117 d = dict(zip(local_list, local_list))
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
118 for sp in remote_list:
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
119 if sp in d:
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
120 d[sp].remote_rev = sp.remote_rev
1135
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
121 d[sp].remote_name = sp.remote_name
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
122 else:
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
123 d[sp] = sp
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
124 return d.keys()
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
125 merge = classmethod(merge)
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
126
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
127 def is_only_local(self):
1159
0432e8a9ba2f Added docstrings.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1158
diff changeset
128 """ Is true if the page is only in the local wiki. """
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
129 return not self.remote_rev
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
130
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
131 def is_only_remote(self):
1159
0432e8a9ba2f Added docstrings.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1158
diff changeset
132 """ Is true if the page is only in the remote wiki. """
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
133 return not self.local_rev
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
134
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
135 def is_local_and_remote(self):
1159
0432e8a9ba2f Added docstrings.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1158
diff changeset
136 """ Is true if the page is in both wikis. """
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
137 return self.local_rev and self.remote_rev
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
138
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
139 def iter_local_only(cls, sp_list):
1159
0432e8a9ba2f Added docstrings.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1158
diff changeset
140 """ Iterates over all pages that are local only. """
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
141 for x in sp_list:
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
142 if x.is_only_local():
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
143 yield x
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
144 iter_local_only = classmethod(iter_local_only)
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
145
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
146 def iter_remote_only(cls, sp_list):
1159
0432e8a9ba2f Added docstrings.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1158
diff changeset
147 """ Iterates over all pages that are remote only. """
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
148 for x in sp_list:
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
149 if x.is_only_remote():
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
150 yield x
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
151 iter_remote_only = classmethod(iter_remote_only)
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 def iter_local_and_remote(cls, sp_list):
1159
0432e8a9ba2f Added docstrings.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1158
diff changeset
154 """ Iterates over all pages that are local and remote. """
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
155 for x in sp_list:
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
156 if x.is_local_and_remote():
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
157 yield x
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
158 iter_local_and_remote = classmethod(iter_local_and_remote)
1041
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
159
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
160 class RemoteWiki(object):
976
a442ed63b165 Reordered class hierachy of remote wikis, enhanced RemoteWiki interface
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 971
diff changeset
161 """ This class should be the base for all implementations of remote wiki
a442ed63b165 Reordered class hierachy of remote wikis, enhanced RemoteWiki interface
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 971
diff changeset
162 classes. """
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
163
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
164 def __repr__(self):
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
165 """ Returns a representation of the instance for debugging purposes. """
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
166 return NotImplemented
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
167
1134
34abcbba032d Refactored some names in SyncPages
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1119
diff changeset
168 def get_interwiki_name(self):
976
a442ed63b165 Reordered class hierachy of remote wikis, enhanced RemoteWiki interface
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 971
diff changeset
169 """ Returns the interwiki name of the other wiki. """
a442ed63b165 Reordered class hierachy of remote wikis, enhanced RemoteWiki interface
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 971
diff changeset
170 return NotImplemented
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
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 def get_iwid(self):
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
173 """ Returns the InterWiki ID. """
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
174 return NotImplemented
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
175
1254
7686daa0249c Small fixes, added direction support to get_pages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1253
diff changeset
176 def get_pages(self, **kwargs):
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
177 """ Returns a list of SyncPage instances. """
976
a442ed63b165 Reordered class hierachy of remote wikis, enhanced RemoteWiki interface
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 971
diff changeset
178 return NotImplemented
a442ed63b165 Reordered class hierachy of remote wikis, enhanced RemoteWiki interface
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 971
diff changeset
179
1041
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
180
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
181 class MoinRemoteWiki(RemoteWiki):
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
182 """ Used for MoinMoin wikis reachable via XMLRPC. """
1135
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
183 def __init__(self, request, interwikiname, prefix):
1041
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
184 self.request = request
1135
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
185 self.prefix = prefix
1095
e2cc6b5bed96 Added detection of anonymous wikis to the SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1092
diff changeset
186 _ = self.request.getText
1135
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
187
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
188 wikitag, wikiurl, wikitail, wikitag_bad = wikiutil.resolve_wiki(self.request, '%s:""' % (interwikiname, ))
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
189 self.wiki_url = wikiutil.mapURL(self.request, wikiurl)
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
190 self.valid = not wikitag_bad
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
191 self.xmlrpc_url = self.wiki_url + "?action=xmlrpc2"
1095
e2cc6b5bed96 Added detection of anonymous wikis to the SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1092
diff changeset
192 if not self.valid:
e2cc6b5bed96 Added detection of anonymous wikis to the SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1092
diff changeset
193 self.connection = None
e2cc6b5bed96 Added detection of anonymous wikis to the SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1092
diff changeset
194 return
1135
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
195
976
a442ed63b165 Reordered class hierachy of remote wikis, enhanced RemoteWiki interface
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 971
diff changeset
196 self.connection = self.createConnection()
1135
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
197
1254
7686daa0249c Small fixes, added direction support to get_pages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1253
diff changeset
198 iw_list = self.connection.interwikiName()
1135
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
199
1254
7686daa0249c Small fixes, added direction support to get_pages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1253
diff changeset
200 #version = self.connection.getMoinVersion()
7686daa0249c Small fixes, added direction support to get_pages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1253
diff changeset
201 #if not isinstance(version, (tuple, list)):
7686daa0249c Small fixes, added direction support to get_pages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1253
diff changeset
202 # raise UnsupportedWikiException(_("The remote version of MoinMoin is too old, the version 1.6 is required at least."))
7686daa0249c Small fixes, added direction support to get_pages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1253
diff changeset
203
7686daa0249c Small fixes, added direction support to get_pages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1253
diff changeset
204 self.remote_interwikiname = remote_interwikiname = iw_list[0]
7686daa0249c Small fixes, added direction support to get_pages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1253
diff changeset
205 self.remote_iwid = remote_iwid = iw_list[1]
1095
e2cc6b5bed96 Added detection of anonymous wikis to the SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1092
diff changeset
206 self.is_anonymous = remote_interwikiname is None
e2cc6b5bed96 Added detection of anonymous wikis to the SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1092
diff changeset
207 if not self.is_anonymous and interwikiname != remote_interwikiname:
1097
e22024151c2c Fixed some bugs in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1096
diff changeset
208 raise UnsupportedWikiException(_("The remote wiki uses a different InterWiki name (%(remotename)s)"
e22024151c2c Fixed some bugs in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1096
diff changeset
209 " internally than you specified (%(localname)s).") % {
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
210 "remotename": wikiutil.escape(remote_interwikiname), "localname": wikiutil.escape(interwikiname)})
976
a442ed63b165 Reordered class hierachy of remote wikis, enhanced RemoteWiki interface
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 971
diff changeset
211
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
212 if self.is_anonymous:
1099
92f5835853ae Fixed full iwid for all cases.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1098
diff changeset
213 self.iwid_full = packLine([remote_iwid])
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
214 else:
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
215 self.iwid_full = packLine([remote_iwid, interwikiname])
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
216
976
a442ed63b165 Reordered class hierachy of remote wikis, enhanced RemoteWiki interface
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 971
diff changeset
217 def createConnection(self):
1095
e2cc6b5bed96 Added detection of anonymous wikis to the SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1092
diff changeset
218 return xmlrpclib.ServerProxy(self.xmlrpc_url, allow_none=True, verbose=True)
976
a442ed63b165 Reordered class hierachy of remote wikis, enhanced RemoteWiki interface
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 971
diff changeset
219
1141
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
220 # Public methods
1136
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
221 def get_diff(self, pagename, from_rev, to_rev):
1159
0432e8a9ba2f Added docstrings.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1158
diff changeset
222 """ Returns the binary diff of the remote page named pagename, given
0432e8a9ba2f Added docstrings.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1158
diff changeset
223 from_rev and to_rev. """
1164
32c936ab469e Made SyncPages working, first page could be syncronised.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1159
diff changeset
224 result = self.connection.getDiff(pagename, from_rev, to_rev)
32c936ab469e Made SyncPages working, first page could be syncronised.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1159
diff changeset
225 result["diff"] = str(result["diff"]) # unmarshal Binary object
32c936ab469e Made SyncPages working, first page could be syncronised.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1159
diff changeset
226 return result
32c936ab469e Made SyncPages working, first page could be syncronised.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1159
diff changeset
227
32c936ab469e Made SyncPages working, first page could be syncronised.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1159
diff changeset
228 def merge_diff(self, pagename, diff, local_rev, delta_remote_rev, last_remote_rev, interwiki_name):
32c936ab469e Made SyncPages working, first page could be syncronised.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1159
diff changeset
229 """ Merges the diff into the page on the remote side. """
32c936ab469e Made SyncPages working, first page could be syncronised.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1159
diff changeset
230 result = self.connection.mergeDiff(pagename, xmlrpclib.Binary(diff), local_rev, delta_remote_rev, last_remote_rev, interwiki_name)
32c936ab469e Made SyncPages working, first page could be syncronised.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1159
diff changeset
231 return result
1136
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
232
976
a442ed63b165 Reordered class hierachy of remote wikis, enhanced RemoteWiki interface
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 971
diff changeset
233 # Methods implementing the RemoteWiki interface
1134
34abcbba032d Refactored some names in SyncPages
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1119
diff changeset
234 def get_interwiki_name(self):
1254
7686daa0249c Small fixes, added direction support to get_pages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1253
diff changeset
235 return self.remote_interwikiname
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
236
1141
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
237 def get_iwid(self):
1254
7686daa0249c Small fixes, added direction support to get_pages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1253
diff changeset
238 return self.remote_iwid
1141
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
239
1254
7686daa0249c Small fixes, added direction support to get_pages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1253
diff changeset
240 def get_pages(self, **kwargs):
7686daa0249c Small fixes, added direction support to get_pages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1253
diff changeset
241 options = {"include_revno": True,
7686daa0249c Small fixes, added direction support to get_pages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1253
diff changeset
242 "include_deleted": True,
7686daa0249c Small fixes, added direction support to get_pages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1253
diff changeset
243 "exclude_non_writable": kwargs["exclude_non_writable"]}
7686daa0249c Small fixes, added direction support to get_pages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1253
diff changeset
244 pages = self.connection.getAllPagesEx(options)
1135
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
245 rpages = []
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
246 for name, revno in pages:
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
247 normalised_name = normalise_pagename(name, self.prefix)
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
248 if normalised_name is None:
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
249 continue
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
250 rpages.append(SyncPage(normalised_name, remote_rev=revno, remote_name=name))
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
251 return rpages
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
252
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
253 def __repr__(self):
1041
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
254 return "<MoinRemoteWiki wiki_url=%r valid=%r>" % (self.wiki_url, self.valid)
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
255
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
256
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
257 class MoinLocalWiki(RemoteWiki):
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
258 """ Used for the current MoinMoin wiki. """
1135
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
259 def __init__(self, request, prefix):
1041
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
260 self.request = request
1135
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
261 self.prefix = prefix
1041
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
262
1092
f80e88b33c9d Added processing of local- and remoteMatch options to the SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1053
diff changeset
263 def getGroupItems(self, group_list):
1134
34abcbba032d Refactored some names in SyncPages
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1119
diff changeset
264 """ Returns all page names that are listed on the page group_list. """
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 pages = []
f80e88b33c9d Added processing of local- and remoteMatch options to the SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1053
diff changeset
266 for group_pagename in group_list:
f80e88b33c9d Added processing of local- and remoteMatch options to the SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1053
diff changeset
267 pages.extend(Group(self.request, group_pagename).members())
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
268 return [self.createSyncPage(x) for x in pages]
1092
f80e88b33c9d Added processing of local- and remoteMatch options to the SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1053
diff changeset
269
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
270 def createSyncPage(self, page_name):
1135
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
271 normalised_name = normalise_pagename(page_name, self.prefix)
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
272 if normalised_name is None:
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
273 return None
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
274 return SyncPage(normalised_name, local_rev=Page(self.request, page_name).get_real_rev(), local_name=page_name)
1092
f80e88b33c9d Added processing of local- and remoteMatch options to the SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1053
diff changeset
275
1141
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
276 # Public methods:
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
277
1041
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
278 # Methods implementing the RemoteWiki interface
1134
34abcbba032d Refactored some names in SyncPages
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1119
diff changeset
279 def get_interwiki_name(self):
1041
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
280 return self.request.cfg.interwikiname
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
281
1141
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
282 def get_iwid(self):
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
283 return self.request.cfg.iwid
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
284
1254
7686daa0249c Small fixes, added direction support to get_pages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1253
diff changeset
285 def get_pages(self, **kwargs):
7686daa0249c Small fixes, added direction support to get_pages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1253
diff changeset
286 assert not kwargs
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
287 return [x for x in [self.createSyncPage(x) for x in self.request.rootpage.getPageList(exists=1)] if x]
1041
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
288
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
289 def __repr__(self):
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
290 return "<MoinLocalWiki>"
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
291
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
292
971
d24f2b1d606a Refactoring, fixed Fault codes, fixed return format of the getdiff method.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 970
diff changeset
293 class ActionClass:
1164
32c936ab469e Made SyncPages working, first page could be syncronised.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1159
diff changeset
294 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
295
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
296 def __init__(self, pagename, request):
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
297 self.request = request
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
298 self.pagename = pagename
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
299 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
300 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
301
353c493dfb77 Added local conflict detection, logging support to SyncPages, updated my CHANGES file.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1141
diff changeset
302 def log_status(self, level, message):
1159
0432e8a9ba2f Added docstrings.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1158
diff changeset
303 """ 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
304 self.status.append((level, message))
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
305
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
306 def parse_page(self):
1159
0432e8a9ba2f Added docstrings.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1158
diff changeset
307 """ 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
308 options = {
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
309 "remotePrefix": "",
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
310 "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
311 "remoteWiki": "",
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
312 "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
313 "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
314 "groupList": None,
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
315 "direction": "foo", # is defaulted below
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
316 }
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
317
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
318 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
319
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
320 # 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
321 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
322 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
323 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
324 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
325
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
326 options["direction"] = directions_map.get(options["direction"], BOTH)
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
327
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
328 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
329
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
330 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
331 """ 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
332
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
333 # 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
334 if params["pageList"] is not None:
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
335 params["pageMatch"] = u'|'.join([r'^%s$' % re.escape(name)
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
336 for name in params["pageList"]])
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
337 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
338
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
339 if params["pageMatch"] is not None:
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
340 params["pageMatch"] = re.compile(params["pageMatch"], re.U)
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
341
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
342 # 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
343 if params["groupList"]:
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
344 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
345
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
346 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
347
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
348 def render(self):
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
349 """ Render action
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
350
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
351 This action returns a status message.
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
352 """
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
353 _ = 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
354
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
355 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
356
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
357 try:
976
a442ed63b165 Reordered class hierachy of remote wikis, enhanced RemoteWiki interface
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 971
diff changeset
358 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
359 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
360
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
361 if not params["remoteWiki"]:
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
362 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
363
1135
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
364 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
365 try:
1135
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
366 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
367 except UnsupportedWikiException, (msg, ):
e22024151c2c Fixed some bugs in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1096
diff changeset
368 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
369
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
370 if not remote.valid:
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
371 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
372
1041
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
373 self.sync(params, local, remote)
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
374 except ActionStatus, e:
1164
32c936ab469e Made SyncPages working, first page could be syncronised.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1159
diff changeset
375 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
376 else:
32c936ab469e Made SyncPages working, first page could be syncronised.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1159
diff changeset
377 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
378
1164
32c936ab469e Made SyncPages working, first page could be syncronised.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1159
diff changeset
379 # 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
380 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
381
1041
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
382 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
383 """ 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
384 _ = self.request.getText
1136
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
385
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
386 l_pages = local.get_pages()
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
387 r_pages = remote.get_pages(exclude_non_writable=params["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
388
f80e88b33c9d Added processing of local- and remoteMatch options to the SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1053
diff changeset
389 if params["groupList"]:
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
390 pages_from_groupList = set(local.getGroupItems(params["groupList"]))
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
391 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
392 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
393
1141
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
394 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
395
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
396 print "Got %i local, %i remote pages, %i merged pages" % (len(l_pages), len(r_pages), len(m_pages))
1098
cdd1ea31f00e Added sample code for set logic in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1097
diff changeset
397
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
398 if params["pageMatch"]:
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
399 m_pages = SyncPage.filter(m_pages, params["pageMatch"].match)
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
400 print "After filtering: Got %i merges pages" % (len(m_pages), )
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
401
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
402 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
403 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
404 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
405
1136
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
406 # 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
407 #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
408 #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
409 #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
410
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
411 # 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
412 # 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
413 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
414 # 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
415 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
416
1164
32c936ab469e Made SyncPages working, first page could be syncronised.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1159
diff changeset
417 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
418 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
419 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
420
1141
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
421 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
422 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
423 matching_tags.sort()
1251
7b128ea29fc4 Further bug fixes in SyncPages and wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1164
diff changeset
424 #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
425
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
426 if not matching_tags:
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
427 remote_rev = None
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
428 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
429 old_contents = ""
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
430 else:
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
431 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
432 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
433 remote_rev = newest_tag.remote_rev
1141
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
434 if remote_rev == rp.remote_rev and local_rev == current_rev:
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
435 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
436 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
437 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
438
1164
32c936ab469e Made SyncPages working, first page could be syncronised.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1159
diff changeset
439 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
440
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
441 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
442 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
443 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
444 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
445 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
446 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
447 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
448 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
449 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
450 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
451
1251
7b128ea29fc4 Further bug fixes in SyncPages and wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1164
diff changeset
452 # 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
453 # 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
454 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
455 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
456 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
457 continue
7b128ea29fc4 Further bug fixes in SyncPages and wikisync
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1164
diff changeset
458
1141
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
459 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
460 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
461 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
462
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
463 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
464 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
465 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
466 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
467 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
468 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
469
1141
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
470 # 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
471 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
472 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
473
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
474 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
475 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
476
1164
32c936ab469e Made SyncPages working, first page could be syncronised.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1159
diff changeset
477 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
478 #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
479
1141
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
480 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
481
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 # 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
483 try:
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
484 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
485 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
486 pass
1141
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
487 except PageEditor.EditConflict:
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
488 # XXX remote rollback needed
1141
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
489 assert False, "You stumbled on a problem with the current storage system - I cannot lock pages"
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
490 new_local_rev = current_page.get_real_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
491 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
492 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
493 except Exception, e:
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
494 raise # XXX rollback
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
495 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
496 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
497
353c493dfb77 Added local conflict detection, logging support to SyncPages, updated my CHANGES file.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1141
diff changeset
498 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
499 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
500 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
501 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
502
353c493dfb77 Added local conflict detection, logging support to SyncPages, updated my CHANGES file.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1141
diff changeset
503 # 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
504
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
505
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
506 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
507 ActionClass(pagename, request).render()