summaryrefslogtreecommitdiffstats
path: root/Tools/scripts/md5sum.py
blob: ac2eac0cb6821ad66f3c162078e46c5cfd213bc8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#! /usr/bin/env python

"""Python utility to print MD5 checksums of argument files.

Works with Python 1.5.2 and later.
"""

import sys, md5

BLOCKSIZE = 1024*1024

def hexify(s):
    return ("%02x"*len(s)) % tuple(map(ord, s))

def main():
    args = sys.argv[1:]
    if not args:
        sys.stderr.write("usage: %s file ...\n" % sys.argv[0])
        sys.exit(2)
    for file in sys.argv[1:]:
        f = open(file, "rb")
        sum = md5.new()
        while 1:
            block = f.read(BLOCKSIZE)
            if not block:
                break
            sum.update(block)
        f.close()
        print hexify(sum.digest()), file

if __name__ == "__main__":
    main()