• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zopefoundation / Zope / 6651743771

26 Oct 2023 08:53AM UTC coverage: 82.189% (-0.05%) from 82.237%
6651743771

Pull #1178

github

drfho
table facelift
Pull Request #1178: Separate ZODB connection information into new ZODB Connections view

4368 of 6981 branches covered (0.0%)

Branch coverage included in aggregate %.

45 of 45 new or added lines in 2 files covered. (100.0%)

27570 of 31878 relevant lines covered (86.49%)

0.86 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

39.58
/src/App/ZODBConnectionDebugger.py
1
##############################################################################
2
#
3
# Copyright (c) 2023 Zope Foundation and Contributors.
4
#
5
# This software is subject to the provisions of the Zope Public License,
6
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
7
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
8
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
9
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
10
# FOR A PARTICULAR PURPOSE
11
#
12
##############################################################################
13

14
import pprint
1✔
15
import time
1✔
16
from operator import itemgetter
1✔
17

18
from AccessControl.class_init import InitializeClass
1✔
19
from AccessControl.SecurityInfo import ClassSecurityInfo
1✔
20
from Acquisition import Implicit
1✔
21
from App.special_dtml import DTMLFile
1✔
22
from OFS.SimpleItem import Item
1✔
23

24

25
class ZODBConnectionDebugger(Item, Implicit):
1✔
26
    id = 'ZODBConnectionDebugger'
1✔
27
    name = title = 'ZODB Connections'
1✔
28
    meta_type = 'ZODB Connection Debugger'
1✔
29
    zmi_icon = 'fas fa-bug'
1✔
30

31
    security = ClassSecurityInfo()
1✔
32

33
    manage_zodb_conns = manage_main = manage = manage_workspace = DTMLFile(
1✔
34
        'dtml/zodbConnections', globals())
35
    manage_zodb_conns._setName('manage_zodb_conns')
1✔
36
    manage_options = (
1✔
37
        {'label': 'Control Panel', 'action': '../manage_main'},
38
        {'label': 'Databases', 'action': '../Database/manage_main'},
39
        {'label': 'Configuration', 'action': '../Configuration/manage_main'},
40
        {'label': 'DAV Locks', 'action': '../DavLocks/manage_main'},
41
        {'label': 'Reference Counts', 'action': '../DebugInfo/manage_main'},
42
        {'label': 'ZODB Connections', 'action': 'manage_main'},
43
    )
44

45
    def dbconnections(self):
1✔
46
        import Zope2  # for data
×
47

48
        result = []
×
49
        now = time.time()
×
50

51
        def get_info(connection):
×
52
            # `result`, `time` and `before` are lexically inherited.
53
            request_info = {}
×
54
            request_info_formatted = ''
×
55
            debug_info_formatted = ''
×
56
            opened = connection.opened
×
57
            debug_info = connection.getDebugInfo() or {}
×
58

59
            if debug_info:
×
60
                debug_info_formatted = pprint.pformat(debug_info)
×
61
                if len(debug_info) == 2:
×
62
                    request_info = debug_info[0]
×
63
                    request_info.update(debug_info[1])
×
64
                    request_info_formatted = pprint.pformat(request_info)
×
65

66
            if opened is not None:
×
67
                # output UTC time with the standard Z time zone indicator
68
                open_since = "{}".format(
×
69
                    time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime(opened)))
70
                open_for = "{:.2f}s".format(now - opened)
×
71
            else:
72
                open_since = '(closed)'
×
73
                open_for = ''
×
74

75
            result.append({
×
76
                'open_since': open_since,
77
                'open_for': open_for,
78
                'info': debug_info,
79
                'info_formatted': debug_info_formatted,
80
                'request_info': request_info,
81
                'request_formatted': request_info_formatted,
82
                'before': connection.before,
83
                'cache_size': len(connection._cache),
84
            })
85

86
        Zope2.DB._connectionMap(get_info)
×
87
        return sorted(result, key=itemgetter('open_since'))
×
88

89

90
InitializeClass(ZODBConnectionDebugger)
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc