From b51c8032ace8536281bab56292eedd1c85c917fb Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Mon, 7 Dec 2020 20:31:03 -0800 Subject: [PATCH] Update crc32.py. --- crc32.py | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/crc32.py b/crc32.py index ca678cf..a51b761 100644 --- a/crc32.py +++ b/crc32.py @@ -1,11 +1,33 @@ +import argparse import sys import zlib +from voussoirkit import pipeable from voussoirkit import winglob -patterns = sys.argv[1:] -files = [file for pattern in patterns for file in winglob.glob(pattern)] -for file in files: - with open(file, 'rb') as handle: - crc = zlib.crc32(handle.read()) - print(hex(crc)[2:].rjust(8, '0'), file) +def crc32_argparse(args): + files = ( + file + for arg in args.source + for pattern in pipeable.input(arg) + for file in winglob.glob(pattern) + ) + for file in files: + try: + with open(file, 'rb') as handle: + crc = zlib.crc32(handle.read()) + print(hex(crc)[2:].rjust(8, '0'), file) + except Exception as e: + print(file, e) + +def main(argv): + parser = argparse.ArgumentParser(description=__doc__) + + parser.add_argument('source', nargs='+') + parser.set_defaults(func=crc32_argparse) + + args = parser.parse_args(argv) + return args.func(args) + +if __name__ == '__main__': + raise SystemExit(main(sys.argv[1:]))