1 | n/a | import hashlib |
---|
2 | n/a | import os |
---|
3 | n/a | import sys |
---|
4 | n/a | |
---|
5 | n/a | def main(): |
---|
6 | n/a | filenames, hashes, sizes = [], [], [] |
---|
7 | n/a | |
---|
8 | n/a | for file in sys.argv[1:]: |
---|
9 | n/a | if not os.path.isfile(file): |
---|
10 | n/a | continue |
---|
11 | n/a | |
---|
12 | n/a | with open(file, 'rb') as f: |
---|
13 | n/a | data = f.read() |
---|
14 | n/a | md5 = hashlib.md5() |
---|
15 | n/a | md5.update(data) |
---|
16 | n/a | filenames.append(os.path.split(file)[1]) |
---|
17 | n/a | hashes.append(md5.hexdigest()) |
---|
18 | n/a | sizes.append(str(len(data))) |
---|
19 | n/a | |
---|
20 | n/a | print('{:40s} {:<32s} {:<9s}'.format('File', 'MD5', 'Size')) |
---|
21 | n/a | for f, h, s in zip(filenames, hashes, sizes): |
---|
22 | n/a | print('{:40s} {:>32s} {:>9s}'.format(f, h, s)) |
---|
23 | n/a | |
---|
24 | n/a | |
---|
25 | n/a | |
---|
26 | n/a | if __name__ == "__main__": |
---|
27 | n/a | sys.exit(int(main() or 0)) |
---|