annotate Tools/scripts/md5sum.py @ 25838:8540887bcec6 2.2

Backport of 2.183: Fix memory leak in add_subclass() found by NealN with valgrind.
author Guido van Rossum <guido@python.org>
date Fri, 18 Oct 2002 13:42:21 +0000
parents 368e8081e73c
children a5e99e7e7ff0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18218
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 #! /usr/bin/env python
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
2
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 """Python utility to print MD5 checksums of argument files.
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
4
23126
368e8081e73c backport akuchling's patch:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 18218
diff changeset
5 Works with Python 2.1 and later.
18218
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 """
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
7
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 import sys, md5
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
9
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 BLOCKSIZE = 1024*1024
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
11
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 def main():
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 args = sys.argv[1:]
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 if not args:
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 sys.stderr.write("usage: %s file ...\n" % sys.argv[0])
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 sys.exit(2)
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 for file in sys.argv[1:]:
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 f = open(file, "rb")
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 sum = md5.new()
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 while 1:
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 block = f.read(BLOCKSIZE)
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 if not block:
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 break
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 sum.update(block)
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 f.close()
23126
368e8081e73c backport akuchling's patch:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 18218
diff changeset
26 print sum.hexdigest(), file
18218
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
27
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 if __name__ == "__main__":
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 main()