From 5da9f5c179fcf45c1ea3e9e577d87cd2e369eb57 Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Thu, 19 Mar 2015 17:22:16 -0700 Subject: [PATCH] livemedia-creator: Clean up resultdir handling (#1290552) (cherry picked from commit 3148a2b2157a19ceb55e1884b0ca878e6e0ec3b6) Resolves: rhbz#1290552 --- src/sbin/livemedia-creator | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/sbin/livemedia-creator b/src/sbin/livemedia-creator index 4e1b5a6a..a12cb48c 100755 --- a/src/sbin/livemedia-creator +++ b/src/sbin/livemedia-creator @@ -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 )