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

zopefoundation / ZODB / 8679957491

30 Mar 2024 11:42AM CUT coverage: 83.744%. Remained the same
8679957491

push

github

dataflake
- vb [ci skip]

2878 of 4051 branches covered (71.04%)

13348 of 15939 relevant lines covered (83.74%)

0.84 hits per line

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

0.0
/src/ZODB/scripts/space.py
1
#!/usr/bin/env python
2
"""Report on the space used by objects in a storage.
×
3

4
usage: space.py data.fs
5

6
The current implementation only supports FileStorage.
7

8
Current limitations / simplifications: Ignores revisions and versions.
9
"""
10

11
from operator import itemgetter
×
12

13
from ZODB.FileStorage import FileStorage
×
14
from ZODB.utils import U64
×
15
from ZODB.utils import get_pickle_metadata
×
16
from ZODB.utils import load_current
×
17

18

19
def run(path, v=0):
×
20
    fs = FileStorage(path, read_only=1)
×
21
    # break into the file implementation
22
    if hasattr(fs._index, 'iterkeys'):
×
23
        iter = fs._index.keys()
×
24
    else:
25
        iter = fs._index.keys()
×
26
    totals = {}
×
27
    for oid in iter:
×
28
        data, serialno = load_current(fs, oid)
×
29
        mod, klass = get_pickle_metadata(data)
×
30
        key = "{}.{}".format(mod, klass)
×
31
        bytes, count = totals.get(key, (0, 0))
×
32
        bytes += len(data)
×
33
        count += 1
×
34
        totals[key] = bytes, count
×
35
        if v:
×
36
            print("%8s %5d %s" % (U64(oid), len(data), key))
×
37
    L = sorted(totals.items(), key=itemgetter(1), reverse=True)
×
38
    print("Totals per object class:")
×
39
    for key, (bytes, count) in L:
×
40
        print("%8d %8d %s" % (count, bytes, key))
×
41

42

43
def main():
×
44
    import getopt
×
45
    import sys
×
46
    try:
×
47
        opts, args = getopt.getopt(sys.argv[1:], "v")
×
48
    except getopt.error as msg:
×
49
        print(msg)
×
50
        print("usage: space.py [-v] Data.fs")
×
51
        sys.exit(2)
×
52
    if len(args) != 1:
×
53
        print("usage: space.py [-v] Data.fs")
×
54
        sys.exit(2)
×
55
    v = 0
×
56
    for o, a in opts:
×
57
        if o == "-v":
×
58
            v += 1
×
59
    path = args[0]
×
60
    run(path, v)
×
61

62

63
if __name__ == "__main__":
×
64
    main()
×
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