Ethan Dalool
4a9051e617
With pathclass.glob_many, we can clean up and feel more confident about many programs that use pipeable to take glob patterns. Added return 0 to all programs that didn't have it, so we have consistent and explicit command line return values. Other linting and whitespace.
40 lines
1 KiB
Python
40 lines
1 KiB
Python
import argparse
|
|
import sys
|
|
import zlib
|
|
|
|
from voussoirkit import pathclass
|
|
from voussoirkit import pipeable
|
|
from voussoirkit import vlogging
|
|
|
|
log = vlogging.getLogger(__name__, 'crc32')
|
|
|
|
def crc32_argparse(args):
|
|
return_status = 0
|
|
|
|
patterns = pipeable.input_many(args.patterns, skip_blank=True, strip=True)
|
|
files = pathclass.glob_many(patterns, files=True)
|
|
|
|
for file in files:
|
|
try:
|
|
with open(file, 'rb') as handle:
|
|
crc = zlib.crc32(handle.read())
|
|
crc = hex(crc)[2:].rjust(8, '0')
|
|
pipeable.stdout(f'{crc} {file}')
|
|
except Exception as e:
|
|
log.error('%s %s', file, e)
|
|
return_status = 1
|
|
|
|
return return_status
|
|
|
|
@vlogging.main_decorator
|
|
def main(argv):
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
|
|
parser.add_argument('patterns', 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:]))
|