Attachment 'text_x_exportfile-1.6.0-3.py'

Download

   1 # -*- coding: iso-8859-1 -*-
   2 """
   3     MoinMoin - ExportFile parser
   4 
   5     PURPOSE:
   6       This parser is used to download some content of a wiki page to a file. It needs the action exportfile.py
   7 
   8     CALLING SEQUENCE:
   9       {{{
  10       #!ExportFile [file=file]
  11       = Example =
  12       }}}
  13 
  14     OPTIONAL KEYWORD PARAMETERS:
  15         file:              file name to save to
  16 
  17     EXAMPLE:
  18 {{{#!ExportFile
  19 = some wiki mark up =
  20  * A
  21  * B
  22 }}}
  23 
  24 
  25 {{{#!ExportFile file=example.txt
  26 #format plain
  27 AAEE BBAA CCAA
  28 DDDE FFAE BBCD
  29 }}}
  30 
  31 
  32 {{{#!ExportFile file=example.py
  33 #format python
  34 def format(self, formatter):
  35     self.pagename = formatter.page.page_name
  36     self.quoted_pagename = wikiutil.quoteWikinameURL(self.pagename)
  37     attachment_path = AttachFile.getAttachDir(self.request, self.pagename, create=1)
  38 }}}
  39 
  40 
  41     PROCEDURE:
  42       ABOUT:
  43       This parser is the result of a discussion with ThiloPfennig about saving conten of a page to a file 
  44       while editing functionality is done from the wiki. see FeatureRequests/ExportFileAction
  45 
  46     MODIFICATION HISTORY:
  47         Version 1.6.0-1
  48         1.6.0-2 some code cleanup
  49         1.6.0-3 some more code moved to wikiutil
  50         @copyright: 2007 by Reimar Bauer (R.Bauer@fz-juelich.de)
  51         @license: GNU GPL, see COPYING for details.
  52 
  53 """
  54 Dependencies = ['time'] # do not cache
  55 import StringIO, codecs
  56 from MoinMoin.action import AttachFile
  57 from MoinMoin import wikiutil
  58 from MoinMoin.parser import text_moin_wiki
  59 
  60 class Parser:
  61     extensions = '*'
  62     def __init__(self, raw, request, **kw):
  63         self.file = 'exportfile.txt'
  64         test = kw.get('format_args', '')
  65         if test:
  66             for arg in kw.get('format_args', '').split(','):
  67                 if arg.find('=') > -1:
  68                     key, value = arg.split('=')
  69                     setattr(self, key, wikiutil.escape(value.strip(), quote=1))
  70         self.raw = raw
  71         self.request = request
  72         self.form = request.form
  73         self._ = request.getText
  74 
  75 
  76     def format(self, formatter):
  77         self.pagename = formatter.page.page_name
  78         self.quoted_pagename = wikiutil.quoteWikinameURL(self.pagename)
  79         attachment_path = AttachFile.getAttachDir(self.request, self.pagename, create=1)
  80 
  81         Parser = wikiutil.get_parser(self.request, self.raw)
  82 
  83         lines = self.raw.split('\n')
  84         raw = []
  85         for line in lines:
  86             is_good = True
  87             for pi in ("#format", "#refresh", "#redirect", "#deprecated",
  88                        "#pragma", "#form", "#acl", "#language"):
  89                 if line.lower().startswith(pi):
  90                    is_good = False
  91                    break
  92             if is_good:
  93                raw.append(line)
  94         raw = '\n'.join(raw)
  95 
  96         out = StringIO.StringIO()
  97         self.request.redirect(out)
  98         wikiizer = Parser(raw, self.request)
  99         wikiizer.format(formatter)
 100         result = out.getvalue()
 101         self.request.redirect()
 102         del out
 103 
 104         self.request.write(result)
 105 
 106         form = """
 107 <form action="%(baseurl)s/%(pagename)s" method="POST" enctype="multipart/form-data">
 108    <input type="hidden" name="action" value="exportfile">
 109    <input type="hidden" name="ticket" value="%(ticket)s">
 110    <input type="hidden" name="file" value="%(file)s">
 111    <input type="hidden" name="raw" value="%(raw)s">
 112    <input type="hidden" name="content-type" value="%(content_type)s"> 
 113    <input type="submit" value="download %(file)s">
 114 </form>""" % {
 115 "baseurl": self.request.getBaseURL(),
 116 "ticket": wikiutil.createTicket(self.request),
 117 "pagename": self.pagename,
 118 "file": self.file,
 119 "content_type": "text/plain",
 120 "raw": raw,
 121 }
 122         self.request.write(form)

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] (2007-01-02 19:13:36, 13.2 KB) [[attachment:ExportFile_1.png]]
  • [get | view] (2007-01-02 19:27:33, 0.2 KB) [[attachment:example.py]]
  • [get | view] (2007-01-02 19:27:41, 0.0 KB) [[attachment:example.txt]]
  • [get | view] (2007-01-02 19:14:06, 1.4 KB) [[attachment:exportfile-1.6.0-1.py]]
  • [get | view] (2007-01-02 19:27:52, 0.0 KB) [[attachment:exportfile.txt]]
  • [get | view] (2007-01-02 19:13:52, 4.4 KB) [[attachment:text_x_exportfile-1.6.0-1.py]]
  • [get | view] (2007-01-04 04:56:37, 4.0 KB) [[attachment:text_x_exportfile-1.6.0-2.py]]
  • [get | view] (2007-01-04 05:16:14, 3.6 KB) [[attachment:text_x_exportfile-1.6.0-3.py]]
  • [get | view] (2007-01-04 04:57:15, 1.1 KB) [[attachment:wikiutil_20070103_patch.txt]]
  • [get | view] (2007-01-04 05:15:49, 1.6 KB) [[attachment:wikiutil_20070104_patch.txt]]
 All files | Selected Files: delete move to page copy to page

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