correcting a bug when url and files are mixed
This commit is contained in:
parent
5850d8530e
commit
824546d343
@ -23,8 +23,10 @@
|
|||||||
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
##############################################################################
|
##############################################################################
|
||||||
import os
|
import os
|
||||||
import hashlib
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import hashlib
|
||||||
|
|
||||||
|
from contextlib import contextmanager
|
||||||
|
|
||||||
import llnl.util.tty as tty
|
import llnl.util.tty as tty
|
||||||
from llnl.util.filesystem import *
|
from llnl.util.filesystem import *
|
||||||
@ -34,6 +36,19 @@
|
|||||||
|
|
||||||
description = "Calculate md5 checksums for files/urls."
|
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):
|
def setup_parser(subparser):
|
||||||
setup_parser.parser = subparser
|
setup_parser.parser = subparser
|
||||||
subparser.add_argument('files', nargs=argparse.REMAINDER,
|
subparser.add_argument('files', nargs=argparse.REMAINDER,
|
||||||
@ -46,17 +61,9 @@ def md5(parser, args):
|
|||||||
|
|
||||||
for f in args.files:
|
for f in args.files:
|
||||||
if not os.path.isfile(f):
|
if not os.path.isfile(f):
|
||||||
stage = Stage(f)
|
with stager(f) as stage:
|
||||||
try:
|
|
||||||
stage.fetch()
|
|
||||||
checksum = spack.util.crypto.checksum(hashlib.md5, stage.archive_file)
|
checksum = spack.util.crypto.checksum(hashlib.md5, stage.archive_file)
|
||||||
print "%s %s" % (checksum, f)
|
print "%s %s" % (checksum, f)
|
||||||
except FailedDownloadError, e:
|
|
||||||
tty.msg("Failed to fetch %s" % url)
|
|
||||||
continue
|
|
||||||
|
|
||||||
finally:
|
|
||||||
stage.destroy()
|
|
||||||
else:
|
else:
|
||||||
if not can_access(f):
|
if not can_access(f):
|
||||||
tty.die("Cannot read file: %s" % f)
|
tty.die("Cannot read file: %s" % f)
|
||||||
|
Loading…
Reference in New Issue
Block a user