diff options
author | Nicolas Richart <nicolas.richart@epfl.ch> | 2016-01-28 14:43:30 +0100 |
---|---|---|
committer | Nicolas Richart <nicolas.richart@epfl.ch> | 2016-01-28 14:43:30 +0100 |
commit | 824546d343917fb24c1b94af0eeaea79371efb46 (patch) | |
tree | 212144e614de588d1515a4bd71c57cc65164c733 /lib | |
parent | 5850d8530ef0570e508fb1ebd53428e98cc761a3 (diff) | |
download | spack-824546d343917fb24c1b94af0eeaea79371efb46.tar.gz spack-824546d343917fb24c1b94af0eeaea79371efb46.tar.bz2 spack-824546d343917fb24c1b94af0eeaea79371efb46.tar.xz spack-824546d343917fb24c1b94af0eeaea79371efb46.zip |
correcting a bug when url and files are mixed
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/cmd/md5.py | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/lib/spack/spack/cmd/md5.py b/lib/spack/spack/cmd/md5.py index b8ffb5dec7..879ef9f7b7 100644 --- a/lib/spack/spack/cmd/md5.py +++ b/lib/spack/spack/cmd/md5.py @@ -23,8 +23,10 @@ # 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 * @@ -34,6 +36,19 @@ from spack.stage import Stage, FailedDownloadError description = "Calculate md5 checksums for files/urls." +@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 subparser.add_argument('files', nargs=argparse.REMAINDER, @@ -46,17 +61,9 @@ def md5(parser, args): for f in args.files: if not os.path.isfile(f): - stage = Stage(f) - try: - stage.fetch() + with stager(f) as stage: checksum = spack.util.crypto.checksum(hashlib.md5, stage.archive_file) print "%s %s" % (checksum, f) - except FailedDownloadError, e: - tty.msg("Failed to fetch %s" % url) - continue - - finally: - stage.destroy() else: if not can_access(f): tty.die("Cannot read file: %s" % f) |