web/views/debug.py
changeset 10924 2125def9498b
parent 10923 846e5676ca39
child 11127 6464edfa95bb
equal deleted inserted replaced
10923:846e5676ca39 10924:2125def9498b
    33 def dict_to_html(w, dict):
    33 def dict_to_html(w, dict):
    34     # XHTML doesn't allow emtpy <ul> nodes
    34     # XHTML doesn't allow emtpy <ul> nodes
    35     if dict:
    35     if dict:
    36         w(u'<ul>')
    36         w(u'<ul>')
    37         for key in sorted(dict):
    37         for key in sorted(dict):
    38             w(u'<li><span class="label">%s</span>: <span>%s</span></li>' % (
    38             w(u'<li><span>%s</span>: <span>%s</span></li>' % (
    39                 xml_escape(str(key)), xml_escape(repr(dict[key]))))
    39                 xml_escape(str(key)), xml_escape(repr(dict[key]))))
    40         w(u'</ul>')
    40         w(u'</ul>')
    41 
    41 
    42 
    42 
    43 class SiteInfoAction(actions.ManagersAction):
    43 class SiteInfoAction(actions.ManagersAction):
    74         _ = req._
    74         _ = req._
    75         w = self.w
    75         w = self.w
    76         repo = req.cnx.repo
    76         repo = req.cnx.repo
    77         # generic instance information
    77         # generic instance information
    78         w(u'<h2>%s</h2>' % _('Instance'))
    78         w(u'<h2>%s</h2>' % _('Instance'))
    79         w(u'<table>')
    79         pyvalue = ((_('config type'), self._cw.vreg.config.name),
    80         w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % (
    80                    (_('config mode'), self._cw.vreg.config.mode),
    81             _('config type'), self._cw.vreg.config.name))
    81                    (_('instance home'), self._cw.vreg.config.apphome))
    82         w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % (
    82         self.wview('pyvaltable', pyvalue=pyvalue, header_column_idx=0)
    83             _('config mode'), self._cw.vreg.config.mode))
       
    84         w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % (
       
    85             _('instance home'), self._cw.vreg.config.apphome))
       
    86         w(u'</table>')
       
    87         vcconf = repo.get_versions()
    83         vcconf = repo.get_versions()
    88         w(u'<h3>%s</h3>' % _('versions configuration'))
    84         w(u'<h3>%s</h3>' % _('versions configuration'))
    89         w(u'<table>')
    85         missing = _('no version information')
    90         w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % (
    86         pyvalue = [('CubicWeb', vcconf.get('cubicweb', missing))]
    91             'CubicWeb', vcconf.get('cubicweb', _('no version information'))))
    87         pyvalue += [(cube, vcconf.get(cube, missing))
    92         for cube in sorted(self._cw.vreg.config.cubes()):
    88                     for cube in sorted(self._cw.vreg.config.cubes())]
    93             cubeversion = vcconf.get(cube, _('no version information'))
    89         self.wview('pyvaltable', pyvalue=pyvalue, header_column_idx=0)
    94             w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % (
       
    95                 cube, cubeversion))
       
    96         w(u'</table>')
       
    97         # repository information
    90         # repository information
    98         w(u'<h2>%s</h2>' % _('Repository'))
    91         w(u'<h2>%s</h2>' % _('Repository'))
    99         w(u'<h3>%s</h3>' % _('resources usage'))
    92         w(u'<h3>%s</h3>' % _('resources usage'))
   100         w(u'<table>')
       
   101         stats = self._cw.call_service('repo_stats')
    93         stats = self._cw.call_service('repo_stats')
   102         stats['looping_tasks'] = ', '.join('%s (%s seconds)' % (n, i) for n, i in stats['looping_tasks'])
    94         stats['looping_tasks'] = ', '.join('%s (%s seconds)' % (n, i) for n, i in stats['looping_tasks'])
   103         stats['threads'] = ', '.join(sorted(stats['threads']))
    95         stats['threads'] = ', '.join(sorted(stats['threads']))
   104         for k in stats:
    96         for k in stats:
   105             if k in ('extid_cache_size', 'type_source_cache_size'):
    97             if k in ('extid_cache_size', 'type_source_cache_size'):
   106                 continue
    98                 continue
   107             if k.endswith('_cache_size'):
    99             if k.endswith('_cache_size'):
   108                 stats[k] = '%s / %s' % (stats[k]['size'], stats[k]['maxsize'])
   100                 stats[k] = '%s / %s' % (stats[k]['size'], stats[k]['maxsize'])
   109         for element in sorted(stats):
   101         def format_stat(sname, sval):
   110             w(u'<tr><th align="left">%s</th><td>%s %s</td></tr>'
   102             return '%s %s' % (xml_escape(text_type(sval)),
   111                    % (element, xml_escape(text_type(stats[element])),
   103                               sname.endswith('percent') and '%' or '')
   112                       element.endswith('percent') and '%' or '' ))
   104         pyvalue = [(sname, format_stat(sname, sval))
   113         w(u'</table>')
   105                     for sname, sval in sorted(stats.items())]
       
   106         self.wview('pyvaltable', pyvalue=pyvalue, header_column_idx=0)
       
   107         # open repo sessions
   114         if req.cnx.is_repo_in_memory and req.user.is_in_group('managers'):
   108         if req.cnx.is_repo_in_memory and req.user.is_in_group('managers'):
   115             w(u'<h3>%s</h3>' % _('opened sessions'))
   109             w(u'<h3>%s</h3>' % _('opened sessions'))
   116             sessions = repo._sessions.values()
   110             sessions = repo._sessions.values()
   117             if sessions:
   111             if sessions:
   118                 w(u'<ul>')
   112                 w(u'<ul>')
   126                 w(u'</ul>')
   120                 w(u'</ul>')
   127             else:
   121             else:
   128                 w(u'<p>%s</p>' % _('no repository sessions found'))
   122                 w(u'<p>%s</p>' % _('no repository sessions found'))
   129         # web server information
   123         # web server information
   130         w(u'<h2>%s</h2>' % _('Web server'))
   124         w(u'<h2>%s</h2>' % _('Web server'))
   131         w(u'<table>')
   125         pyvalue = ((_('base url'), req.base_url()),
   132         w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % (
   126                    (_('data directory url'), req.datadir_url))
   133             _('base url'), req.base_url()))
   127         self.wview('pyvaltable', pyvalue=pyvalue, header_column_idx=0)
   134         w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % (
       
   135             _('data directory url'), req.datadir_url))
       
   136         w(u'</table>')
       
   137         from cubicweb.web.application import SESSION_MANAGER
   128         from cubicweb.web.application import SESSION_MANAGER
   138         if SESSION_MANAGER is not None and req.user.is_in_group('managers'):
   129         if SESSION_MANAGER is not None and req.user.is_in_group('managers'):
   139             sessions = SESSION_MANAGER.current_sessions()
   130             sessions = SESSION_MANAGER.current_sessions()
   140             w(u'<h3>%s</h3>' % _('opened web sessions'))
   131             w(u'<h3>%s</h3>' % _('opened web sessions'))
   141             if sessions:
   132             if sessions: