1#!/usr/bin/python 2 3############################################################################## 4# 5# Copyright (c) 2004 Zope Foundation and Contributors. 6# All Rights Reserved. 7# 8# This software is subject to the provisions of the Zope Public License, 9# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. 10# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED 11# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 12# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS 13# FOR A PARTICULAR PURPOSE 14# 15############################################################################## 16 17"""FileStorage oid-tracer. 18 19usage: fsoids.py [-f oid_file] Data.fs [oid]... 20 21Display information about all occurrences of specified oids in a FileStorage. 22This is meant for heavy debugging. 23 24This includes all revisions of the oids, all objects referenced by the 25oids, and all revisions of all objects referring to the oids. 26 27If specified, oid_file is an input text file, containing one oid per 28line. oids are specified as integers, in any of Python's integer 29notations (typically like 0x341a). One or more oids can also be specified 30on the command line. 31 32The output is grouped by oid, from smallest to largest, and sub-grouped 33by transaction, from oldest to newest. 34 35This will not alter the FileStorage, but running against a live FileStorage 36is not recommended (spurious error messages may result). 37 38See testfsoids.py for a tutorial doctest. 39""" 40from __future__ import print_function 41 42import sys 43 44from ZODB.FileStorage.fsoids import Tracer 45 46def usage(): 47 print(__doc__) 48 49def main(): 50 import getopt 51 52 try: 53 opts, args = getopt.getopt(sys.argv[1:], 'f:') 54 if not args: 55 usage() 56 raise ValueError("Must specify a FileStorage") 57 path = None 58 for k, v in opts: 59 if k == '-f': 60 path = v 61 except (getopt.error, ValueError): 62 usage() 63 raise 64 65 c = Tracer(args[0]) 66 for oid in args[1:]: 67 as_int = int(oid, 0) # 0 == auto-detect base 68 c.register_oids(as_int) 69 if path is not None: 70 for line in open(path): 71 as_int = int(line, 0) 72 c.register_oids(as_int) 73 if not c.oids: 74 raise ValueError("no oids specified") 75 c.run() 76 c.report() 77 78if __name__ == "__main__": 79 main() 80