Skip to content

Commit

Permalink
Fix ResourceWarning in fstail.py
Browse files Browse the repository at this point in the history
  • Loading branch information
mgedmin committed Feb 28, 2013
1 parent 2d18187 commit 5472857
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
30 changes: 15 additions & 15 deletions src/ZODB/scripts/fstail.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@
from sha import sha as sha1

def main(path, ntxn):
f = open(path, "rb")
f.seek(0, 2)
th = prev_txn(f)
i = ntxn
while th and i > 0:
hash = sha1(th.get_raw_data()).digest()
l = len(str(th.get_timestamp())) + 1
th.read_meta()
print("%s: hash=%s" % (th.get_timestamp(),
binascii.hexlify(hash).decode()))
print(("user=%r description=%r length=%d offset=%d"
% (th.user, th.descr, th.length, th.get_data_offset())))
print()
th = th.prev_txn()
i -= 1
with open(path, "rb") as f:
f.seek(0, 2)
th = prev_txn(f)
i = ntxn
while th and i > 0:
hash = sha1(th.get_raw_data()).digest()
l = len(str(th.get_timestamp())) + 1
th.read_meta()
print("%s: hash=%s" % (th.get_timestamp(),
binascii.hexlify(hash).decode()))
print(("user=%r description=%r length=%d offset=%d"
% (th.user, th.descr, th.length, th.get_data_offset())))
print()
th = th.prev_txn()
i -= 1

def Main():
ntxn = 10
Expand Down
3 changes: 2 additions & 1 deletion src/ZODB/scripts/tests/fstail.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ We have to prepare a FileStorage first:
>>> from ZODB.DB import DB
>>> import transaction
>>> from tempfile import mktemp
>>> storagefile = mktemp()
>>> storagefile = mktemp(suffix='.fs')
>>> base_storage = FileStorage(storagefile)
>>> database = DB(base_storage)
>>> connection1 = database.open()
Expand All @@ -33,6 +33,7 @@ Now lets have a look at the last transactions of this FileStorage:
Now clean up the storage again:

>>> import os
>>> connection1.close()
>>> base_storage.close()
>>> os.unlink(storagefile)
>>> os.unlink(storagefile+'.index')
Expand Down

0 comments on commit 5472857

Please sign in to comment.