cmd/crc32.py

34 lines
818 B
Python
Raw Normal View History

2020-12-08 04:31:03 +00:00
import argparse
2020-05-13 01:17:17 +00:00
import sys
import zlib
2020-12-08 04:31:03 +00:00
from voussoirkit import pipeable
2020-05-13 01:17:17 +00:00
from voussoirkit import winglob
2020-12-08 04:31:03 +00:00
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:]))