Checksum warning now prompts for override.

This commit is contained in:
Todd Gamblin 2014-11-08 23:20:01 -08:00
parent 79414947ae
commit eba13b8653
2 changed files with 35 additions and 5 deletions

View File

@ -114,6 +114,33 @@ def get_number(prompt, **kwargs):
return number
def get_yes_or_no(prompt, **kwargs):
default_value = kwargs.get('default', None)
if default_value is None:
prompt += ' [y/n] '
elif default_value is True:
prompt += ' [Y/n] '
elif default_value is False:
prompt += ' [y/N] '
else:
raise ValueError("default for get_yes_no() must be True, False, or None.")
result = None
while result is None:
ans = raw_input(prompt).lower()
if not ans:
result = default_value
if result is None:
print "Please enter yes or no."
else:
if ans == 'y' or ans == 'yes':
result = True
elif ans == 'n' or ans == 'no':
result = False
return result
def hline(label=None, **kwargs):
"""Draw an optionally colored or labeled horizontal line.
Options:

View File

@ -613,11 +613,14 @@ def do_fetch(self):
raise ValueError("Can only fetch concrete packages.")
if spack.do_checksum and not self.version in self.versions:
raise FetchError(
"Cannot fetch %s safely; there is no checksum on file for version %s."
% (self.name, self.version),
"Add a checksum to the package file, or use --no-checksum to "
"skip this check.")
tty.warn("There is no checksum on file to fetch %s safely."
% self.spec.format('$_$@'))
ignore = tty.get_yes_or_no(" Fetch anyway?", default=False)
msg = "Add a checksum or use --no-checksum to skip this check."
if ignore:
tty.msg("Fetching with no checksum.", msg)
else:
raise FetchError("Will not fetch %s." % self.spec.format('$_$@'), msg)
self.stage.fetch()