Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_text/tests/detect_corpus/python/shebang.txt

988 bytes, 1 run

created by r1870400018:12034, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1#!/usr/bin/env python3
2
3import argparse
4import hashlib
5import sys
6
7
8def hash_file(path, algorithm='sha256'):
9 h = hashlib.new(algorithm)
10 with open(path, 'rb') as f:
11 while True:
12 chunk = f.read(8192)
13 if not chunk:
14 break
15 h.update(chunk)
16 return h.hexdigest()
17
18
19def main():
20 parser = argparse.ArgumentParser(description='hash files')
21 parser.add_argument('files', nargs='+', help='files to hash')
22 parser.add_argument('--algorithm', default='sha256',
23 choices=['md5', 'sha1', 'sha256', 'sha512'])
24 args = parser.parse_args()
25
26 for path in args.files:
27 try:
28 digest = hash_file(path, args.algorithm)
29 print(f"{digest} {path}")
30 except FileNotFoundError:
31 print(f"not found: {path}", file=sys.stderr)
32 except PermissionError:
33 print(f"permission denied: {path}", file=sys.stderr)
34
35
36if __name__ == '__main__':
37 main()