author | Adrien Di Mascio <Adrien.DiMascio@logilab.fr> |
Thu, 07 Jan 2010 16:52:32 +0100 | |
branch | stable |
changeset 4212 | ab6573088b4a |
parent 2312 | af4d8f75c5db |
child 4252 | 6c4f109c2b03 |
permissions | -rw-r--r-- |
0 | 1 |
"""management and error screens |
2 |
||
3 |
||
4 |
:organization: Logilab |
|
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2312
diff
changeset
|
5 |
:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
0 | 6 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
7 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 8 |
""" |
9 |
__docformat__ = "restructuredtext en" |
|
10 |
||
11 |
from time import strftime, localtime |
|
12 |
||
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
13 |
from logilab.mtconverter import xml_escape |
0 | 14 |
|
635
305da8d6aa2d
require_group/match_user_group -> match_user_groups
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
15 |
from cubicweb.selectors import none_rset, match_user_groups |
981
d86d1ee3b60e
fix some imports, update treeview for 3.2
sylvain.thenault@logilab.fr
parents:
742
diff
changeset
|
16 |
from cubicweb.view import StartupView |
0 | 17 |
|
18 |
def dict_to_html(w, dict): |
|
19 |
# XHTML doesn't allow emtpy <ul> nodes |
|
20 |
if dict: |
|
21 |
w(u'<ul>') |
|
22 |
for key in sorted(dict): |
|
23 |
w(u'<li><span class="label">%s</span>: <span>%s</span></li>' % ( |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
24 |
xml_escape(str(key)), xml_escape(repr(dict[key])))) |
0 | 25 |
w(u'</ul>') |
635
305da8d6aa2d
require_group/match_user_group -> match_user_groups
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
26 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
981
diff
changeset
|
27 |
|
0 | 28 |
class DebugView(StartupView): |
29 |
id = 'debug' |
|
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
635
diff
changeset
|
30 |
__select__ = none_rset() & match_user_groups('managers') |
0 | 31 |
title = _('server debug information') |
32 |
||
33 |
def call(self, **kwargs): |
|
34 |
"""display server information""" |
|
35 |
w = self.w |
|
36 |
w(u'<h1>server sessions</h1>') |
|
37 |
sessions = self.req.cnx._repo._sessions.items() |
|
38 |
if sessions: |
|
39 |
w(u'<ul>') |
|
40 |
for sid, session in sessions: |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
41 |
w(u'<li>%s (last usage: %s)<br/>' % (xml_escape(str(session)), |
0 | 42 |
strftime('%Y-%m-%d %H:%M:%S', |
43 |
localtime(session.timestamp)))) |
|
44 |
dict_to_html(w, session.data) |
|
45 |
w(u'</li>') |
|
46 |
w(u'</ul>') |
|
47 |
else: |
|
48 |
w(u'<p>no server sessions found</p>') |
|
49 |
from cubicweb.web.application import SESSION_MANAGER |
|
50 |
w(u'<h1>web sessions</h1>') |
|
51 |
sessions = SESSION_MANAGER.current_sessions() |
|
52 |
if sessions: |
|
53 |
w(u'<ul>') |
|
54 |
for session in sessions: |
|
55 |
w(u'<li>%s (last usage: %s)<br/>' % (session.sessionid, |
|
56 |
strftime('%Y-%m-%d %H:%M:%S', |
|
57 |
localtime(session.last_usage_time)))) |
|
58 |
dict_to_html(w, session.data) |
|
59 |
w(u'</li>') |
|
60 |
w(u'</ul>') |
|
61 |
else: |
|
62 |
w(u'<p>no web sessions found</p>') |