bin/checksum
raw| 1 | #!/usr/bin/env python |
| 2 | # -*- coding: utf-8 -*- |
| 3 | |
| 4 | import hashlib |
| 5 | import sys |
| 6 | |
| 7 | |
| 8 | def run(paths): |
| 9 | sha = hashlib.sha1() |
| 10 | |
| 11 | for path in paths: |
| 12 | try: |
| 13 | with open(path, 'rb') as f: |
| 14 | for chunk in iter(lambda: f.read(4096), b''): |
| 15 | sha.update(chunk) |
| 16 | except IOError: |
| 17 | sha.update(path.encode()) |
| 18 | |
| 19 | print(sha.hexdigest()) |
| 20 | |
| 21 | |
| 22 | if __name__ == '__main__': |
| 23 | run(sys.argv[1:]) |