spack checksum works.
This commit is contained in:
parent
db32769347
commit
2f1eae8c0d
@ -7,12 +7,13 @@
|
|||||||
|
|
||||||
import spack.tty as tty
|
import spack.tty as tty
|
||||||
import spack.packages as packages
|
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.colify import colify
|
||||||
from spack.util.crypto import checksum
|
|
||||||
from spack.version import *
|
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."
|
description ="Checksum available versions of a package, print out checksums for addition to a package file."
|
||||||
|
|
||||||
def setup_parser(subparser):
|
def setup_parser(subparser):
|
||||||
@ -20,9 +21,6 @@ def setup_parser(subparser):
|
|||||||
'package', metavar='PACKAGE', help='Package to list versions for')
|
'package', metavar='PACKAGE', help='Package to list versions for')
|
||||||
subparser.add_argument(
|
subparser.add_argument(
|
||||||
'versions', nargs=argparse.REMAINDER, help='Versions to generate checksums for')
|
'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):
|
def checksum(parser, args):
|
||||||
@ -30,7 +28,6 @@ def checksum(parser, args):
|
|||||||
pkg = packages.get(args.package)
|
pkg = packages.get(args.package)
|
||||||
|
|
||||||
# If the user asked for specific versions, use those.
|
# 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]
|
versions = [ver(v) for v in args.versions]
|
||||||
|
|
||||||
if not all(type(v) == Version for v in versions):
|
if not all(type(v) == Version for v in versions):
|
||||||
@ -38,23 +35,48 @@ def checksum(parser, args):
|
|||||||
"version ranges. Use unambiguous versions.")
|
"version ranges. Use unambiguous versions.")
|
||||||
|
|
||||||
if not versions:
|
if not versions:
|
||||||
versions = pkg.fetch_available_versions()[:args.number]
|
versions = pkg.fetch_available_versions()
|
||||||
if not versions:
|
if not versions:
|
||||||
tty.die("Could not fetch any available versions for %s." % pkg.name)
|
tty.die("Could not fetch any available versions for %s." % pkg.name)
|
||||||
|
|
||||||
versions.sort()
|
versions = list(reversed(versions))
|
||||||
versions.reverse()
|
|
||||||
urls = [pkg.url_for_version(v) for v in versions]
|
urls = [pkg.url_for_version(v) for v in versions]
|
||||||
|
|
||||||
tty.msg("Found %s versions to checksum." % len(urls))
|
version_listings = ["%-10s%s" % (v,u) for v, u in zip(versions, urls)]
|
||||||
tty.msg("Downloading...")
|
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 = []
|
hashes = []
|
||||||
for url, version in zip(urls, versions):
|
for url, version in zip(urls, versions):
|
||||||
stage = Stage(url)
|
stage = Stage(url)
|
||||||
try:
|
try:
|
||||||
stage.fetch()
|
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:
|
finally:
|
||||||
stage.destroy()
|
stage.destroy()
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import spack.tty as tty
|
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)]
|
quoted_args = [arg for arg in args if re.search(r'^"|^\'|"$|\'$', arg)]
|
||||||
if quoted_args:
|
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:",
|
"The following arguments may cause problems when executed:",
|
||||||
str("\n".join([" "+arg for arg in quoted_args])),
|
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)
|
cmd = self.exe + list(args)
|
||||||
tty.verbose(" ".join(cmd))
|
tty.verbose(" ".join(cmd))
|
||||||
|
|
||||||
if return_output:
|
try:
|
||||||
return subprocess.check_output(cmd)
|
proc = subprocess.Popen(
|
||||||
elif fail_on_error:
|
cmd,
|
||||||
return subprocess.check_call(cmd)
|
stderr=sys.stderr,
|
||||||
else:
|
stdout=subprocess.PIPE if return_output else sys.stdout)
|
||||||
return subprocess.call(cmd)
|
out, err = proc.communicate()
|
||||||
|
if return_output:
|
||||||
|
return out
|
||||||
|
|
||||||
|
except CalledProcessError, e:
|
||||||
|
if fail_on_error: raise
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<exe: %s>" % self.exe
|
return "<exe: %s>" % self.exe
|
||||||
|
@ -144,8 +144,7 @@ def a_or_n(seg):
|
|||||||
|
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
for v in self.version:
|
return iter(self.version)
|
||||||
yield v
|
|
||||||
|
|
||||||
|
|
||||||
def __getitem__(self, idx):
|
def __getitem__(self, idx):
|
||||||
@ -486,8 +485,11 @@ def __getitem__(self, index):
|
|||||||
|
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
for v in self.versions:
|
return iter(self.versions)
|
||||||
yield v
|
|
||||||
|
|
||||||
|
def __reversed__(self):
|
||||||
|
return reversed(self.versions)
|
||||||
|
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user