blob: ac2eac0cb6821ad66f3c162078e46c5cfd213bc8 [file] [log] [blame]
Guido van Rossum9966e2c2001-06-22 16:05:48 +00001#! /usr/bin/env python
2
3"""Python utility to print MD5 checksums of argument files.
4
5Works with Python 1.5.2 and later.
6"""
7
8import sys, md5
9
10BLOCKSIZE = 1024*1024
11
12def hexify(s):
13 return ("%02x"*len(s)) % tuple(map(ord, s))
14
15def main():
16 args = sys.argv[1:]
17 if not args:
18 sys.stderr.write("usage: %s file ...\n" % sys.argv[0])
19 sys.exit(2)
20 for file in sys.argv[1:]:
21 f = open(file, "rb")
22 sum = md5.new()
23 while 1:
24 block = f.read(BLOCKSIZE)
25 if not block:
26 break
27 sum.update(block)
28 f.close()
29 print hexify(sum.digest()), file
30
31if __name__ == "__main__":
32 main()