File: checksum

package info (click to toggle)
python-aiomusiccast 0.14.8-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 496 kB
  • sloc: python: 2,965; makefile: 152
file content (23 lines) | stat: -rwxr-xr-x 434 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import hashlib
import sys


def run(paths):
    sha = hashlib.sha1()

    for path in paths:
        try:
            with open(path, 'rb') as f:
                for chunk in iter(lambda: f.read(4096), b''):
                    sha.update(chunk)
        except IOError:
            sha.update(path.encode())

    print(sha.hexdigest())


if __name__ == '__main__':
    run(sys.argv[1:])