livemedia-creator: Clean up resultdir handling

This commit is contained in:
Brian C. Lane 2015-03-19 17:22:16 -07:00
parent fc1316e767
commit 3148a2b215
1 changed files with 14 additions and 9 deletions

View File

@ -900,7 +900,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:
@ -946,7 +946,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
@ -1031,9 +1031,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:
@ -1308,6 +1308,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)
@ -1343,7 +1349,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"):
@ -1379,7 +1385,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
@ -1491,7 +1497,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)
@ -1502,8 +1508,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 )