web/views/debug.py
changeset 6961 686c59dfc401
parent 6582 8eb7883b4223
child 7428 5338d895b891
equal deleted inserted replaced
6960:822f2530570d 6961:686c59dfc401
    25 from logilab.mtconverter import xml_escape
    25 from logilab.mtconverter import xml_escape
    26 
    26 
    27 from cubicweb import BadConnectionId
    27 from cubicweb import BadConnectionId
    28 from cubicweb.selectors import none_rset, match_user_groups
    28 from cubicweb.selectors import none_rset, match_user_groups
    29 from cubicweb.view import StartupView
    29 from cubicweb.view import StartupView
    30 from cubicweb.web.views import actions
    30 from cubicweb.web.views import actions, tabs
    31 
    31 
    32 def dict_to_html(w, dict):
    32 def dict_to_html(w, dict):
    33     # XHTML doesn't allow emtpy <ul> nodes
    33     # XHTML doesn't allow emtpy <ul> nodes
    34     if dict:
    34     if dict:
    35         w(u'<ul>')
    35         w(u'<ul>')
    37             w(u'<li><span class="label">%s</span>: <span>%s</span></li>' % (
    37             w(u'<li><span class="label">%s</span>: <span>%s</span></li>' % (
    38                 xml_escape(str(key)), xml_escape(repr(dict[key]))))
    38                 xml_escape(str(key)), xml_escape(repr(dict[key]))))
    39         w(u'</ul>')
    39         w(u'</ul>')
    40 
    40 
    41 
    41 
    42 
       
    43 class SiteInfoAction(actions.ManagersAction):
    42 class SiteInfoAction(actions.ManagersAction):
    44     __regid__ = 'siteinfo'
    43     __regid__ = 'siteinfo'
    45     __select__ = match_user_groups('users','managers')
    44     __select__ = match_user_groups('users','managers')
    46     title = _('info')
    45     title = _('siteinfo')
    47     order = 30
    46     category = 'manage'
       
    47     order = 1000
       
    48 
       
    49 
       
    50 class SiteInfoView(tabs.TabsMixin, StartupView):
       
    51     __regid__ = 'siteinfo'
       
    52     title = _('Site information')
       
    53     tabs = [_('info'), _('registry'), _('gc')]
       
    54     default_tab = 'info'
       
    55 
       
    56     def call(self, **kwargs):
       
    57         """The default view representing the instance's management"""
       
    58         self.w(u'<h1>%s</h1>' % self._cw._(self.title))
       
    59         self.render_tabs(self.tabs, self.default_tab)
    48 
    60 
    49 
    61 
    50 class ProcessInformationView(StartupView):
    62 class ProcessInformationView(StartupView):
    51     """display various web server /repository information"""
    63     """display various web server /repository information"""
    52     __regid__ = 'info'
    64     __regid__ = 'info'
    59         req = self._cw
    71         req = self._cw
    60         dtformat = req.property_value('ui.datetime-format')
    72         dtformat = req.property_value('ui.datetime-format')
    61         _ = req._
    73         _ = req._
    62         w = self.w
    74         w = self.w
    63         # generic instance information
    75         # generic instance information
    64         w(u'<h1>%s</h1>' % _('Instance'))
    76         w(u'<h2>%s</h2>' % _('Instance'))
    65         w(u'<table>')
    77         w(u'<table>')
    66         w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % (
    78         w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % (
    67             _('config type'), self._cw.vreg.config.name))
    79             _('config type'), self._cw.vreg.config.name))
    68         w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % (
    80         w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % (
    69             _('config mode'), self._cw.vreg.config.mode))
    81             _('config mode'), self._cw.vreg.config.mode))
    80             w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % (
    92             w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % (
    81                 cube, cubeversion))
    93                 cube, cubeversion))
    82         w(u'</table>')
    94         w(u'</table>')
    83         # repository information
    95         # repository information
    84         repo = req.vreg.config.repository(None)
    96         repo = req.vreg.config.repository(None)
    85         w(u'<h1>%s</h1>' % _('Repository'))
    97         w(u'<h2>%s</h2>' % _('Repository'))
    86         w(u'<h3>%s</h3>' % _('resources usage'))
    98         w(u'<h3>%s</h3>' % _('resources usage'))
    87         w(u'<table>')
    99         w(u'<table>')
    88         stats = repo.stats()
   100         stats = repo.stats()
    89         for element in sorted(stats):
   101         for element in sorted(stats):
    90             w(u'<tr><th align="left">%s</th><td>%s %s</td></tr>'
   102             w(u'<tr><th align="left">%s</th><td>%s %s</td></tr>'
   105                     w(u'</li>')
   117                     w(u'</li>')
   106                 w(u'</ul>')
   118                 w(u'</ul>')
   107             else:
   119             else:
   108                 w(u'<p>%s</p>' % _('no repository sessions found'))
   120                 w(u'<p>%s</p>' % _('no repository sessions found'))
   109         # web server information
   121         # web server information
   110         w(u'<h1>%s</h1>' % _('Web server'))
   122         w(u'<h2>%s</h2>' % _('Web server'))
   111         w(u'<table>')
   123         w(u'<table>')
   112         w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % (
   124         w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % (
   113             _('base url'), req.base_url()))
   125             _('base url'), req.base_url()))
   114         w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % (
   126         w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % (
   115             _('data directory url'), req.datadir_url))
   127             _('data directory url'), req.datadir_url))
   144     __select__ = StartupView.__select__ & match_user_groups('managers')
   156     __select__ = StartupView.__select__ & match_user_groups('managers')
   145     title = _('registry')
   157     title = _('registry')
   146     cache_max_age = 0
   158     cache_max_age = 0
   147 
   159 
   148     def call(self, **kwargs):
   160     def call(self, **kwargs):
   149         self.w(u'<h1>%s</h1>' % self._cw._("Registry's content"))
   161         self.w(u'<h2>%s</h2>' % self._cw._("Registry's content"))
   150         keys = sorted(self._cw.vreg)
   162         keys = sorted(self._cw.vreg)
   151         url = xml_escape(self._cw.url())
   163         url = xml_escape(self._cw.url())
   152         self.w(u'<p>%s</p>\n' % ' - '.join('<a href="%s#%s">%s</a>'
   164         self.w(u'<p>%s</p>\n' % ' - '.join('<a href="%s#%s">%s</a>'
   153                                            % (url, key, key) for key in keys))
   165                                            % (url, key, key) for key in keys))
   154         for key in keys:
   166         for key in keys:
   155             if key in ('boxes', 'contentnavigation'): # those are bw compat registries
   167             if key in ('boxes', 'contentnavigation'): # those are bw compat registries
   156                 continue
   168                 continue
   157             self.w(u'<h2 id="%s">%s</h2>' % (key, key))
   169             self.w(u'<h3 id="%s">%s</h3>' % (key, key))
   158             if self._cw.vreg[key]:
   170             if self._cw.vreg[key]:
   159                 values = sorted(self._cw.vreg[key].iteritems())
   171                 values = sorted(self._cw.vreg[key].iteritems())
   160                 self.wview('pyvaltable', pyvalue=[(key, xml_escape(repr(val)))
   172                 self.wview('pyvaltable', pyvalue=[(key, xml_escape(repr(val)))
   161                                                   for key, val in values])
   173                                                   for key, val in values])
   162             else:
   174             else:
   184         try:
   196         try:
   185             from cubicweb.server.session import Session, InternalSession
   197             from cubicweb.server.session import Session, InternalSession
   186             lookupclasses += (InternalSession, Session)
   198             lookupclasses += (InternalSession, Session)
   187         except ImportError:
   199         except ImportError:
   188             pass # no server part installed
   200             pass # no server part installed
   189         self.w(u'<h1>%s</h1>' % _('Garbage collection information'))
   201         self.w(u'<h2>%s</h2>' % _('Garbage collection information'))
   190         counters, ocounters, garbage = gc_info(lookupclasses,
   202         counters, ocounters, garbage = gc_info(lookupclasses,
   191                                                viewreferrersclasses=())
   203                                                viewreferrersclasses=())
   192         self.w(u'<h3>%s</h3>' % self._cw._('Looked up classes'))
   204         self.w(u'<h3>%s</h3>' % self._cw._('Looked up classes'))
   193         values = sorted(counters.iteritems(), key=lambda x: x[1], reverse=True)
   205         values = sorted(counters.iteritems(), key=lambda x: x[1], reverse=True)
   194         self.wview('pyvaltable', pyvalue=values)
   206         self.wview('pyvaltable', pyvalue=values)