diff options
author | Srinivas Reddy Thatiparthy <thatiparthysreenivas@gmail.com> | 2017-08-25 14:03:20 +0530 |
---|---|---|
committer | Srinivas Reddy Thatiparthy <thatiparthysreenivas@gmail.com> | 2017-08-25 17:30:04 +0530 |
commit | d6282a92239c55a2ba486668a834db9a735be2c7 (patch) | |
tree | 1606bf1100c620f7745ff556828aedc9057f74b3 | |
parent | 67f27be82600e31472927fa30dd71de5320d9a45 (diff) | |
download | python-numpy-d6282a92239c55a2ba486668a834db9a735be2c7.tar.gz python-numpy-d6282a92239c55a2ba486668a834db9a735be2c7.tar.bz2 python-numpy-d6282a92239c55a2ba486668a834db9a735be2c7.zip |
MAINT: Reuse the code to compute sha256, md5 hashes
-rw-r--r-- | pavement.py | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/pavement.py b/pavement.py index 81d6b25a4..780993a38 100644 --- a/pavement.py +++ b/pavement.py @@ -65,11 +65,7 @@ import sys import shutil import subprocess import re -try: - from hashlib import md5 - from hashlib import sha256 -except ImportError: - from md5 import md5 +import hashlib import paver from paver.easy import \ @@ -562,25 +558,22 @@ def sdist(options): target = os.path.join(idirs, tarball_name(t)) shutil.copy(source, target) -def compute_md5(idirs): +def _compute_hash(idirs, algo): released = paver.path.path(idirs).listdir() checksums = [] for f in sorted(released): - m = md5(open(f, 'r').read()) - checksums.append('%s %s' % (m.hexdigest(), os.path.basename(f))) - + with open(f, 'r') as _file: + m = algo(_file.read()) + checksums.append('%s %s' % (m.hexdigest(), os.path.basename(f))) return checksums +def compute_md5(idirs): + return _compute_hash(idirs, hashlib.md5) + def compute_sha256(idirs): # better checksum so gpg signed README.txt containing the sums can be used # to verify the binaries instead of signing all binaries - released = paver.path.path(idirs).listdir() - checksums = [] - for f in sorted(released): - m = sha256(open(f, 'r').read()) - checksums.append('%s %s' % (m.hexdigest(), os.path.basename(f))) - - return checksums + return _compute_hash(idirs, hashlib.sha256) def write_release_task(options, filename='README'): idirs = options.installers.installersdir |