File: TeudView.py

package info (click to toggle)
moin 1.9.9-1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 76,024 kB
  • sloc: python: 143,896; java: 10,704; php: 2,385; perl: 1,574; xml: 371; makefile: 214; sh: 81; sed: 5
file content (76 lines) | stat: -rw-r--r-- 2,218 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# -*- coding: iso-8859-1 -*-
"""
    MoinMoin - Teud Macro

    This integrates the "Teud" documentation system into
    MoinMoin. Besides Teud, you need 4XSLT.

    Teud: http://purl.net/wiki/python/TeudProject
    4XSLT: http://4suite.org/

    @copyright: 2001 Juergen Hermann <jh@web.de>
    @license: GNU GPL, see COPYING for details.
"""

_imperr = None
try:
    from teud import xmldoc, pydoc
except ImportError, _imperr:
    pass
try:
    from xml.xslt.Processor import Processor
except ImportError, _imperr:
    pass

from MoinMoin import config, wikiutil

Dependencies = ["time"]

def macro_TeudView(macro):
    if _imperr: return "Error in TeudView macro: " + str(_imperr)

    #dtdfile = xmldoc.getDTDPath()
    xslfile = xmldoc.getDataPath('webde.xsl')
    pagename = macro.formatter.page.page_name

    if 'module' in macro.request.args:
        modname = macro.request.args["module"]
        try:
            obj = pydoc.locate(modname)
        except pydoc.ErrorDuringImport, value:
            return "Error while loading module %s: %s" % (modname, value)
        else:
            xmlstr = xmldoc.xml.document(obj, encoding=config.charset)

        navigation = '<a href="%s">Index</a>' % pagename
        pathlen = modname.count('.')
        if pathlen:
            navigation = navigation + ' | '
            modparts = modname.split('.')
            for pathidx in range(pathlen):
                path = '.'.join(modparts[:pathidx+1])
                navigation = navigation + '<a href="%s?module=%s">%s</a>' % (
                    pagename, path, modparts[pathidx])
                if pathidx < pathlen:
                    navigation = navigation + '.'
        navigation = navigation + '<hr size="1">'
    else:
        # generate index
        xmlstr = xmldoc.xml.document(None, encoding=config.charset)
        navigation = ''

    processor = Processor()
    processor.appendStylesheetFile(xslfile)
    try:
        result = processor.runString(xmlstr,
            topLevelParams={
                'uri-prefix': pagename + "?module=",
                'uri-suffix': "",
            }
        )
    except:
        print wikiutil.escape(xmlstr)
        raise

    return navigation + result