annotate MoinMoin/action/thread_monitor.py @ 5522:879674c9320a

AttachFile: add ticketing for all operations that do modifications Tickets for upload (POST), also for every (GET) URL except do=get and do=view. Avoid KeyError if there is no ticket (was a minor issues, because there has to be one). Use the same i18n string for all "Please use the interactive user interface" messages.
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 08 Feb 2010 18:56:07 +0100
parents ee0644a26e30
children 85884c67228d
rev   line source
674
b4a6bad53f91 Added thread monitor.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
b4a6bad53f91 Added thread monitor.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
2 """
b4a6bad53f91 Added thread monitor.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
3 MoinMoin - Thread monitor action
b4a6bad53f91 Added thread monitor.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
4
b4a6bad53f91 Added thread monitor.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
5 Shows the current traceback of all threads.
b4a6bad53f91 Added thread monitor.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
6
1918
bb2e053067fb fixing copyright headers: remove umlauts (encoding troubles), make epydoc compatible, reformat
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1528
diff changeset
7 @copyright: 2006 MoinMoin:AlexanderSchremmer
674
b4a6bad53f91 Added thread monitor.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
8 @license: GNU GPL, see COPYING for details.
b4a6bad53f91 Added thread monitor.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
9 """
837
7abe5a3e5e8c thread_monitor can write dumps to data_dir, updated CHANGES (already done in 1.5 branch)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 835
diff changeset
10 import os, time
835
d4dd4fca1477 moved action/tm to action/thread_monitor, minor cleanup, added CHANGES entry about thread_monitor action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 674
diff changeset
11 from StringIO import StringIO
949
cbbde07e00c4 whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 837
diff changeset
12
3520
fa0ee02c9c39 action.thread_monitor: added restrictions for superuser and actions_excluded
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1918
diff changeset
13 from MoinMoin import Page, wikiutil
837
7abe5a3e5e8c thread_monitor can write dumps to data_dir, updated CHANGES (already done in 1.5 branch)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 835
diff changeset
14 from MoinMoin.util import thread_monitor
949
cbbde07e00c4 whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 837
diff changeset
15
837
7abe5a3e5e8c thread_monitor can write dumps to data_dir, updated CHANGES (already done in 1.5 branch)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 835
diff changeset
16 def execute_fs(pagename, request):
3520
fa0ee02c9c39 action.thread_monitor: added restrictions for superuser and actions_excluded
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1918
diff changeset
17 _ = request.getText
3525
ee0644a26e30 action Attachfile, Despam, backup, thread_monitor: removed duplicated checks done by request.__init__
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3520
diff changeset
18 # check for superuser
ee0644a26e30 action Attachfile, Despam, backup, thread_monitor: removed duplicated checks done by request.__init__
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3520
diff changeset
19 if not request.user.isSuperUser():
3520
fa0ee02c9c39 action.thread_monitor: added restrictions for superuser and actions_excluded
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1918
diff changeset
20 request.theme.add_msg(_('You are not allowed to use this action.'), "error")
fa0ee02c9c39 action.thread_monitor: added restrictions for superuser and actions_excluded
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1918
diff changeset
21 return Page.Page(request, pagename).send_page()
fa0ee02c9c39 action.thread_monitor: added restrictions for superuser and actions_excluded
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1918
diff changeset
22
1528
ec52fba7f971 Added support for Python 2.5 in the thread monitor.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1068
diff changeset
23 if thread_monitor.hook_enabled():
837
7abe5a3e5e8c thread_monitor can write dumps to data_dir, updated CHANGES (already done in 1.5 branch)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 835
diff changeset
24 s = StringIO()
7abe5a3e5e8c thread_monitor can write dumps to data_dir, updated CHANGES (already done in 1.5 branch)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 835
diff changeset
25 thread_monitor.trigger_dump(s)
7abe5a3e5e8c thread_monitor can write dumps to data_dir, updated CHANGES (already done in 1.5 branch)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 835
diff changeset
26 time.sleep(5) # allow for all threads to dump to request
7abe5a3e5e8c thread_monitor can write dumps to data_dir, updated CHANGES (already done in 1.5 branch)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 835
diff changeset
27 data = s.getvalue()
7abe5a3e5e8c thread_monitor can write dumps to data_dir, updated CHANGES (already done in 1.5 branch)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 835
diff changeset
28 timestamp = time.time()
7abe5a3e5e8c thread_monitor can write dumps to data_dir, updated CHANGES (already done in 1.5 branch)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 835
diff changeset
29 dump_fname = os.path.join(request.cfg.data_dir, "tm_%d.log" % timestamp)
7abe5a3e5e8c thread_monitor can write dumps to data_dir, updated CHANGES (already done in 1.5 branch)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 835
diff changeset
30 f = file(dump_fname, "w")
7abe5a3e5e8c thread_monitor can write dumps to data_dir, updated CHANGES (already done in 1.5 branch)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 835
diff changeset
31 f.write(data)
7abe5a3e5e8c thread_monitor can write dumps to data_dir, updated CHANGES (already done in 1.5 branch)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 835
diff changeset
32 f.close()
7abe5a3e5e8c thread_monitor can write dumps to data_dir, updated CHANGES (already done in 1.5 branch)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 835
diff changeset
33 else:
7abe5a3e5e8c thread_monitor can write dumps to data_dir, updated CHANGES (already done in 1.5 branch)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 835
diff changeset
34 dump_fname = "nowhere"
835
d4dd4fca1477 moved action/tm to action/thread_monitor, minor cleanup, added CHANGES entry about thread_monitor action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 674
diff changeset
35
1068
ecece5db5288 use emit_http_headers
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 949
diff changeset
36 request.emit_http_headers()
837
7abe5a3e5e8c thread_monitor can write dumps to data_dir, updated CHANGES (already done in 1.5 branch)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 835
diff changeset
37 request.write('<html><body>A dump has been saved to %s.</body></html>' % dump_fname)
674
b4a6bad53f91 Added thread monitor.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
38
837
7abe5a3e5e8c thread_monitor can write dumps to data_dir, updated CHANGES (already done in 1.5 branch)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 835
diff changeset
39 def execute_wiki(pagename, request):
3520
fa0ee02c9c39 action.thread_monitor: added restrictions for superuser and actions_excluded
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1918
diff changeset
40 _ = request.getText
fa0ee02c9c39 action.thread_monitor: added restrictions for superuser and actions_excluded
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1918
diff changeset
41 # be extra paranoid in dangerous actions
fa0ee02c9c39 action.thread_monitor: added restrictions for superuser and actions_excluded
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1918
diff changeset
42 actname = __name__.split('.')[-1]
3525
ee0644a26e30 action Attachfile, Despam, backup, thread_monitor: removed duplicated checks done by request.__init__
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3520
diff changeset
43 if not request.user.isSuperUser():
3520
fa0ee02c9c39 action.thread_monitor: added restrictions for superuser and actions_excluded
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1918
diff changeset
44 request.theme.add_msg(_('You are not allowed to use this action.'), "error")
fa0ee02c9c39 action.thread_monitor: added restrictions for superuser and actions_excluded
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1918
diff changeset
45 return Page.Page(request, pagename).send_page()
fa0ee02c9c39 action.thread_monitor: added restrictions for superuser and actions_excluded
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1918
diff changeset
46
1068
ecece5db5288 use emit_http_headers
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 949
diff changeset
47 request.emit_http_headers()
674
b4a6bad53f91 Added thread monitor.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
48
b4a6bad53f91 Added thread monitor.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
49 request.theme.send_title("Thread monitor")
b4a6bad53f91 Added thread monitor.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
50 request.write('<pre>')
b4a6bad53f91 Added thread monitor.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
51
1528
ec52fba7f971 Added support for Python 2.5 in the thread monitor.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1068
diff changeset
52 if not thread_monitor.hook_enabled():
674
b4a6bad53f91 Added thread monitor.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
53 request.write("Hook is not enabled.")
b4a6bad53f91 Added thread monitor.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
54 else:
b4a6bad53f91 Added thread monitor.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
55 s = StringIO()
b4a6bad53f91 Added thread monitor.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
56 thread_monitor.trigger_dump(s)
837
7abe5a3e5e8c thread_monitor can write dumps to data_dir, updated CHANGES (already done in 1.5 branch)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 835
diff changeset
57 time.sleep(5) # allow for all threads to dump to request
7abe5a3e5e8c thread_monitor can write dumps to data_dir, updated CHANGES (already done in 1.5 branch)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 835
diff changeset
58 request.write(wikiutil.escape(s.getvalue()))
949
cbbde07e00c4 whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 837
diff changeset
59
674
b4a6bad53f91 Added thread monitor.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
60 request.write('</pre>')
b4a6bad53f91 Added thread monitor.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
61 request.theme.send_footer(pagename)
b4a6bad53f91 Added thread monitor.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
62 request.theme.send_closing_html()
949
cbbde07e00c4 whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 837
diff changeset
63
837
7abe5a3e5e8c thread_monitor can write dumps to data_dir, updated CHANGES (already done in 1.5 branch)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 835
diff changeset
64 execute = execute_fs
835
d4dd4fca1477 moved action/tm to action/thread_monitor, minor cleanup, added CHANGES entry about thread_monitor action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 674
diff changeset
65