Update crc32.py.
This commit is contained in:
parent
27463a1711
commit
b51c8032ac
1 changed files with 28 additions and 6 deletions
34
crc32.py
34
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:]))
|
||||
|
|
Loading…
Reference in a new issue