Commit c35f03d1 authored by Tim Peters's avatar Tim Peters

s/register_oid/register_oids/ -- support more than 1 oid per call.

parent 5bf75c18
......@@ -35,7 +35,7 @@ class Tracer(object):
"""Trace all occurrences of a set of oids in a FileStorage.
Create passing a path to an existing FileStorage.
Call register_oid() one or more times to specify which oids to
Call register_oids(oid, ...) one or more times to specify which oids to
investigate.
Call run() to do the analysis. This isn't swift -- it has to read
every byte in the database, in order to find all references.
......@@ -62,21 +62,22 @@ class Tracer(object):
# in this mapping.
self.oid2name = {}
def register_oid(self, oid):
def register_oids(self, *oids):
"""
Declare that an oid is "interesting".
Declare that oids (0 or more) are "interesting".
The oid can be given as a native 8-byte string, or as an
An oid can be given as a native 8-byte string, or as an
integer.
Info will be gathered about all appearances of this oid in the
entire database, including references.
"""
for oid in oids:
if isinstance(oid, str):
assert len(oid) == 8
else:
oid = p64(oid)
self.oids[oid] = 0
self.oids[oid] = 0 # 0 revisions seen so far
def _msg(self, oid, tid, *args):
args = map(str, args)
......
......@@ -38,9 +38,9 @@ Create an empty FileStorage.
There's not a lot interesting in an empty DB!
>>> t = Tracer(path)
>>> t.register_oid(0x123456)
>>> t.register_oid(1)
>>> t.register_oid(0)
>>> t.register_oids(0x123456)
>>> t.register_oids(1)
>>> t.register_oids(0)
>>> t.run()
>>> t.report()
oid 0x00 <unknown> 0 revisions
......@@ -57,7 +57,7 @@ Create a root object and try again:
>>> db = ZODB.DB(st) # yes, that creates a root object!
>>> t = Tracer(path)
>>> t.register_oid(0); t.register_oid(1)
>>> t.register_oids(0, 1)
>>> t.run(); t.report() #doctest: +ELLIPSIS
oid 0x00 persistent.mapping.PersistentMapping 1 revision
tid 0x... offset=4 ...
......@@ -83,7 +83,7 @@ Let's add a BTree and try again:
>>> txn.get().note('added an OOBTree')
>>> txn.get().commit()
>>> t = Tracer(path)
>>> t.register_oid(0); t.register_oid(1)
>>> t.register_oids(0, 1)
>>> t.run(); t.report() #doctest: +ELLIPSIS
oid 0x00 persistent.mapping.PersistentMapping 2 revisions
tid 0x... offset=4 ...
......@@ -123,7 +123,7 @@ One more, storing a reference in the BTree back to the root object:
>>> txn.get().note('circling back to the root')
>>> txn.get().commit()
>>> t = Tracer(path)
>>> t.register_oid(0); t.register_oid(1); t.register_oid(2)
>>> t.register_oids(*range(3))
>>> t.run(); t.report() #doctest: +ELLIPSIS
oid 0x00 persistent.mapping.PersistentMapping 2 revisions
tid 0x... offset=4 ...
......
......@@ -68,7 +68,7 @@ def main():
if path is not None:
for line in open(path):
as_int = int(line, 0)
c.register_oid(as_int)
c.register_oids(as_int)
if not c.oids:
raise ValueError("no oids specified")
c.run()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment