Attachment 'HelpOn-1.7.1-10.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.emit_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 thispage = Page(request, pagename)
100 if not request.user.valid:
101 msg="Please log in"
102 request.theme.add_msg(msg)
103 thispage.send_page()
104 return
105
106 _ = request.getText
107 actname = __name__.split('.')[-1]
108
109 if request.form.has_key('button') and request.form.has_key('ticket'):
110 if not wikiutil.checkTicket(request, request.form['ticket'][0]):
111 msg = _('Please use the interactive user interface for HelpOn extensions!')
112 request.theme.add_msg(msg)
113 thispage.send_page()
114 return
115 module = request.form.get('helpon', [u''])[0]
116 return (HelpOn(request, pagename, module))
117
118 html = []
119
120 for name in action.getNames(request.cfg):
121 html.append("<OPTION>MM-action:%(name)s</OPTION>" % {"name": name})
122
123 for name in wikiutil.wikiPlugins('action', request.cfg):
124 html.append("<OPTION>W-action:%(name)s</OPTION>" % {"name": name})
125
126 for name in macro.getNames(request.cfg):
127 html.append("<OPTION>MM-macro:%(name)s</OPTION>" % {"name": name})
128
129 for name in wikiutil.wikiPlugins('macro', request.cfg):
130 html.append("<OPTION>W-macro:%(name)s</OPTION>" % {"name": name})
131
132 for name in parser.modules:
133 html.append("<OPTION>MM-parser:%(name)s</OPTION>" % {"name": name})
134
135 for name in wikiutil.wikiPlugins('parser', request.cfg):
136 html.append("<OPTION>W-parser:%(name)s</OPTION>" % {"name": name})
137
138 formhtml = '''
139 <form method="post" action="">
140 <select name="helpon" size="1">
141 %(option)s
142 </select>
143 <input type="hidden" name="action" value="%(actname)s">
144 <input type="submit" name="button" value="%(button)s">
145 <input type="hidden" name="ticket" value="%(ticket)s">
146 <p>
147 </form>''' % {
148 'actname': 'HelpOn',
149 'ticket': wikiutil.createTicket(request),
150 'option': '\n'.join(html),
151 'button': 'Help'}
152
153 request.theme.add_msg(formhtml)
154 thispage.send_page()
155 return
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.