From d7c84268a26a4391af55a3533422367b02737435 Mon Sep 17 00:00:00 2001 From: Daniel Gnoutcheff Date: Mon, 23 Jan 2017 18:38:22 -0500 Subject: Misc. unrecorded changes --- lsbin.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100755 lsbin.py (limited to 'lsbin.py') diff --git a/lsbin.py b/lsbin.py new file mode 100755 index 0000000..e4bd36c --- /dev/null +++ b/lsbin.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python3 + +import avfs +import os, sys + +# https://stackoverflow.com/questions/898669/how-can-i-detect-if-a-file-is-binary-non-text-in-python +textchars = bytearray({7,8,9,10,12,13,27} | set(range(0x20, 0x100)) - {0x7f}) +def is_binary(fname): + head = avfs.open(fname, 'rb').read(1024) + return bool(head.translate(None, textchars)) + +if __name__ == "__main__": + for fname in avfs.find(os.fsencode(sys.argv[1]), {b'.git'}): + try: + if is_binary(fname): + print(fname.decode('utf-8', 'replace')) + except: + pass + -- cgit v1.2.1