diff options
author | ZyX <kp-pav@yandex.ru> | 2015-08-08 05:10:19 +0300 |
---|---|---|
committer | ZyX <kp-pav@yandex.ru> | 2015-10-08 22:00:29 +0300 |
commit | 1e067920994a5dd02df8f71f21afa29f0d4bcd21 (patch) | |
tree | 605391848b5e483b61c3c6853f1563652e7ff2dc /scripts/shadacat.py | |
parent | d8b0cd5c173d6255a100977bd18204ecf989f5d4 (diff) | |
download | rneovim-1e067920994a5dd02df8f71f21afa29f0d4bcd21.tar.gz rneovim-1e067920994a5dd02df8f71f21afa29f0d4bcd21.tar.bz2 rneovim-1e067920994a5dd02df8f71f21afa29f0d4bcd21.zip |
scripts: Improve shadacat to work with unknown items
Diffstat (limited to 'scripts/shadacat.py')
-rwxr-xr-x | scripts/shadacat.py | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/scripts/shadacat.py b/scripts/shadacat.py index d29000a5d9..4ff493bfbc 100755 --- a/scripts/shadacat.py +++ b/scripts/shadacat.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3.4 +import os import sys import codecs @@ -58,18 +59,28 @@ def mnormalize(o): return ctable.get(type(o), idfunc)(o) -with open(sys.argv[1], 'rb') as fp: +fname = sys.argv[1] +poswidth = len(str(os.stat(fname).st_size or 1000)) + + +with open(fname, 'rb') as fp: unpacker = msgpack.Unpacker(file_like=fp, read_size=1) + max_type = max(typ.value for typ in EntryTypes) while True: try: pos = fp.tell() - typ = EntryTypes(unpacker.unpack()) + typ = unpacker.unpack() except msgpack.OutOfData: break else: timestamp = unpacker.unpack() time = datetime.fromtimestamp(timestamp) length = unpacker.unpack() - entry = unpacker.unpack() - print('{0:4} {1:13} {2} {3:5} {4!r}'.format( - pos, typ.name, time.isoformat(), length, mnormalize(entry))) + if typ > max_type: + entry = fp.read(length) + typ = EntryTypes.Unknown + else: + entry = unpacker.unpack() + typ = EntryTypes(typ) + print('%*u %13s %s %5u %r' % ( + poswidth, pos, typ.name, time.isoformat(), length, mnormalize(entry))) |