author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Mon, 15 Feb 2010 18:44:47 +0100 | |
changeset 4587 | 70d47389630c |
parent 4252 | 6c4f109c2b03 |
child 4714 | fccda6dd91bf |
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): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
29 |
__regid__ = '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>') |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
37 |
sessions = self._cw.cnx._repo._sessions.items() |
0 | 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>') |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
63 |
|
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
64 |
|
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
65 |
class RegistryView(StartupView): |
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
66 |
__regid__ = 'registry' |
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
67 |
__select__ = StartupView.__select__ & match_user_groups('managers') |
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
68 |
title = _('registry') |
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
69 |
|
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
70 |
def call(self, **kwargs): |
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
71 |
"""The default view representing the instance's management""" |
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
72 |
self.w(u'<h1>%s</h1>' % _("Registry's content")) |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
73 |
keys = sorted(self._cw.vreg) |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
74 |
self.w(u'<p>%s</p>\n' % ' - '.join('<a href="/_registry#%s">%s</a>' |
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
75 |
% (key, key) for key in keys)) |
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
76 |
for key in keys: |
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
77 |
self.w(u'<h2><a name="%s">%s</a></h2>' % (key,key)) |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
78 |
items = self._cw.vreg[key].items() |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
79 |
if items: |
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
80 |
self.w(u'<table><tbody>') |
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
81 |
for key, value in sorted(items): |
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
82 |
self.w(u'<tr><td>%s</td><td>%s</td></tr>' |
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
83 |
% (key, xml_escape(repr(value)))) |
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
84 |
self.w(u'</tbody></table>\n') |
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
85 |
else: |
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
86 |
self.w(u'<p>Empty</p>\n') |