livemedia-creator: Clean up resultdir handling

(cherry picked from commit 3148a2b215)
This commit is contained in:
Brian C. Lane 2015-03-19 17:22:16 -07:00
parent 5155ff65ac
commit 229759f411

View File

@ -882,7 +882,7 @@ def novirt_install(opts, disk_img, disk_size, repo_url):
# convert the image to qcow2 format
if "-O" not in qcow2_args:
qcow2_args.extend(["-O", "qcow2"])
qcow2_img = tempfile.mktemp(prefix="disk", suffix=".img", dir=opts.tmp)
qcow2_img = tempfile.mktemp(prefix="disk", suffix=".img")
execWithRedirect("qemu-img", ["convert"] + qcow2_args + [disk_img, qcow2_img], raise_err=True)
execWithRedirect("mv", ["-f", qcow2_img, disk_img], raise_err=True)
elif opts.make_tar:
@ -928,7 +928,7 @@ def virt_install(opts, install_log, disk_img, disk_size):
mkqcow2(disk_img, disk_size*1024**2, qcow2_args)
if opts.make_fsimage or opts.make_tar:
diskimg_path = tempfile.mktemp(prefix="disk", suffix=".img", dir=opts.tmp)
diskimg_path = tempfile.mktemp(prefix="disk", suffix=".img")
else:
diskimg_path = disk_img
@ -1013,9 +1013,9 @@ def make_image(opts, ks):
log.info("disk_size = %sMiB", disk_size)
if opts.image_name:
disk_img = joinpaths(opts.tmp, opts.image_name)
disk_img = joinpaths(opts.result_dir, opts.image_name)
else:
disk_img = tempfile.mktemp(prefix="disk", suffix=".img", dir=opts.tmp)
disk_img = tempfile.mktemp(prefix="disk", suffix=".img", dir=opts.result_dir)
log.info("disk_img = %s", disk_img)
try:
@ -1290,6 +1290,12 @@ def main():
errors.append("The results_dir (%s) should not exist, please delete or "
"move its contents" % opts.result_dir)
# Default to putting results into tmp
if not opts.result_dir:
opts.result_dir = opts.tmp
else:
os.makedirs(opts.result_dir)
if opts.iso and not os.path.exists(opts.iso):
errors.append("The iso %s is missing." % opts.iso)
@ -1325,7 +1331,7 @@ def main():
errors.append("The appliance template (%s) doesn't "
"exist" % opts.app_template)
if opts.image_name and os.path.exists(joinpaths(opts.tmp, opts.image_name)):
if opts.image_name and os.path.exists(joinpaths(opts.result_dir, opts.image_name)):
errors.append("The disk image to be created should not exist.")
if opts.qcow2 and not os.path.exists("/usr/bin/qemu-img"):
@ -1361,7 +1367,7 @@ def main():
opts.compress_args = ["-9"]
if opts.app_file:
opts.app_file = joinpaths(opts.tmp, opts.app_file)
opts.app_file = joinpaths(opts.result_dir, opts.app_file)
if opts.make_ostree_live:
opts.make_pxe_live = True
@ -1473,7 +1479,7 @@ def main():
if mounted_sysroot_boot_dir:
umount(mounted_sysroot_boot_dir)
if opts.result_dir and result_dir:
if opts.result_dir != opts.tmp and result_dir:
shutil.copytree(result_dir, opts.result_dir)
shutil.rmtree(result_dir)
@ -1484,8 +1490,7 @@ def main():
log.info("Disk image is at {0}".format(disk_img))
if opts.make_appliance:
log.info("Appliance description is in {0}".format(opts.app_file))
if result_dir:
log.info("Results are in {0}".format(opts.result_dir or result_dir))
log.info("Results are in {0}".format(opts.result_dir))
sys.exit( 0 )