Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9966e2c

Browse files
committed
This is a trivial command line utility to print MD5 checksums.
I published it on the web as http://www.python.org/2.1/md5sum.py so I thought I might as well check it in. Works with Python 1.5.2 and later. Works like the Linux tool ``mdfsum file ...'' except it doesn't take any options or read stdin.
1 parent 93438bf commit 9966e2c

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

Tools/scripts/md5sum.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#! /usr/bin/env python
2+
3+
"""Python utility to print MD5 checksums of argument files.
4+
5+
Works with Python 1.5.2 and later.
6+
"""
7+
8+
import sys, md5
9+
10+
BLOCKSIZE = 1024*1024
11+
12+
def hexify(s):
13+
return ("%02x"*len(s)) % tuple(map(ord, s))
14+
15+
def 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+
31+
if __name__ == "__main__":
32+
main()

0 commit comments

Comments
 (0)