Attachment 'HelpOn-1.6.0-9.py'
Download 1 # -*- coding: iso-8859-1 -*-
2 """
3 MoinMoin - HelpOn Action Macro
4
5 PURPOSE:
6 This action macro is used to get help on an other extensions
7
8 SYNTAX:
9 http://WikiServer/WikiName?action=HelpOn
10
11 PROCEDURE:
12 You get a pull down list of available extensions and after selection
13 the help from inside of the routine is shown
14
15 The extensions below the MoinMoin path are indicated by the prefix MM-
16 While the others are indicated by a W- in the list
17
18 Please remove the version number from the filename.
19
20 MODIFICATION HISTORY:
21 @copyright: 2005 by MoinMoin:ReimarBauer
22 @license: GNU GPL, see COPYING for details.
23 Version: 1.3.5-1
24
25 1.3.5-2 bug fix if no routine desription is defined
26 minor change from table output to preformatted text
27
28 1.3.5-3 code refactored
29 1.3.5-4 PRE does not need an additional line break
30
31 1.5.1-5 removed request.cfg.excluded_actions
32 1.5.4-6 2006-07-04 RB: some PEP8 changes
33 1.6.0-9 2008-01-10 refactored for 1.6 getting the header is not quite optimal currently
34 """
35
36 import codecs, os
37 from MoinMoin import config, wikiutil, user, macro, action, parser
38 from MoinMoin.Page import Page
39 from MoinMoin.formatter.text_html import Formatter
40
41 def HelpOn_Extract_Help(module_path_name, module_name):
42 # if the module is not a file it is defined in __init__
43 if not os.path.exists(module_path_name):
44 module_path_name = module_path_name.replace(module_name.split(':')[1], '__init__')
45
46 file = codecs.open(module_path_name, 'r')
47 lines = file.readlines()
48 file.close()
49
50 index = []
51 i = 0
52 for line in lines:
53 if line.strip() == '"""':
54 index.append(i)
55 i += 1
56
57 if len(index) >= 2:
58 txt = lines[(index[0])+1: index[1]]
59 else:
60 txt = ["no help available for %(name)s" % {"name": module_name}]
61
62 return txt
63
64 def HelpOn(request, pagename, module):
65 request.formatter = Formatter(request)
66 mod = module.split(':')
67 module_type = mod[0]
68 this_type = module_type.split('-')
69 module_type = this_type[1]
70 module_name = mod[1]
71
72 if this_type[0] == 'MM':
73 module_path_name = "%(path)s/%(module_type)s/%(name)s.py" % {
74 "module_type": module_type,
75 "path": request.cfg.moinmoin_dir,
76 "name": module_name }
77
78 if this_type[0] == 'W':
79 module_path_name = "%(path)s/plugin/%(module_type)s/%(name)s.py" % {
80 "module_type": module_type,
81 "path": request.cfg.data_dir,
82 "name": module_name}
83
84 info = HelpOn_Extract_Help(module_path_name, module)
85 html = "<PRE>%(txt)s</PRE>" % {
86 "txt": '\n'.join(info)}
87
88 request.http_headers()
89 request.setContentLanguage(request.lang)
90 request.theme.send_title('Helpon %s' % module_name, pagename=pagename)
91 request.write(request.formatter.startContent("content"))
92 request.write(html)
93 request.write(request.formatter.endContent())
94 request.theme.send_footer(pagename)
95 return
96
97
98 def execute(pagename, request):
99 _ = request.getText
100 actname = __name__.split('.')[-1]
101 thispage = Page(request, pagename)
102
103 if request.form.has_key('button') and request.form.has_key('ticket'):
104 if not wikiutil.checkTicket(request, request.form['ticket'][0]):
105 return thispage.send_page(request, msg=_('Please use the interactive user interface for HelpOn extensions!'))
106 module = request.form.get('helpon', [u''])[0]
107 return (HelpOn(request, pagename, module))
108
109 html = []
110
111 for name in action.getNames(request.cfg):
112 html.append("<OPTION>MM-action:%(name)s</OPTION>" % {"name": name})
113
114 for name in wikiutil.wikiPlugins('action', request.cfg):
115 html.append("<OPTION>W-action:%(name)s</OPTION>" % {"name": name})
116
117 for name in macro.getNames(request.cfg):
118 html.append("<OPTION>MM-macro:%(name)s</OPTION>" % {"name": name})
119
120 for name in wikiutil.wikiPlugins('macro', request.cfg):
121 html.append("<OPTION>W-macro:%(name)s</OPTION>" % {"name": name})
122
123 for name in parser.modules:
124 html.append("<OPTION>MM-parser:%(name)s</OPTION>" % {"name": name})
125
126 for name in wikiutil.wikiPlugins('parser', request.cfg):
127 html.append("<OPTION>W-parser:%(name)s</OPTION>" % {"name": name})
128
129 formhtml = '''
130 <form method="post" action="">
131 <select name="helpon" size="1">
132 %(option)s
133 </select>
134 <input type="hidden" name="action" value="%(actname)s">
135 <input type="submit" name="button" value="%(button)s">
136 <input type="hidden" name="ticket" value="%(ticket)s">
137 <p>
138 </form>''' % {
139 'actname': 'HelpOn',
140 'ticket': wikiutil.createTicket(request),
141 'option': '\n'.join(html),
142 'button': 'Help'}
143
144 return thispage.send_page(msg=formhtml)
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.