web/views/debug.py
author Rémi Cardona <remi.cardona@logilab.fr>
Wed, 25 Nov 2015 17:31:32 +0100
changeset 10924 2125def9498b
parent 10923 846e5676ca39
child 11127 6464edfa95bb
permissions -rw-r--r--
[views] Use 'pyvaltable' instead of hand-crafted <table> tags
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7428
5338d895b891 [web session] fix session handling so we get a chance to have for instance the 'forgotpwd' feature working on a site where anonymous are not allowed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6961
diff changeset
     1
# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5248
diff changeset
     2
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5248
diff changeset
     3
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5248
diff changeset
     4
# This file is part of CubicWeb.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5248
diff changeset
     5
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5248
diff changeset
     6
# CubicWeb is free software: you can redistribute it and/or modify it under the
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5248
diff changeset
     7
# terms of the GNU Lesser General Public License as published by the Free
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5248
diff changeset
     8
# Software Foundation, either version 2.1 of the License, or (at your option)
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5248
diff changeset
     9
# any later version.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5248
diff changeset
    10
#
5424
8ecbcbff9777 replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5421
diff changeset
    11
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5248
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5248
diff changeset
    13
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5248
diff changeset
    14
# details.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5248
diff changeset
    15
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5248
diff changeset
    16
# You should have received a copy of the GNU Lesser General Public License along
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5248
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
5824
de9b7e88660e cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    18
"""management and error screens"""
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    19
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    20
__docformat__ = "restructuredtext en"
10666
7f6b5f023884 [py3k] replace '_ = unicode' in global scope (closes #7589459)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10662
diff changeset
    21
from cubicweb import _
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    22
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    23
from time import strftime, localtime
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    24
10717
46f934bebd85 [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10666
diff changeset
    25
from six import text_type
46f934bebd85 [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10666
diff changeset
    26
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    27
from logilab.mtconverter import xml_escape
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    28
8190
2a3c1b787688 [vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7810
diff changeset
    29
from cubicweb.predicates import none_rset, match_user_groups
981
d86d1ee3b60e fix some imports, update treeview for 3.2
sylvain.thenault@logilab.fr
parents: 742
diff changeset
    30
from cubicweb.view import StartupView
6961
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6582
diff changeset
    31
from cubicweb.web.views import actions, tabs
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    32
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    33
def dict_to_html(w, dict):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    34
    # XHTML doesn't allow emtpy <ul> nodes
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    35
    if dict:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    36
        w(u'<ul>')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    37
        for key in sorted(dict):
10924
2125def9498b [views] Use 'pyvaltable' instead of hand-crafted <table> tags
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10923
diff changeset
    38
            w(u'<li><span>%s</span>: <span>%s</span></li>' % (
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    39
                xml_escape(str(key)), xml_escape(repr(dict[key]))))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    40
        w(u'</ul>')
635
305da8d6aa2d require_group/match_user_group -> match_user_groups
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    41
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 981
diff changeset
    42
5963
4d75f743ed49 [actions] homogen action/view selectors. Move action together with associated view to avoid such thing in the future
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5825
diff changeset
    43
class SiteInfoAction(actions.ManagersAction):
4d75f743ed49 [actions] homogen action/view selectors. Move action together with associated view to avoid such thing in the future
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5825
diff changeset
    44
    __regid__ = 'siteinfo'
4d75f743ed49 [actions] homogen action/view selectors. Move action together with associated view to avoid such thing in the future
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5825
diff changeset
    45
    __select__ = match_user_groups('users','managers')
7810
21683b1975e3 [i18n] tweaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7428
diff changeset
    46
    title = _('Site information')
6961
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6582
diff changeset
    47
    category = 'manage'
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6582
diff changeset
    48
    order = 1000
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6582
diff changeset
    49
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6582
diff changeset
    50
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6582
diff changeset
    51
class SiteInfoView(tabs.TabsMixin, StartupView):
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6582
diff changeset
    52
    __regid__ = 'siteinfo'
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6582
diff changeset
    53
    title = _('Site information')
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6582
diff changeset
    54
    tabs = [_('info'), _('registry'), _('gc')]
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6582
diff changeset
    55
    default_tab = 'info'
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6582
diff changeset
    56
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6582
diff changeset
    57
    def call(self, **kwargs):
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6582
diff changeset
    58
        """The default view representing the instance's management"""
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6582
diff changeset
    59
        self.w(u'<h1>%s</h1>' % self._cw._(self.title))
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6582
diff changeset
    60
        self.render_tabs(self.tabs, self.default_tab)
5963
4d75f743ed49 [actions] homogen action/view selectors. Move action together with associated view to avoid such thing in the future
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5825
diff changeset
    61
4d75f743ed49 [actions] homogen action/view selectors. Move action together with associated view to avoid such thing in the future
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5825
diff changeset
    62
4714
fccda6dd91bf merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    63
class ProcessInformationView(StartupView):
4865
90ad729d3540 [debug] minor improvments to the registry view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4725
diff changeset
    64
    """display various web server /repository information"""
4714
fccda6dd91bf merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    65
    __regid__ = 'info'
5963
4d75f743ed49 [actions] homogen action/view selectors. Move action together with associated view to avoid such thing in the future
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5825
diff changeset
    66
    __select__ = none_rset() & match_user_groups('managers', 'users')
4714
fccda6dd91bf merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    67
fccda6dd91bf merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    68
    title = _('server information')
5825
2daf1ac79d5c [debug views] set http cache max age to 0 on debug views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5824
diff changeset
    69
    cache_max_age = 0
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    70
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    71
    def call(self, **kwargs):
4714
fccda6dd91bf merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    72
        req = self._cw
fccda6dd91bf merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    73
        dtformat = req.property_value('ui.datetime-format')
fccda6dd91bf merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    74
        _ = req._
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    75
        w = self.w
10923
846e5676ca39 [web] Stop using config.repository()
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10922
diff changeset
    76
        repo = req.cnx.repo
4714
fccda6dd91bf merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    77
        # generic instance information
6961
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6582
diff changeset
    78
        w(u'<h2>%s</h2>' % _('Instance'))
10924
2125def9498b [views] Use 'pyvaltable' instead of hand-crafted <table> tags
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10923
diff changeset
    79
        pyvalue = ((_('config type'), self._cw.vreg.config.name),
2125def9498b [views] Use 'pyvaltable' instead of hand-crafted <table> tags
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10923
diff changeset
    80
                   (_('config mode'), self._cw.vreg.config.mode),
2125def9498b [views] Use 'pyvaltable' instead of hand-crafted <table> tags
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10923
diff changeset
    81
                   (_('instance home'), self._cw.vreg.config.apphome))
2125def9498b [views] Use 'pyvaltable' instead of hand-crafted <table> tags
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10923
diff changeset
    82
        self.wview('pyvaltable', pyvalue=pyvalue, header_column_idx=0)
10923
846e5676ca39 [web] Stop using config.repository()
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10922
diff changeset
    83
        vcconf = repo.get_versions()
4714
fccda6dd91bf merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    84
        w(u'<h3>%s</h3>' % _('versions configuration'))
10924
2125def9498b [views] Use 'pyvaltable' instead of hand-crafted <table> tags
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10923
diff changeset
    85
        missing = _('no version information')
2125def9498b [views] Use 'pyvaltable' instead of hand-crafted <table> tags
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10923
diff changeset
    86
        pyvalue = [('CubicWeb', vcconf.get('cubicweb', missing))]
2125def9498b [views] Use 'pyvaltable' instead of hand-crafted <table> tags
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10923
diff changeset
    87
        pyvalue += [(cube, vcconf.get(cube, missing))
2125def9498b [views] Use 'pyvaltable' instead of hand-crafted <table> tags
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10923
diff changeset
    88
                    for cube in sorted(self._cw.vreg.config.cubes())]
2125def9498b [views] Use 'pyvaltable' instead of hand-crafted <table> tags
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10923
diff changeset
    89
        self.wview('pyvaltable', pyvalue=pyvalue, header_column_idx=0)
4714
fccda6dd91bf merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    90
        # repository information
6961
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6582
diff changeset
    91
        w(u'<h2>%s</h2>' % _('Repository'))
4714
fccda6dd91bf merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    92
        w(u'<h3>%s</h3>' % _('resources usage'))
9034
cc3442054e48 [repo] move repo stats to Service (closes #2951067)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8718
diff changeset
    93
        stats = self._cw.call_service('repo_stats')
10309
35bf741203d6 [services] Prevent 'repo_stats' service from aggregating information
David Douard <david.douard@logilab.fr>
parents: 9671
diff changeset
    94
        stats['looping_tasks'] = ', '.join('%s (%s seconds)' % (n, i) for n, i in stats['looping_tasks'])
35bf741203d6 [services] Prevent 'repo_stats' service from aggregating information
David Douard <david.douard@logilab.fr>
parents: 9671
diff changeset
    95
        stats['threads'] = ', '.join(sorted(stats['threads']))
35bf741203d6 [services] Prevent 'repo_stats' service from aggregating information
David Douard <david.douard@logilab.fr>
parents: 9671
diff changeset
    96
        for k in stats:
35bf741203d6 [services] Prevent 'repo_stats' service from aggregating information
David Douard <david.douard@logilab.fr>
parents: 9671
diff changeset
    97
            if k in ('extid_cache_size', 'type_source_cache_size'):
35bf741203d6 [services] Prevent 'repo_stats' service from aggregating information
David Douard <david.douard@logilab.fr>
parents: 9671
diff changeset
    98
                continue
35bf741203d6 [services] Prevent 'repo_stats' service from aggregating information
David Douard <david.douard@logilab.fr>
parents: 9671
diff changeset
    99
            if k.endswith('_cache_size'):
35bf741203d6 [services] Prevent 'repo_stats' service from aggregating information
David Douard <david.douard@logilab.fr>
parents: 9671
diff changeset
   100
                stats[k] = '%s / %s' % (stats[k]['size'], stats[k]['maxsize'])
10924
2125def9498b [views] Use 'pyvaltable' instead of hand-crafted <table> tags
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10923
diff changeset
   101
        def format_stat(sname, sval):
2125def9498b [views] Use 'pyvaltable' instead of hand-crafted <table> tags
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10923
diff changeset
   102
            return '%s %s' % (xml_escape(text_type(sval)),
2125def9498b [views] Use 'pyvaltable' instead of hand-crafted <table> tags
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10923
diff changeset
   103
                              sname.endswith('percent') and '%' or '')
2125def9498b [views] Use 'pyvaltable' instead of hand-crafted <table> tags
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10923
diff changeset
   104
        pyvalue = [(sname, format_stat(sname, sval))
2125def9498b [views] Use 'pyvaltable' instead of hand-crafted <table> tags
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10923
diff changeset
   105
                    for sname, sval in sorted(stats.items())]
2125def9498b [views] Use 'pyvaltable' instead of hand-crafted <table> tags
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10923
diff changeset
   106
        self.wview('pyvaltable', pyvalue=pyvalue, header_column_idx=0)
2125def9498b [views] Use 'pyvaltable' instead of hand-crafted <table> tags
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10923
diff changeset
   107
        # open repo sessions
8669
62213a34726e [db-api/configuration] simplify db-api and configuration so that all the connection information is in the repository url, closes #2521848
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8190
diff changeset
   108
        if req.cnx.is_repo_in_memory and req.user.is_in_group('managers'):
4714
fccda6dd91bf merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   109
            w(u'<h3>%s</h3>' % _('opened sessions'))
9670
5b661f58978c [web/debug] Fix check for open sessions
Julien Cristau <julien.cristau@logilab.fr>
parents: 9034
diff changeset
   110
            sessions = repo._sessions.values()
4714
fccda6dd91bf merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   111
            if sessions:
fccda6dd91bf merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   112
                w(u'<ul>')
fccda6dd91bf merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   113
                for session in sessions:
fccda6dd91bf merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   114
                    w(u'<li>%s (%s: %s)<br/>' % (
10717
46f934bebd85 [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10666
diff changeset
   115
                        xml_escape(text_type(session)),
4714
fccda6dd91bf merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   116
                        _('last usage'),
fccda6dd91bf merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   117
                        strftime(dtformat, localtime(session.timestamp))))
fccda6dd91bf merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   118
                    dict_to_html(w, session.data)
fccda6dd91bf merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   119
                    w(u'</li>')
fccda6dd91bf merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   120
                w(u'</ul>')
fccda6dd91bf merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   121
            else:
fccda6dd91bf merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   122
                w(u'<p>%s</p>' % _('no repository sessions found'))
fccda6dd91bf merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   123
        # web server information
6961
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6582
diff changeset
   124
        w(u'<h2>%s</h2>' % _('Web server'))
10924
2125def9498b [views] Use 'pyvaltable' instead of hand-crafted <table> tags
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10923
diff changeset
   125
        pyvalue = ((_('base url'), req.base_url()),
2125def9498b [views] Use 'pyvaltable' instead of hand-crafted <table> tags
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10923
diff changeset
   126
                   (_('data directory url'), req.datadir_url))
2125def9498b [views] Use 'pyvaltable' instead of hand-crafted <table> tags
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10923
diff changeset
   127
        self.wview('pyvaltable', pyvalue=pyvalue, header_column_idx=0)
10574
6a07c2dc3d85 [views] fix ProcessInformationView: SESSION_MANAGER can be None (closes #5753280)
David Douard <david.douard@logilab.fr>
parents: 10330
diff changeset
   128
        from cubicweb.web.application import SESSION_MANAGER
6a07c2dc3d85 [views] fix ProcessInformationView: SESSION_MANAGER can be None (closes #5753280)
David Douard <david.douard@logilab.fr>
parents: 10330
diff changeset
   129
        if SESSION_MANAGER is not None and req.user.is_in_group('managers'):
6016
0eabedcfb0a9 [security] do not show sessions information to non managers users. Close security ticket #38246
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5963
diff changeset
   130
            sessions = SESSION_MANAGER.current_sessions()
0eabedcfb0a9 [security] do not show sessions information to non managers users. Close security ticket #38246
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5963
diff changeset
   131
            w(u'<h3>%s</h3>' % _('opened web sessions'))
0eabedcfb0a9 [security] do not show sessions information to non managers users. Close security ticket #38246
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5963
diff changeset
   132
            if sessions:
0eabedcfb0a9 [security] do not show sessions information to non managers users. Close security ticket #38246
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5963
diff changeset
   133
                w(u'<ul>')
0eabedcfb0a9 [security] do not show sessions information to non managers users. Close security ticket #38246
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5963
diff changeset
   134
                for session in sessions:
9671
a16fcf064323 [web/debug] remove code broken by session refactoring
Julien Cristau <julien.cristau@logilab.fr>
parents: 9670
diff changeset
   135
                    last_usage_time = session.mtime
6016
0eabedcfb0a9 [security] do not show sessions information to non managers users. Close security ticket #38246
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5963
diff changeset
   136
                    w(u'<li>%s (%s: %s)<br/>' % (
0eabedcfb0a9 [security] do not show sessions information to non managers users. Close security ticket #38246
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5963
diff changeset
   137
                        session.sessionid,
0eabedcfb0a9 [security] do not show sessions information to non managers users. Close security ticket #38246
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5963
diff changeset
   138
                        _('last usage'),
6020
6f3b4f20ee9f backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6012 6016
diff changeset
   139
                        strftime(dtformat, localtime(last_usage_time))))
6016
0eabedcfb0a9 [security] do not show sessions information to non managers users. Close security ticket #38246
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5963
diff changeset
   140
                    dict_to_html(w, session.data)
0eabedcfb0a9 [security] do not show sessions information to non managers users. Close security ticket #38246
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5963
diff changeset
   141
                    w(u'</li>')
0eabedcfb0a9 [security] do not show sessions information to non managers users. Close security ticket #38246
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5963
diff changeset
   142
                w(u'</ul>')
0eabedcfb0a9 [security] do not show sessions information to non managers users. Close security ticket #38246
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5963
diff changeset
   143
            else:
0eabedcfb0a9 [security] do not show sessions information to non managers users. Close security ticket #38246
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5963
diff changeset
   144
                w(u'<p>%s</p>' % _('no web sessions found'))
4714
fccda6dd91bf merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   145
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2312
diff changeset
   146
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2312
diff changeset
   147
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2312
diff changeset
   148
class RegistryView(StartupView):
4865
90ad729d3540 [debug] minor improvments to the registry view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4725
diff changeset
   149
    """display vregistry content"""
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2312
diff changeset
   150
    __regid__ = 'registry'
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2312
diff changeset
   151
    __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
   152
    title = _('registry')
5825
2daf1ac79d5c [debug views] set http cache max age to 0 on debug views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5824
diff changeset
   153
    cache_max_age = 0
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2312
diff changeset
   154
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2312
diff changeset
   155
    def call(self, **kwargs):
6961
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6582
diff changeset
   156
        self.w(u'<h2>%s</h2>' % self._cw._("Registry's content"))
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   157
        keys = sorted(self._cw.vreg)
4916
4b8cdda342ae fix tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4873
diff changeset
   158
        url = xml_escape(self._cw.url())
4865
90ad729d3540 [debug] minor improvments to the registry view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4725
diff changeset
   159
        self.w(u'<p>%s</p>\n' % ' - '.join('<a href="%s#%s">%s</a>'
90ad729d3540 [debug] minor improvments to the registry view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4725
diff changeset
   160
                                           % (url, key, key) for key in keys))
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2312
diff changeset
   161
        for key in keys:
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6020
diff changeset
   162
            if key in ('boxes', 'contentnavigation'): # those are bw compat registries
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6020
diff changeset
   163
                continue
6961
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6582
diff changeset
   164
            self.w(u'<h3 id="%s">%s</h3>' % (key, key))
4865
90ad729d3540 [debug] minor improvments to the registry view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4725
diff changeset
   165
            if self._cw.vreg[key]:
10662
10942ed172de [py3k] dict.iteritems → dict.items
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10574
diff changeset
   166
                values = sorted(self._cw.vreg[key].items())
4865
90ad729d3540 [debug] minor improvments to the registry view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4725
diff changeset
   167
                self.wview('pyvaltable', pyvalue=[(key, xml_escape(repr(val)))
90ad729d3540 [debug] minor improvments to the registry view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4725
diff changeset
   168
                                                  for key, val in values])
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2312
diff changeset
   169
            else:
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2312
diff changeset
   170
                self.w(u'<p>Empty</p>\n')
4866
550e35a69b75 [debug] a new view to help debugging memory leaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4865
diff changeset
   171
550e35a69b75 [debug] a new view to help debugging memory leaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4865
diff changeset
   172
550e35a69b75 [debug] a new view to help debugging memory leaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4865
diff changeset
   173
class GCView(StartupView):
550e35a69b75 [debug] a new view to help debugging memory leaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4865
diff changeset
   174
    """display garbage collector information"""
550e35a69b75 [debug] a new view to help debugging memory leaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4865
diff changeset
   175
    __regid__ = 'gc'
550e35a69b75 [debug] a new view to help debugging memory leaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4865
diff changeset
   176
    __select__ = StartupView.__select__ & match_user_groups('managers')
4873
bfebe3d14d53 i18nupdate
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4866
diff changeset
   177
    title = _('memory leak debugging')
5825
2daf1ac79d5c [debug views] set http cache max age to 0 on debug views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5824
diff changeset
   178
    cache_max_age = 0
4866
550e35a69b75 [debug] a new view to help debugging memory leaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4865
diff changeset
   179
550e35a69b75 [debug] a new view to help debugging memory leaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4865
diff changeset
   180
    def call(self, **kwargs):
10311
4e9dcca71fad [views] Fix 'gc' view to use 'repo_gc_stats' service
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10309
diff changeset
   181
        stats = self._cw.call_service('repo_gc_stats')
6961
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6582
diff changeset
   182
        self.w(u'<h2>%s</h2>' % _('Garbage collection information'))
6582
8eb7883b4223 [pylint] fix a bug of pylint detected errors and i18n pb (calling builtins._ instead of req._)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6141
diff changeset
   183
        self.w(u'<h3>%s</h3>' % self._cw._('Looked up classes'))
10311
4e9dcca71fad [views] Fix 'gc' view to use 'repo_gc_stats' service
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10309
diff changeset
   184
        self.wview('pyvaltable', pyvalue=stats['lookupclasses'])
6582
8eb7883b4223 [pylint] fix a bug of pylint detected errors and i18n pb (calling builtins._ instead of req._)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6141
diff changeset
   185
        self.w(u'<h3>%s</h3>' % self._cw._('Most referenced classes'))
10311
4e9dcca71fad [views] Fix 'gc' view to use 'repo_gc_stats' service
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10309
diff changeset
   186
        self.wview('pyvaltable', pyvalue=stats['referenced'])
4e9dcca71fad [views] Fix 'gc' view to use 'repo_gc_stats' service
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10309
diff changeset
   187
        if stats['unreachable']:
6582
8eb7883b4223 [pylint] fix a bug of pylint detected errors and i18n pb (calling builtins._ instead of req._)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6141
diff changeset
   188
            self.w(u'<h3>%s</h3>' % self._cw._('Unreachable objects'))
10311
4e9dcca71fad [views] Fix 'gc' view to use 'repo_gc_stats' service
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10309
diff changeset
   189
            values = [xml_escape(val) for val in stats['unreachable']]
4866
550e35a69b75 [debug] a new view to help debugging memory leaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4865
diff changeset
   190
            self.wview('pyvallist', pyvalue=values)