annotate MoinMoin/action/SyncPages.py @ 1159:0432e8a9ba2f

Added docstrings.
author Alexander Schremmer <alex AT alexanderweb DOT de>
date Tue, 08 Aug 2006 22:05:59 +0200
parents 353c493dfb77
children 32c936ab469e
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):
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
78 return u"%s<%r:%r>" % (self.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
1134
34abcbba032d Refactored some names in SyncPages
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1119
diff changeset
176 def get_pages(self):
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
1095
e2cc6b5bed96 Added detection of anonymous wikis to the SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1092
diff changeset
198 version = self.connection.getMoinVersion()
e2cc6b5bed96 Added detection of anonymous wikis to the SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1092
diff changeset
199 if not isinstance(version, (tuple, list)):
e2cc6b5bed96 Added detection of anonymous wikis to the SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1092
diff changeset
200 raise UnsupportedWikiException(_("The remote version of MoinMoin is too old, the version 1.6 is required at least."))
1135
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
201
1134
34abcbba032d Refactored some names in SyncPages
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1119
diff changeset
202 remote_interwikiname = self.get_interwiki_name()
1095
e2cc6b5bed96 Added detection of anonymous wikis to the SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1092
diff changeset
203 remote_iwid = self.connection.interwikiName()[1]
e2cc6b5bed96 Added detection of anonymous wikis to the SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1092
diff changeset
204 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
205 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
206 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
207 " internally than you specified (%(localname)s).") % {
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
208 "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
209
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
210 if self.is_anonymous:
1099
92f5835853ae Fixed full iwid for all cases.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1098
diff changeset
211 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
212 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
213 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
214
976
a442ed63b165 Reordered class hierachy of remote wikis, enhanced RemoteWiki interface
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 971
diff changeset
215 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
216 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
217
1141
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
218 # Public methods
1136
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
219 def get_diff(self, pagename, from_rev, to_rev):
1159
0432e8a9ba2f Added docstrings.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1158
diff changeset
220 """ 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
221 from_rev and to_rev. """
1136
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
222 return str(self.connection.getDiff(pagename, from_rev, to_rev))
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
223
976
a442ed63b165 Reordered class hierachy of remote wikis, enhanced RemoteWiki interface
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 971
diff changeset
224 # Methods implementing the RemoteWiki interface
1134
34abcbba032d Refactored some names in SyncPages
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1119
diff changeset
225 def get_interwiki_name(self):
1053
6632f9919a89 Implemented IWID system.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1043
diff changeset
226 return self.connection.interwikiName()[0]
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
227
1141
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
228 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
229 return self.connection.interwikiName()[1]
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
230
1134
34abcbba032d Refactored some names in SyncPages
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1119
diff changeset
231 def get_pages(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
232 pages = self.connection.getAllPagesEx({"include_revno": True, "include_deleted": True})
1135
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
233 rpages = []
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
234 for name, revno in pages:
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
235 normalised_name = normalise_pagename(name, self.prefix)
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
236 if normalised_name is None:
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
237 continue
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
238 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
239 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
240
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
241 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
242 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
243
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
244
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
245 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
246 """ Used for the current MoinMoin wiki. """
1135
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
247 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
248 self.request = request
1135
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
249 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
250
1092
f80e88b33c9d Added processing of local- and remoteMatch options to the SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1053
diff changeset
251 def getGroupItems(self, group_list):
1134
34abcbba032d Refactored some names in SyncPages
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1119
diff changeset
252 """ 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
253 pages = []
f80e88b33c9d Added processing of local- and remoteMatch options to the SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1053
diff changeset
254 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
255 pages.extend(Group(self.request, group_pagename).members())
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
256 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
257
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
258 def createSyncPage(self, page_name):
1135
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
259 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
260 if normalised_name is None:
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
261 return None
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
262 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
263
1141
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
264 # Public methods:
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
265
1041
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
266 # Methods implementing the RemoteWiki interface
1134
34abcbba032d Refactored some names in SyncPages
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1119
diff changeset
267 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
268 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
269
1141
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
270 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
271 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
272
1134
34abcbba032d Refactored some names in SyncPages
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1119
diff changeset
273 def get_pages(self):
1135
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
274 return [x for x in [self.createSyncPage(x) for x in self.request.rootpage.getPageList(exists=0)] 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
275
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
276 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
277 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
278
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
279
971
d24f2b1d606a Refactoring, fixed Fault codes, fixed return format of the getdiff method.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 970
diff changeset
280 class ActionClass:
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
281 INFO, WARNING, ERROR = range(3) # used for logging
353c493dfb77 Added local conflict detection, logging support to SyncPages, updated my CHANGES file.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1141
diff changeset
282
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
283 def __init__(self, pagename, request):
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
284 self.request = request
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
285 self.pagename = pagename
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
286 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
287 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
288
353c493dfb77 Added local conflict detection, logging support to SyncPages, updated my CHANGES file.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1141
diff changeset
289 def log_status(self, level, message):
1159
0432e8a9ba2f Added docstrings.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1158
diff changeset
290 """ 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
291 self.status.append((level, message))
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
292
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
293 def parse_page(self):
1159
0432e8a9ba2f Added docstrings.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1158
diff changeset
294 """ 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
295 options = {
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
296 "remotePrefix": "",
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
297 "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
298 "remoteWiki": "",
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
299 "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
300 "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
301 "groupList": None,
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
302 "direction": "foo", # is defaulted below
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
303 }
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
304
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
305 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
306
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
307 # 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
308 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
309 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
310 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
311 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
312
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
313 options["direction"] = directions_map.get(options["direction"], BOTH)
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
314
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
315 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
316
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 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
318 """ 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
319
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
320 # 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
321 if params["pageList"] is not None:
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
322 params["pageMatch"] = u'|'.join([r'^%s$' % re.escape(name)
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
323 for name in params["pageList"]])
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
324 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
325
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
326 if params["pageMatch"] is not None:
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
327 params["pageMatch"] = re.compile(params["pageMatch"], re.U)
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
328
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
329 # 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
330 if params["groupList"]:
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
331 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
332
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
333 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
334
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
335 def render(self):
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
336 """ Render action
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
337
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 This action returns a status message.
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
339 """
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
340 _ = 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
341
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
342 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
343
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
344 try:
976
a442ed63b165 Reordered class hierachy of remote wikis, enhanced RemoteWiki interface
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 971
diff changeset
345 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
346 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
347
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
348 if not params["remoteWiki"]:
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
349 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
350
1135
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
351 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
352 try:
1135
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
353 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
354 except UnsupportedWikiException, (msg, ):
e22024151c2c Fixed some bugs in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1096
diff changeset
355 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
356
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
357 if not remote.valid:
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
358 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
359
1041
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
360 self.sync(params, local, remote)
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
361 except ActionStatus, e:
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
362 return self.page.send_page(self.request, msg=u'<p class="error">%s</p><p>%s</p>\n' % (e.args[0], repr(self.status)))
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
363
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
364 return self.page.send_page(self.request, 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
365
1041
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
366 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
367 """ This method does the syncronisation work. """
1136
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
368
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
369 l_pages = local.get_pages()
1134
34abcbba032d Refactored some names in SyncPages
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1119
diff changeset
370 r_pages = remote.get_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
371
f80e88b33c9d Added processing of local- and remoteMatch options to the SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1053
diff changeset
372 if params["groupList"]:
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
373 pages_from_groupList = set(local.getGroupItems(params["groupList"]))
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
374 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
375 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
376
1141
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
377 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
378
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
379 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
380
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
381 if params["pageMatch"]:
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
382 m_pages = SyncPage.filter(m_pages, params["pageMatch"].match)
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
383 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
384
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
385 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
386 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
387 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
388
1136
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
389 # 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
390 #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
391 #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
392 #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))
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
393 #if params["direction"] in (DOWN, BOTH):
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
394 # for rp in remote_but_not_local:
1136
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
395
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
396 # 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
397 # 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
398 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
399 # XXX add locking, acquire read-lock on rp
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
400
1141
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
401 current_page = Page(self.request, local_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
402 if wikiutil.containsConflictMarker(current_page.get_raw_body()):
353c493dfb77 Added local conflict detection, logging support to SyncPages, updated my CHANGES file.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1141
diff changeset
403 self.log_status(ActionClass.WARN, _("Skipped page %(pagename)s because of a local unresolved conflict.") % {"pagename": local_pagename})
353c493dfb77 Added local conflict detection, logging support to SyncPages, updated my CHANGES file.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1141
diff changeset
404 continue
1141
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
405 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
406 local_pagename = rp.local_pagename
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
407
1141
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
408 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
409 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
410 matching_tags.sort()
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
411
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
412 if not matching_tags:
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
413 remote_rev = None
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
414 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
415 old_contents = ""
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
416 else:
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
417 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
418 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
419 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
420 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
421 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
422 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
423 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
424
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
425 self.log_status(ActionClass.INFO, _("Synchronising page %(pagename)s with remote page %(remotepagename)s ...") % {"pagename": local_pagename, "remotepagename": rp.remote_pagename})
353c493dfb77 Added local conflict detection, logging support to SyncPages, updated my CHANGES file.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1141
diff changeset
426
1141
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
427 diff_result = remote.get_diff(rp.remote_pagename, remote_rev, None)
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
428 is_remote_conflict = diff_result["conflict"]
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
429 assert diff_result["diffversion"] == 1
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
430 diff = diff_result["diff"]
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
431 current_remote_rev = diff_result["current"]
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
432
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
433 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
434 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
435 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
436
1136
4ba6da7e23a4 Started implementing the merging process. Not working yet.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1135
diff changeset
437 new_contents = patch(old_contents, decompress(diff)).decode("utf-8")
1141
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
438 old_contents = old_contents.encode("utf-8")
1041
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
439
1141
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
440 # here, the actual merge happens
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
441 verynewtext = diff3.text_merge(old_contents, new_contents, current_page.get_raw_body(), 1, *conflict_markers)
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
442
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
443 new_local_rev = current_rev + 1 # XXX commit first?
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
444 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
445 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
446
1141
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
447 very_current_remote_rev = remote.merge_diff(rp.remote_pagename, compress(textdiff(new_contents, verynewtext)), new_local_rev, remote_rev, current_remote_rev, local_full_iwid)
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
448 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
449
353c493dfb77 Added local conflict detection, logging support to SyncPages, updated my CHANGES file.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1141
diff changeset
450 # 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
451 try:
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
452 current_page.saveText(verynewtext, current_rev, comment=comment)
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
453 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
454 # 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
455 assert False, "You stumbled on a problem with the current storage system - I cannot lock pages"
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
456 tags.add(remote_wiki=remote_full_iwid, remote_rev=very_current_remote_rev, current_rev=new_local_rev)
353c493dfb77 Added local conflict detection, logging support to SyncPages, updated my CHANGES file.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1141
diff changeset
457
353c493dfb77 Added local conflict detection, logging support to SyncPages, updated my CHANGES file.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1141
diff changeset
458 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
459 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
460 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
461 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
462
353c493dfb77 Added local conflict detection, logging support to SyncPages, updated my CHANGES file.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1141
diff changeset
463 # XXX release lock
1141
0390d7857d87 Work on SyncPages, fixed prefix handling, wrote initial merge loop.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1136
diff changeset
464 # XXX untested
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
465
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
466
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
467 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
468 ActionClass(pagename, request).render()