livemedia-creator: Clean up resultdir handling (#1290552)

(cherry picked from commit 3148a2b215)

Resolves: rhbz#1290552
This commit is contained in:
Brian C. Lane 2015-03-19 17:22:16 -07:00
parent f9dfc02fbf
commit 5da9f5c179

View File

@ -790,7 +790,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)
@ -821,7 +821,7 @@ def virt_install(opts, install_log, disk_img, disk_size):
mkqcow2(disk_img, disk_size*1024**3, 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
@ -886,9 +886,9 @@ def make_image(opts, ks):
log.info("disk_size = %sGB", 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:
@ -1142,6 +1142,12 @@ if __name__ == '__main__':
"move its contents".format( opts.result_dir ))
sys.exit( 1 )
# 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 ):
log.error( "The iso {0} is missing.".format( opts.iso ) )
sys.exit( 1 )
@ -1186,7 +1192,7 @@ if __name__ == '__main__':
"exist".format(opts.app_template))
sys.exit(1)
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)):
log.error("The disk image to be created should not exist.")
sys.exit(1)
@ -1212,7 +1218,7 @@ if __name__ == '__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
@ -1329,7 +1335,7 @@ if __name__ == '__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 )
@ -1340,8 +1346,7 @@ if __name__ == '__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 )