1 #!/usr/bin/env python
2 """
3 Append text to a wiki page
4 ==========================
5
6 Usage::
7
8 python append-text url pagename file
9
10 Append the text in filename to the page url/pagename, saving a backup
11 of the old revision and updating the logs. This should be equivalent to
12 editing the page manually with a browser.
13
14 file is just an example, you might want to customize this script to
15 read the data from another process, the web or whatever.
16
17 If pagename does not exists, it is created automatically. If pagename
18 is an underlay page, it will be copied into the data directory before
19 the edit is performed.
20
21 You should run the script with the same user and group as used by the
22 the wiki server, e.g. 'www-data', or the new revisions might be saved
23 with wrong owner, which will cause an IOError later when browsing the
24 wiki.
25
26 Examples::
27
28 sudo -u www-data python append-text.py 'localhost/mywiki/' \
29 'Additions' 'additions.txt'
30
31 Require MoinMoin release 1.3, tested with 1.3.4 patch 718.
32
33 WARNING: EXPERIMENTAL, USED WITH CATION!
34
35
36 @copyright: 2005 by Nir Soffer <nirs@freeshell.org>
37 @license: GNU GPL, see COPYING for details.
38 """
39
40 # Path configuration
41 import sys
42 sys.path = [# The path to the wiki directory
43 '/Volumes/Home/nir/wiki/fix',
44 # The path to moinmoin, not needed if its installed with setup.py
45 '/Volumes/Home/nir/Projects/moin/fix'] + sys.path
46
47
48 from MoinMoin.PageEditor import PageEditor
49 from MoinMoin.request import RequestCLI
50
51
52 def append(url, pagename, text):
53 request = RequestCLI(url=url, pagename=pagename)
54 editor = PageEditor(request, pagename)
55 text = editor.get_raw_body() + editor.normalizeText(text)
56 dummy, revision, exists = editor.get_rev()
57 return editor.saveText(text, revision)
58
59
60 if __name__ == '__main__':
61 """ Example: reading from file on disk using config.charset """
62 import codecs
63 from MoinMoin import config
64 try:
65 url, pagename, filename = sys.argv[1:]
66 text = codecs.open(filename, 'r', config.charset).read()
67 append(url, pagename, text)
68 except ValueError:
69 print __doc__
Script thows exception when using it with MoinMoin 1.5 beta 1
I tried the script with MoinMoin 1.5 beta 1 and got the error message "AttributeError: 'RequestCLI' object has no attribute 'theme' ".
Script works fine when using it with MoinMoin 1.5.3
I tried with 1.5.3-1.1ubuntu3 (Ubuntu 7.04)
Patch for use with 1.6
1 The append-text.py script from the script market does not seem to work with
2 MoinMoin 1.6. This patch attempts to make it work.
3
4 Please note that you must edit append-text.py to add your config dir
5 (where wikiconfig.py is) and the directory where the MoinMoin library
6 scripts are located to sys.path. If you want to edit MoinMoin pages that
7 are not world-writable, you must edit append-text.py to set the
8 'editor_email' variable.
9
10 To apply this patch run "patch -p 1 < append-text.patch" in the same dir as append-text.py.
11
12 -Dylan
13
14 --- old/append-text.py 2005-05-28 21:18:27.000000000 -0700
15 +++ patched/append-text.py 2008-11-11 14:27:00.000000000 -0800
16 @@ -44,14 +44,22 @@
17 # The path to moinmoin, not needed if its installed with setup.py
18 '/Volumes/Home/nir/Projects/moin/fix'] + sys.path
19
20 +# set this to the email addr of the moin user who this script should act as
21 +# or leave as None
22 +editor_email = None
23 +# editor_email = 'editor@example.com'
24
25 from MoinMoin.PageEditor import PageEditor
26 -from MoinMoin.request import RequestCLI
27 -
28 +from MoinMoin.request.request_cli import Request
29 +from MoinMoin.user import get_by_email_address
30
31 def append(url, pagename, text):
32 - request = RequestCLI(url=url, pagename=pagename)
33 + request = Request(url=url, pagename=pagename)
34 editor = PageEditor(request, pagename)
35 + if editor_email:
36 + if not get_by_email_address(request,editor_email):
37 + raise Exception, 'No MoinMoin user found with email address ' + editor_email
38 + request.user = get_by_email_address(request,editor_email)
39 text = editor.get_raw_body() + editor.normalizeText(text)
40 dummy, revision, exists = editor.get_rev()
41 return editor.saveText(text, revision)