-
Notifications
You must be signed in to change notification settings - Fork 1
/
crc32.py
39 lines (29 loc) · 1001 Bytes
/
crc32.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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_files(patterns)
for file in files:
try:
crc = zlib.crc32(file.read('rb'))
crc = hex(crc)[2:].rjust(8, '0')
pipeable.stdout(f'{crc} {file.absolute_path}')
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:]))