Attachment 'wikiput.py'
Download 1 #!/usr/local/bin/python
2 # -*- coding: iso-8859-1 -*-
3 #
4 # wikiput.py v1.0
5 #
6 # Update a Moin page.
7 #
8 # By: Max Campos <mcampos@bpsw.biz>
9 # Sept. 1, 2005
10
11 import sys
12 import os
13
14 def parseOpts():
15 from optparse import OptionParser
16
17 usage = "usage: %prog [options] SomePage < page.txt"
18 op = OptionParser(usage=usage)
19 op.add_option('-w', '--wikidir', dest='wikidir',
20 help="Dir containing your wikiconf.py");
21
22 op.add_option('-u', '--user', dest='user',
23 help="Username to make changes as")
24
25 op.add_option('-c', '--comment', dest='comment', default='',
26 help="Comment")
27
28 op.add_option('-t', '--trivial', dest='trivial', action='store_true',
29 help="Trivial change?")
30
31 op.add_option('-x', '--ignore-unchanged', dest='ignore_unchanged',
32 action='store_true', help='Silently ignore edits which do not change the page?')
33
34 op.add_option('-p', '--print', dest='prt', action='store_true',
35 help='Print the new raw page text')
36
37 (options, args) = op.parse_args()
38 if len(args) > 0:
39 options.pagename = args[0]
40 else:
41 op.error("You must specify a page name.")
42
43 return options
44
45
46 opts = parseOpts() or sys.exit(1)
47
48 # Do chdir to the wikidir so that any relative file paths in
49 # the wiki config work.
50 if opts.wikidir:
51 os.chdir(opts.wikidir)
52 sys.path.append(opts.wikidir)
53
54 from MoinMoin.request import RequestCLI
55 from MoinMoin.PageEditor import PageEditor
56 from MoinMoin.user import User
57 from datetime import datetime
58 from MoinMoin.Page import Page
59 request = RequestCLI(url='foo')
60 request.user = User(request=request, auth_username=opts.user)
61 request.form = {}
62 ed = PageEditor(request, opts.pagename, trivial=opts.trivial)
63
64 newtext = sys.stdin.read()
65
66 try:
67 ed.saveText(newtext, 0, comment=unicode(opts.comment) or u'')
68 except PageEditor.Unchanged:
69 if not opts.ignore_unchanged:
70 raise
71
72 # Return the raw wiki text.
73 if opts.prt:
74 p = Page(request, opts.pagename)
75 print p.getPageText()
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.