annotate MoinMoin/action/SyncPages.py @ 976:a442ed63b165

Reordered class hierachy of remote wikis, enhanced RemoteWiki interface
author Alexander Schremmer <alex AT alexanderweb DOT de>
date Sat, 15 Jul 2006 19:46:58 +0200
parents d24f2b1d606a
children b258156f1288
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
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
12 import zipfile
976
a442ed63b165 Reordered class hierachy of remote wikis, enhanced RemoteWiki interface
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 971
diff changeset
13 import xmlrpclib
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
14 from datetime import datetime
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
15
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
16 from MoinMoin import wikiutil, config, user
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
17 from MoinMoin.PageEditor import PageEditor
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
18 from MoinMoin.Page import Page
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
19 from MoinMoin.wikidicts import Dict
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
20
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
21 class ActionStatus(Exception): pass
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
22
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
23 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
24 """ 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
25 classes. """
a442ed63b165 Reordered class hierachy of remote wikis, enhanced RemoteWiki interface
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 971
diff changeset
26 def getInterwikiName(self):
a442ed63b165 Reordered class hierachy of remote wikis, enhanced RemoteWiki interface
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 971
diff changeset
27 """ 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
28 return NotImplemented
a442ed63b165 Reordered class hierachy of remote wikis, enhanced RemoteWiki interface
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 971
diff changeset
29
a442ed63b165 Reordered class hierachy of remote wikis, enhanced RemoteWiki interface
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 971
diff changeset
30 def __repr__(self):
a442ed63b165 Reordered class hierachy of remote wikis, enhanced RemoteWiki interface
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 971
diff changeset
31 """ Returns a representation of the instance for debugging purposes. """
a442ed63b165 Reordered class hierachy of remote wikis, enhanced RemoteWiki interface
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 971
diff changeset
32 return NotImplemented
a442ed63b165 Reordered class hierachy of remote wikis, enhanced RemoteWiki interface
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 971
diff changeset
33
a442ed63b165 Reordered class hierachy of remote wikis, enhanced RemoteWiki interface
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 971
diff changeset
34 class MoinWiki(RemoteWiki):
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
35 def __init__(self, interwikiname):
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
36 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
37 self.wiki_url = wikiutil.mapURL(self.request, wikiurl)
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
38 self.valid = not wikitag_bad
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
39 self.xmlrpc_url = self.wiki_url + "?action=xmlrpc2"
976
a442ed63b165 Reordered class hierachy of remote wikis, enhanced RemoteWiki interface
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 971
diff changeset
40 self.connection = self.createConnection()
a442ed63b165 Reordered class hierachy of remote wikis, enhanced RemoteWiki interface
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 971
diff changeset
41
a442ed63b165 Reordered class hierachy of remote wikis, enhanced RemoteWiki interface
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 971
diff changeset
42 def createConnection(self):
a442ed63b165 Reordered class hierachy of remote wikis, enhanced RemoteWiki interface
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 971
diff changeset
43 return xmlrpclib.ServerProxy(self.xmlrpc_url, allow_none=True)
a442ed63b165 Reordered class hierachy of remote wikis, enhanced RemoteWiki interface
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 971
diff changeset
44
a442ed63b165 Reordered class hierachy of remote wikis, enhanced RemoteWiki interface
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 971
diff changeset
45 # Methods implementing the RemoteWiki interface
a442ed63b165 Reordered class hierachy of remote wikis, enhanced RemoteWiki interface
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 971
diff changeset
46 def getInterwikiName(self):
a442ed63b165 Reordered class hierachy of remote wikis, enhanced RemoteWiki interface
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 971
diff changeset
47 return self.connection.interwikiName()
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
48
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
49 def __repr__(self):
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
50 return "<RemoteWiki wiki_url=%r valid=%r>" % (self.valid, self.wiki_url)
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
51
971
d24f2b1d606a Refactoring, fixed Fault codes, fixed return format of the getdiff method.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 970
diff changeset
52 class ActionClass:
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
53 def __init__(self, pagename, request):
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
54 self.request = request
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
55 self.pagename = pagename
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
56 self.page = Page(request, pagename)
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
57
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
58 def parsePage(self):
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
59 defaults = {
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
60 "remotePrefix": "",
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
61 "localPrefix": "",
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
62 "remoteWiki": ""
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
63 }
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
64
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
65 defaults.update(Dict(self.request, self.pagename).get_dict())
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
66 return defaults
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
67
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
68 def render(self):
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
69 """ Render action
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
70
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
71 This action returns a wiki page with optional message, or
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
72 redirects to new page.
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
73 """
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
74 _ = self.request.getText
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
75
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
76 params = self.parsePage()
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
77
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
78 try:
976
a442ed63b165 Reordered class hierachy of remote wikis, enhanced RemoteWiki interface
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 971
diff changeset
79 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
80 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
81
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
82 if not params["remoteWiki"]:
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
83 raise ActionStatus(_("Incorrect parameters. Please supply at least the ''remoteWiki'' parameter."))
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
84
976
a442ed63b165 Reordered class hierachy of remote wikis, enhanced RemoteWiki interface
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 971
diff changeset
85 remote = MoinWiki(params["remoteWiki"])
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
86
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
87 if not remote.valid:
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
88 raise ActionStatus(_("The ''remoteWiki'' is unknown."))
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
89
970
f29c09448353 Minor modifications.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 968
diff changeset
90 # ...
968
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
91 self.sync(params)
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
92 except ActionStatus, e:
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
93 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
94
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
95 raise ActionStatus(_("Syncronisation finished."))
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
96
3108c8b2597e Add preliminary SyncPages action.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
97 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
98 ActionClass(pagename, request).render()