|
1 """management and error screens |
|
2 |
|
3 |
|
4 :organization: Logilab |
|
5 :copyright: 2001-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
|
6 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
|
7 """ |
|
8 __docformat__ = "restructuredtext en" |
|
9 |
|
10 from time import strftime, localtime |
|
11 |
|
12 from logilab.mtconverter import html_escape |
|
13 |
|
14 from cubicweb.common.view import StartupView |
|
15 |
|
16 def dict_to_html(w, dict): |
|
17 # XHTML doesn't allow emtpy <ul> nodes |
|
18 if dict: |
|
19 w(u'<ul>') |
|
20 for key in sorted(dict): |
|
21 w(u'<li><span class="label">%s</span>: <span>%s</span></li>' % ( |
|
22 html_escape(str(key)), html_escape(repr(dict[key])))) |
|
23 w(u'</ul>') |
|
24 |
|
25 class DebugView(StartupView): |
|
26 id = 'debug' |
|
27 title = _('server debug information') |
|
28 require_groups = ('managers',) |
|
29 |
|
30 def call(self, **kwargs): |
|
31 """display server information""" |
|
32 w = self.w |
|
33 w(u'<h1>server sessions</h1>') |
|
34 sessions = self.req.cnx._repo._sessions.items() |
|
35 if sessions: |
|
36 w(u'<ul>') |
|
37 for sid, session in sessions: |
|
38 w(u'<li>%s (last usage: %s)<br/>' % (html_escape(str(session)), |
|
39 strftime('%Y-%m-%d %H:%M:%S', |
|
40 localtime(session.timestamp)))) |
|
41 dict_to_html(w, session.data) |
|
42 w(u'</li>') |
|
43 w(u'</ul>') |
|
44 else: |
|
45 w(u'<p>no server sessions found</p>') |
|
46 from cubicweb.web.application import SESSION_MANAGER |
|
47 w(u'<h1>web sessions</h1>') |
|
48 sessions = SESSION_MANAGER.current_sessions() |
|
49 if sessions: |
|
50 w(u'<ul>') |
|
51 for session in sessions: |
|
52 w(u'<li>%s (last usage: %s)<br/>' % (session.sessionid, |
|
53 strftime('%Y-%m-%d %H:%M:%S', |
|
54 localtime(session.last_usage_time)))) |
|
55 dict_to_html(w, session.data) |
|
56 w(u'</li>') |
|
57 w(u'</ul>') |
|
58 else: |
|
59 w(u'<p>no web sessions found</p>') |