diff options
author | Guido van Rossum <guido@python.org> | 2001-06-22 16:05:48 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2001-06-22 16:05:48 (GMT) |
commit | 9966e2c6631143445d4faa34fb245524fe95b4b7 (patch) | |
tree | 37d0724601e0b28447fa698f40bacb433b4dea8e /Tools/scripts | |
parent | 93438bf0a24ca1de4f1707a45be28e9621739184 (diff) | |
download | cpython-9966e2c6631143445d4faa34fb245524fe95b4b7.zip cpython-9966e2c6631143445d4faa34fb245524fe95b4b7.tar.gz cpython-9966e2c6631143445d4faa34fb245524fe95b4b7.tar.bz2 |
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.
Diffstat (limited to 'Tools/scripts')
-rw-r--r-- | Tools/scripts/md5sum.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/Tools/scripts/md5sum.py b/Tools/scripts/md5sum.py new file mode 100644 index 0000000..ac2eac0 --- /dev/null +++ b/Tools/scripts/md5sum.py @@ -0,0 +1,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() |