spack checksum works.

This commit is contained in:
Todd Gamblin 2013-12-23 16:12:02 -08:00
parent db32769347
commit 2f1eae8c0d
3 changed files with 56 additions and 25 deletions

View file

@ -7,12 +7,13 @@
import spack.tty as tty
import spack.packages as packages
from spack.stage import Stage
import spack.util.crypto
from spack.stage import Stage, FailedDownloadError
from spack.colify import colify
from spack.util.crypto import checksum
from spack.version import *
group='foo'
default_number_to_fetch = 10
description ="Checksum available versions of a package, print out checksums for addition to a package file."
def setup_parser(subparser):
@ -20,9 +21,6 @@ def setup_parser(subparser):
'package', metavar='PACKAGE', help='Package to list versions for')
subparser.add_argument(
'versions', nargs=argparse.REMAINDER, help='Versions to generate checksums for')
subparser.add_argument(
'-n', '--number', dest='number', type=int,
default=10, help='Number of versions to list')
def checksum(parser, args):
@ -30,7 +28,6 @@ def checksum(parser, args):
pkg = packages.get(args.package)
# If the user asked for specific versions, use those.
# Otherwise get the latest n, where n is from the -n/--number param
versions = [ver(v) for v in args.versions]
if not all(type(v) == Version for v in versions):
@ -38,23 +35,48 @@ def checksum(parser, args):
"version ranges. Use unambiguous versions.")
if not versions:
versions = pkg.fetch_available_versions()[:args.number]
versions = pkg.fetch_available_versions()
if not versions:
tty.die("Could not fetch any available versions for %s." % pkg.name)
versions.sort()
versions.reverse()
versions = list(reversed(versions))
urls = [pkg.url_for_version(v) for v in versions]
tty.msg("Found %s versions to checksum." % len(urls))
tty.msg("Downloading...")
version_listings = ["%-10s%s" % (v,u) for v, u in zip(versions, urls)]
tty.msg("Found %s versions to checksum." % len(urls),
*version_listings)
print
while True:
ans = raw_input("How many would you like to checksum? (default 10, 0 to abort) ")
try:
if not ans:
to_download = default_number_to_fetch
else:
to_download = int(ans)
break
except ValueError:
tty.msg("Please enter a valid number.")
pass
if not to_download:
tty.msg("Aborted.")
return
else:
urls = urls[:to_download]
tty.msg("Downloading...")
hashes = []
for url, version in zip(urls, versions):
stage = Stage(url)
try:
stage.fetch()
hashes.append(checksum(hashlib.md5, stage.archive_file))
hashes.append(spack.util.crypto.checksum(
hashlib.md5, stage.archive_file))
except FailedDownloadError, e:
tty.msg("Failed to fetch %s" % url)
continue
finally:
stage.destroy()

View file

@ -1,4 +1,5 @@
import os
import sys
import re
import subprocess
import spack.tty as tty
@ -26,20 +27,26 @@ def __call__(self, *args, **kwargs):
quoted_args = [arg for arg in args if re.search(r'^"|^\'|"$|\'$', arg)]
if quoted_args:
tty.warn("Quotes in package command arguments can confuse shell scripts like configure.",
tty.warn("Quotes in command arguments can confuse scripts like configure.",
"The following arguments may cause problems when executed:",
str("\n".join([" "+arg for arg in quoted_args])),
"Quotes aren't needed because spack doesn't use a shell. Consider removing them")
"Quotes aren't needed because spack doesn't use a shell.",
"Consider removing them")
cmd = self.exe + list(args)
tty.verbose(" ".join(cmd))
if return_output:
return subprocess.check_output(cmd)
elif fail_on_error:
return subprocess.check_call(cmd)
else:
return subprocess.call(cmd)
try:
proc = subprocess.Popen(
cmd,
stderr=sys.stderr,
stdout=subprocess.PIPE if return_output else sys.stdout)
out, err = proc.communicate()
if return_output:
return out
except CalledProcessError, e:
if fail_on_error: raise
def __repr__(self):
return "<exe: %s>" % self.exe

View file

@ -144,8 +144,7 @@ def a_or_n(seg):
def __iter__(self):
for v in self.version:
yield v
return iter(self.version)
def __getitem__(self, idx):
@ -486,8 +485,11 @@ def __getitem__(self, index):
def __iter__(self):
for v in self.versions:
yield v
return iter(self.versions)
def __reversed__(self):
return reversed(self.versions)
def __len__(self):