Attachment 'append-text.py'

Download

   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__

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.
  • [get | view] (2008-12-15 16:36:18, 1.7 KB) [[attachment:append-text.patch]]
  • [get | view] (2005-05-29 04:18:27, 2.1 KB) [[attachment:append-text.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.