comparison MoinMoin/action/SyncPages.py @ 968:3108c8b2597e

Add preliminary SyncPages action.
author Alexander Schremmer <alex AT alexanderweb DOT de>
date Sun, 09 Jul 2006 20:33:04 +0200
parents
children f29c09448353
comparison
equal deleted inserted replaced
967:675d01d7cb68 968:3108c8b2597e
1 # -*- coding: iso-8859-1 -*-
2 """
3 MoinMoin - SyncPages action
4
5 This action allows you to synchronise pages of two wikis.
6
7 @copyright: 2006 MoinMoin:AlexanderSchremmer
8 @license: GNU GPL, see COPYING for details.
9 """
10
11 import os
12 import zipfile
13 from datetime import datetime
14
15 from MoinMoin import wikiutil, config, user
16 from MoinMoin.PageEditor import PageEditor
17 from MoinMoin.Page import Page
18 from MoinMoin.wikidicts import Dict
19
20 class ActionStatus(Exception): pass
21
22 class RemoteWiki(object):
23 def __init__(self, interwikiname):
24 wikitag, wikiurl, wikitail, wikitag_bad = wikiutil.resolve_wiki(self.request, '%s:""' % (interwikiname, ))
25 self.wiki_url = wikiutil.mapURL(self.request, wikiurl)
26 self.valid = not wikitag_bad
27 self.xmlrpc_url = self.wiki_url + "?action=xmlrpc2"
28
29 def __repr__(self):
30 return "<RemoteWiki wiki_url=%r valid=%r>" % (self.valid, self.wiki_url)
31
32 class PackagePages:
33 def __init__(self, pagename, request):
34 self.request = request
35 self.pagename = pagename
36 self.page = Page(request, pagename)
37
38 def parsePage(self):
39 defaults = {
40 "remotePrefix": "",
41 "localPrefix": "",
42 "remoteWiki": ""
43 }
44
45 defaults.update(Dict(self.request, self.pagename).get_dict())
46 return defaults
47
48 def render(self):
49 """ Render action
50
51 This action returns a wiki page with optional message, or
52 redirects to new page.
53 """
54 _ = self.request.getText
55
56 params = self.parsePage()
57
58 try:
59 if not params["remoteWiki"]:
60 raise ActionStatus(_("Incorrect parameters. Please supply at least the ''remoteWiki'' parameter."))
61
62 remote = RemoteWiki(params["remoteWiki"])
63
64 if not remote.valid:
65 raise ActionStatus(_("The ''remoteWiki'' is unknown."))
66
67
68 self.sync(params)
69 except ActionStatus, e:
70 return self.page.send_page(self.request, msg=u'<p class="error">%s</p>\n' % (e.args[0], ))
71
72 raise ActionStatus(_("Syncronisation finished."))
73
74 def execute(pagename, request):
75 """ Glue code for actions """
76 PackagePages(pagename, request).render()