mirror of
https://github.com/neovim/neovim.git
synced 2025-09-18 17:28:23 +00:00
scripts: Add filter argument to shadacat.py
This commit is contained in:
@@ -60,9 +60,22 @@ def mnormalize(o):
|
|||||||
|
|
||||||
|
|
||||||
fname = sys.argv[1]
|
fname = sys.argv[1]
|
||||||
|
try:
|
||||||
|
filt = sys.argv[2]
|
||||||
|
except IndexError:
|
||||||
|
filt = lambda entry: True
|
||||||
|
else:
|
||||||
|
_filt = filt
|
||||||
|
filt = lambda entry: eval(_filt, globals(), {'entry': entry})
|
||||||
|
|
||||||
poswidth = len(str(os.stat(fname).st_size or 1000))
|
poswidth = len(str(os.stat(fname).st_size or 1000))
|
||||||
|
|
||||||
|
|
||||||
|
class FullEntry(dict):
|
||||||
|
def __init__(self, val):
|
||||||
|
self.__dict__.update(val)
|
||||||
|
|
||||||
|
|
||||||
with open(fname, 'rb') as fp:
|
with open(fname, 'rb') as fp:
|
||||||
unpacker = msgpack.Unpacker(file_like=fp, read_size=1)
|
unpacker = msgpack.Unpacker(file_like=fp, read_size=1)
|
||||||
max_type = max(typ.value for typ in EntryTypes)
|
max_type = max(typ.value for typ in EntryTypes)
|
||||||
@@ -82,5 +95,15 @@ with open(fname, 'rb') as fp:
|
|||||||
else:
|
else:
|
||||||
entry = unpacker.unpack()
|
entry = unpacker.unpack()
|
||||||
typ = EntryTypes(typ)
|
typ = EntryTypes(typ)
|
||||||
|
full_entry = FullEntry({
|
||||||
|
'value': entry,
|
||||||
|
'timestamp': timestamp,
|
||||||
|
'time': time,
|
||||||
|
'length': length,
|
||||||
|
'pos': pos,
|
||||||
|
'type': typ,
|
||||||
|
})
|
||||||
|
if not filt(full_entry):
|
||||||
|
continue
|
||||||
print('%*u %13s %s %5u %r' % (
|
print('%*u %13s %s %5u %r' % (
|
||||||
poswidth, pos, typ.name, time.isoformat(), length, mnormalize(entry)))
|
poswidth, pos, typ.name, time.isoformat(), length, mnormalize(entry)))
|
||||||
|
Reference in New Issue
Block a user