Commit 5472857b authored by Marius Gedminas's avatar Marius Gedminas

Fix ResourceWarning in fstail.py

parent 2d181876
...@@ -26,21 +26,21 @@ except ImportError: ...@@ -26,21 +26,21 @@ except ImportError:
from sha import sha as sha1 from sha import sha as sha1
def main(path, ntxn): def main(path, ntxn):
f = open(path, "rb") with open(path, "rb") as f:
f.seek(0, 2) f.seek(0, 2)
th = prev_txn(f) th = prev_txn(f)
i = ntxn i = ntxn
while th and i > 0: while th and i > 0:
hash = sha1(th.get_raw_data()).digest() hash = sha1(th.get_raw_data()).digest()
l = len(str(th.get_timestamp())) + 1 l = len(str(th.get_timestamp())) + 1
th.read_meta() th.read_meta()
print("%s: hash=%s" % (th.get_timestamp(), print("%s: hash=%s" % (th.get_timestamp(),
binascii.hexlify(hash).decode())) binascii.hexlify(hash).decode()))
print(("user=%r description=%r length=%d offset=%d" print(("user=%r description=%r length=%d offset=%d"
% (th.user, th.descr, th.length, th.get_data_offset()))) % (th.user, th.descr, th.length, th.get_data_offset())))
print() print()
th = th.prev_txn() th = th.prev_txn()
i -= 1 i -= 1
def Main(): def Main():
ntxn = 10 ntxn = 10
......
...@@ -11,7 +11,7 @@ We have to prepare a FileStorage first: ...@@ -11,7 +11,7 @@ We have to prepare a FileStorage first:
>>> from ZODB.DB import DB >>> from ZODB.DB import DB
>>> import transaction >>> import transaction
>>> from tempfile import mktemp >>> from tempfile import mktemp
>>> storagefile = mktemp() >>> storagefile = mktemp(suffix='.fs')
>>> base_storage = FileStorage(storagefile) >>> base_storage = FileStorage(storagefile)
>>> database = DB(base_storage) >>> database = DB(base_storage)
>>> connection1 = database.open() >>> connection1 = database.open()
...@@ -33,6 +33,7 @@ Now lets have a look at the last transactions of this FileStorage: ...@@ -33,6 +33,7 @@ Now lets have a look at the last transactions of this FileStorage:
Now clean up the storage again: Now clean up the storage again:
>>> import os >>> import os
>>> connection1.close()
>>> base_storage.close() >>> base_storage.close()
>>> os.unlink(storagefile) >>> os.unlink(storagefile)
>>> os.unlink(storagefile+'.index') >>> os.unlink(storagefile+'.index')
......
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