diff options
author | Abhishek Kulkarni <adkulkar@indiana.edu> | 2016-01-29 00:32:34 -0500 |
---|---|---|
committer | Abhishek Kulkarni <adkulkar@indiana.edu> | 2016-01-29 00:32:34 -0500 |
commit | 5907cc0de5d60b0266a04299cc560bead8edd05c (patch) | |
tree | 9ae0d8360af34efe7c65bee9f293384d6f2302d7 /lib | |
parent | 2bea7f8d69064f893a21cfc53f3d781b572e2f79 (diff) | |
parent | 9fb5ddbb4c4b2dc90027deb24ec4721018ebd3ae (diff) | |
download | spack-5907cc0de5d60b0266a04299cc560bead8edd05c.tar.gz spack-5907cc0de5d60b0266a04299cc560bead8edd05c.tar.bz2 spack-5907cc0de5d60b0266a04299cc560bead8edd05c.tar.xz spack-5907cc0de5d60b0266a04299cc560bead8edd05c.zip |
Merge remote-tracking branch 'upstream/develop' into develop
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/cmd/md5.py | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/lib/spack/spack/cmd/md5.py b/lib/spack/spack/cmd/md5.py index ef1e4f3475..879ef9f7b7 100644 --- a/lib/spack/spack/cmd/md5.py +++ b/lib/spack/spack/cmd/md5.py @@ -23,15 +23,31 @@ # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ############################################################################## import os -import hashlib import argparse +import hashlib + +from contextlib import contextmanager import llnl.util.tty as tty from llnl.util.filesystem import * import spack.util.crypto +from spack.stage import Stage, FailedDownloadError + +description = "Calculate md5 checksums for files/urls." -description = "Calculate md5 checksums for files." +@contextmanager +def stager(url): + _cwd = os.getcwd() + _stager = Stage(url) + try: + _stager.fetch() + yield _stager + except FailedDownloadError: + tty.msg("Failed to fetch %s" % url) + finally: + _stager.destroy() + os.chdir(_cwd) # the Stage class changes the current working dir so it has to be restored def setup_parser(subparser): setup_parser.parser = subparser @@ -45,9 +61,12 @@ def md5(parser, args): for f in args.files: if not os.path.isfile(f): - tty.die("Not a file: %s" % f) - if not can_access(f): - tty.die("Cannot read file: %s" % f) + with stager(f) as stage: + checksum = spack.util.crypto.checksum(hashlib.md5, stage.archive_file) + print "%s %s" % (checksum, f) + else: + if not can_access(f): + tty.die("Cannot read file: %s" % f) - checksum = spack.util.crypto.checksum(hashlib.md5, f) - print "%s %s" % (checksum, f) + checksum = spack.util.crypto.checksum(hashlib.md5, f) + print "%s %s" % (checksum, f) |