annotate MoinMoin/action/SyncPages.py @ 1135:bf5f8afacf59

Added prefix handling to SyncPages.
author Alexander Schremmer <alex AT alexanderweb DOT de>
date Fri, 04 Aug 2006 21:34:36 +0200
parents 34abcbba032d
children 4ba6da7e23a4
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
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
26 from MoinMoin.PageEditor import PageEditor
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
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
29
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
30 # directions
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
31 UP, DOWN, BOTH = range(3)
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
32 directions_map = {"up": UP, "down": DOWN, "both": BOTH}
1041
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
33
1135
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
34
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
35 def normalise_pagename(page_name, prefix):
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
36 if prefix:
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
37 if not page_name.startswith(prefix):
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
38 return None
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
39 else:
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
40 return page_name[len(prefix):]
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
41 else:
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
42 return page_name
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
43
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
44
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
45 class ActionStatus(Exception): pass
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
46
1095
e2cc6b5bed96 Added detection of anonymous wikis to the SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1092
diff changeset
47 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
48
1092
f80e88b33c9d Added processing of local- and remoteMatch options to the SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1053
diff changeset
49 # Move these classes to MoinMoin.wikisync
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
50 class SyncPage(object):
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
51 """ This class represents a page in (another) wiki. """
1135
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
52 def __init__(self, name, local_rev=None, remote_rev=None, local_name=None, remote_name=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
53 self.name = name
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
54 self.local_rev = local_rev
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
55 self.remote_rev = remote_rev
1135
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
56 self.local_name = local_name
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
57 self.remote_name = remote_name
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
58 assert local_rev or remote_rev
1135
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
59 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
60
1041
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
61 def __repr__(self):
1097
e22024151c2c Fixed some bugs in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1096
diff changeset
62 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
63
f80e88b33c9d Added processing of local- and remoteMatch options to the SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1053
diff changeset
64 def __unicode__(self):
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
65 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
66
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
67 def __lt__(self, other):
1042
9e5749f46b74 Minor bug in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1041
diff changeset
68 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
69
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
70 def __hash__(self):
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
71 return hash(self.name)
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
72
1097
e22024151c2c Fixed some bugs in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1096
diff changeset
73 def __eq__(self, other):
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
74 if not isinstance(other, SyncPage):
1097
e22024151c2c Fixed some bugs in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1096
diff changeset
75 return false
e22024151c2c Fixed some bugs in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1096
diff changeset
76 return self.name == other.name
e22024151c2c Fixed some bugs in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1096
diff changeset
77
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
78 def filter(cls, sp_list, func):
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
79 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
80 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
81
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
82 def merge(cls, local_list, remote_list):
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
83 # map page names to SyncPage objects :-)
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
84 d = dict(zip(local_list, local_list))
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
85 for sp in remote_list:
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
86 if sp in d:
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
87 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
88 d[sp].remote_name = sp.remote_name
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
89 else:
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
90 d[sp] = sp
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
91 return d.keys()
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
92 merge = classmethod(merge)
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
93
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
94 def is_only_local(self):
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
95 return not self.remote_rev
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
96
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
97 def is_only_remote(self):
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
98 return not self.local_rev
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
99
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
100 def is_local_and_remote(self):
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
101 return self.local_rev and self.remote_rev
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
102
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
103 def iter_local_only(cls, sp_list):
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
104 for x in sp_list:
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
105 if x.is_only_local():
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
106 yield x
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
107 iter_local_only = classmethod(iter_local_only)
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
108
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
109 def iter_remote_only(cls, sp_list):
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
110 for x in sp_list:
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
111 if x.is_only_remote():
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
112 yield x
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
113 iter_remote_only = classmethod(iter_remote_only)
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
114
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
115 def iter_local_and_remote(cls, sp_list):
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
116 for x in sp_list:
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
117 if x.is_local_and_remote():
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
118 yield x
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
119 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
120
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
121 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
122 """ 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
123 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
124
807f80c76d81 Work on SyncPages. Fixed a few bugs, added new method to RemoteWiki, build regexes from the RemotePageList.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 977
diff changeset
125 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
126 """ 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
127 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
128
1134
34abcbba032d Refactored some names in SyncPages
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1119
diff changeset
129 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
130 """ 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
131 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
132
1134
34abcbba032d Refactored some names in SyncPages
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1119
diff changeset
133 def get_pages(self):
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
134 """ 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
135 return NotImplemented
a442ed63b165 Reordered class hierachy of remote wikis, enhanced RemoteWiki interface
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 971
diff changeset
136
1041
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
137
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
138 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
139 """ 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
140 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
141 self.request = request
1135
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
142 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
143 _ = self.request.getText
1135
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
144
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
145 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
146 self.wiki_url = wikiutil.mapURL(self.request, wikiurl)
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
147 self.valid = not wikitag_bad
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
148 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
149 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
150 self.connection = None
e2cc6b5bed96 Added detection of anonymous wikis to the SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1092
diff changeset
151 return
1135
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
152
976
a442ed63b165 Reordered class hierachy of remote wikis, enhanced RemoteWiki interface
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 971
diff changeset
153 self.connection = self.createConnection()
1135
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
154
1095
e2cc6b5bed96 Added detection of anonymous wikis to the SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1092
diff changeset
155 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
156 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
157 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
158
1134
34abcbba032d Refactored some names in SyncPages
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1119
diff changeset
159 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
160 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
161 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
162 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
163 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
164 " internally than you specified (%(localname)s).") % {
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
165 "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
166
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
167 if self.is_anonymous:
1099
92f5835853ae Fixed full iwid for all cases.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1098
diff changeset
168 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
169 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
170 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
171
976
a442ed63b165 Reordered class hierachy of remote wikis, enhanced RemoteWiki interface
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 971
diff changeset
172 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
173 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
174
a442ed63b165 Reordered class hierachy of remote wikis, enhanced RemoteWiki interface
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 971
diff changeset
175 # Methods implementing the RemoteWiki interface
1134
34abcbba032d Refactored some names in SyncPages
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1119
diff changeset
176 def get_interwiki_name(self):
1053
6632f9919a89 Implemented IWID system.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1043
diff changeset
177 return self.connection.interwikiName()[0]
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
178
1134
34abcbba032d Refactored some names in SyncPages
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1119
diff changeset
179 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
180 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
181 rpages = []
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
182 for name, revno in pages:
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
183 normalised_name = normalise_pagename(name, self.prefix)
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
184 if normalised_name is None:
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
185 continue
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
186 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
187 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
188
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
189 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
190 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
191
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
192
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
193 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
194 """ Used for the current MoinMoin wiki. """
1135
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
195 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
196 self.request = request
1135
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
197 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
198
1092
f80e88b33c9d Added processing of local- and remoteMatch options to the SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1053
diff changeset
199 def getGroupItems(self, group_list):
1134
34abcbba032d Refactored some names in SyncPages
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1119
diff changeset
200 """ 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
201 pages = []
f80e88b33c9d Added processing of local- and remoteMatch options to the SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1053
diff changeset
202 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
203 pages.extend(Group(self.request, group_pagename).members())
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
204 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
205
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
206 def createSyncPage(self, page_name):
1135
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
207 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
208 if normalised_name is None:
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
209 return None
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
210 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
211
1041
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
212 # Methods implementing the RemoteWiki interface
1134
34abcbba032d Refactored some names in SyncPages
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1119
diff changeset
213 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
214 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
215
1134
34abcbba032d Refactored some names in SyncPages
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1119
diff changeset
216 def get_pages(self):
1135
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
217 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
218
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
219 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
220 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
221
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
222
971
d24f2b1d606a Refactoring, fixed Fault codes, fixed return format of the getdiff method.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 970
diff changeset
223 class ActionClass:
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
224 def __init__(self, pagename, request):
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
225 self.request = request
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
226 self.pagename = pagename
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
227 self.page = Page(request, pagename)
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
228
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
229 def parse_page(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
230 options = {
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
231 "remotePrefix": "",
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
232 "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
233 "remoteWiki": "",
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
234 "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
235 "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
236 "groupList": None,
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
237 "direction": "foo", # is defaulted below
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
238 }
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
239
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 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
241
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
242 # 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
243 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
244 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
245 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
246 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
247
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
248 options["direction"] = directions_map.get(options["direction"], BOTH)
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
249
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
250 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
251
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 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
253 """ 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
254
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
255 # 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
256 if params["pageList"] is not None:
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
257 params["pageMatch"] = u'|'.join([r'^%s$' % re.escape(name)
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
258 for name in params["pageList"]])
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
259 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
260
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
261 if params["pageMatch"] is not None:
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
262 params["pageMatch"] = re.compile(params["pageMatch"], re.U)
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
263
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
264 # 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
265 if params["groupList"]:
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
266 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
267
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
268 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
269
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
270 def render(self):
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
271 """ Render action
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
272
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
273 This action returns a status message.
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
274 """
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
275 _ = 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
276
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
277 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
278
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
279 try:
976
a442ed63b165 Reordered class hierachy of remote wikis, enhanced RemoteWiki interface
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 971
diff changeset
280 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
281 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
282
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
283 if not params["remoteWiki"]:
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
284 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
285
1135
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
286 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
287 try:
1135
bf5f8afacf59 Added prefix handling to SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1134
diff changeset
288 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
289 except UnsupportedWikiException, (msg, ):
e22024151c2c Fixed some bugs in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1096
diff changeset
290 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
291
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
292 if not remote.valid:
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
293 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
294
1041
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
295 self.sync(params, local, remote)
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
296 except ActionStatus, e:
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
297 return self.page.send_page(self.request, msg=u'<p class="error">%s</p>\n' % (e.args[0], ))
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
298
977
b258156f1288 Added question to my CHANGES file, fixed a bug in SyncPages
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 976
diff changeset
299 return self.page.send_page(self.request, msg=_("Syncronisation finished."))
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
300
1041
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
301 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
302 """ This method does the syncronisation work. """
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
303
1134
34abcbba032d Refactored some names in SyncPages
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1119
diff changeset
304 r_pages = remote.get_pages()
34abcbba032d Refactored some names in SyncPages
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1119
diff changeset
305 l_pages = local.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
306
f80e88b33c9d Added processing of local- and remoteMatch options to the SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1053
diff changeset
307 if params["groupList"]:
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
308 pages_from_groupList = set(local.getGroupItems(params["groupList"]))
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
309 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
310 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
311
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
312 m_pages = SyncPage.merge(l_pages, r_pages)
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
313
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
314 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
315
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
316 if params["pageMatch"]:
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
317 m_pages = SyncPage.filter(m_pages, params["pageMatch"].match)
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
318 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
319
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
320 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
321 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
322 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
323
1041
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
324 # some initial test code
1098
cdd1ea31f00e Added sample code for set logic in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1097
diff changeset
325 r_new_pages = u", ".join([unicode(x) for x in remote_but_not_local])
cdd1ea31f00e Added sample code for set logic in SyncPages.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1097
diff changeset
326 l_new_pages = u", ".join([unicode(x) for x in local_but_not_remote])
1119
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
327 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))
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
328 #if params["direction"] in (DOWN, BOTH):
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
329 # for rp in remote_but_not_local:
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
330 # XXX add locking, acquire read-lock on rp
397b97122ad9 General SyncPages refactoring:
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1099
diff changeset
331
1041
f9568edf1ff0 Introduced MoinLocalWiki class, added code that compares page lists for testing.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1030
diff changeset
332
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
333
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
334 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
335 ActionClass(pagename, request).render()