Refs #8: added better error message when attempting to load unknown template

This commit is contained in:
Rob McMullen 2018-03-09 11:06:30 -08:00
parent 4185ca5617
commit 55b368414e
1 changed files with 7 additions and 2 deletions

View File

@ -326,7 +326,7 @@ def get_template_data(template):
with open(path, "rb") as fh:
data = fh.read()
except:
raise InvalidDiskImage("Template disk image %s not found" % template)
raise InvalidDiskImage("Unknown template disk image %s" % template)
try:
with open(path + ".inf", "r") as fh:
s = fh.read()
@ -339,7 +339,12 @@ def get_template_data(template):
def create_image(template, name):
import textwrap
data, inf = get_template_data(template)
try:
data, inf = get_template_data(template)
except InvalidDiskImage, e:
info = get_template_info()
print("Error: %s\n\n%s" % (e, info))
return
print("using %s template:\n %s" % (template, "\n ".join(textwrap.wrap(inf["description"], 77))))
if not options.dry_run:
if os.path.exists(name) and not options.force: