[Python-checkins] CVS: python/dist/src/Tools/scripts md5sum.py,NONE,1.1
Guido van Rossum
gvanrossum@users.sourceforge.net
Fri, 22 Jun 2001 09:05:50 -0700
Update of /cvsroot/python/python/dist/src/Tools/scripts
In directory usw-pr-cvs1:/tmp/cvs-serv6511
Added Files:
md5sum.py
Log Message:
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.
--- NEW FILE: md5sum.py ---
#! /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()