From d260dcf04855146920308a28779413fbbb140e8e Mon Sep 17 00:00:00 2001 From: Zhang Qiang Date: Wed, 26 Oct 2011 11:09:47 +0800 Subject: [PATCH] Give prompt info if target image file exist. --- mic/imager/baseimager.py | 2 +- plugins/imager/livecd_plugin.py | 12 ++++++++++++ plugins/imager/liveusb_plugin.py | 12 ++++++++++++ plugins/imager/loop_plugin.py | 9 +++++++++ plugins/imager/raw_plugin.py | 9 +++++++++ 5 files changed, 43 insertions(+), 1 deletion(-) diff --git a/mic/imager/baseimager.py b/mic/imager/baseimager.py index 0a6c1ea..55fd011 100644 --- a/mic/imager/baseimager.py +++ b/mic/imager/baseimager.py @@ -1090,7 +1090,7 @@ class BaseImageCreator(object): if f.endswith(".iso"): newf = f[:-4] + '.img' elif f.endswith(".usbimg"): - newf = f[:-6] + '.img' + newf = f[:-7] + '.img' else: continue os.rename(_rpath(f), _rpath(newf)) diff --git a/plugins/imager/livecd_plugin.py b/plugins/imager/livecd_plugin.py index 831b4c2..9b67cf5 100644 --- a/plugins/imager/livecd_plugin.py +++ b/plugins/imager/livecd_plugin.py @@ -79,6 +79,18 @@ class LiveCDPlugin(ImagerPlugin): if len(recording_pkgs) > 0: creator._recording_pkgs = recording_pkgs + destdir = os.path.abspath(os.path.expanduser(creatoropts["outdir"])) + if creatoropts['release'] is not None: + imagefile = "%s.img" % os.path.join(destdir, creator.name) + else: + imagefile = "%s.iso" % os.path.join(destdir, creator.name) + + if not os.path.exists(destdir): + os.makedirs(destdir) + elif os.path.exists(imagefile): + if msger.ask('The target image: %s already exists, need to delete it?' % imagefile): + os.unlink(imagefile) + try: creator.check_depend_tools() creator.mount(None, creatoropts["cachedir"]) diff --git a/plugins/imager/liveusb_plugin.py b/plugins/imager/liveusb_plugin.py index 27e8100..a8da871 100644 --- a/plugins/imager/liveusb_plugin.py +++ b/plugins/imager/liveusb_plugin.py @@ -81,6 +81,18 @@ class LiveUSBPlugin(ImagerPlugin): if len(recording_pkgs) > 0: creator._recording_pkgs = recording_pkgs + destdir = os.path.abspath(os.path.expanduser(creatoropts["outdir"])) + if creatoropts['release'] is not None: + imagefile = "%s.img" % os.path.join(destdir, creator.name) + else: + imagefile = "%s.usbimg" % os.path.join(destdir, creator.name) + + if not os.path.exists(destdir): + os.makedirs(destdir) + elif os.path.exists(imagefile): + if msger.ask('The target image: %s already exists, need to delete it?' % imagefile): + os.unlink(imagefile) + try: creator.check_depend_tools() creator.mount(None, creatoropts["cachedir"]) diff --git a/plugins/imager/loop_plugin.py b/plugins/imager/loop_plugin.py index 21ceeee..81d9ce8 100644 --- a/plugins/imager/loop_plugin.py +++ b/plugins/imager/loop_plugin.py @@ -76,6 +76,15 @@ class LoopPlugin(ImagerPlugin): if len(recording_pkgs) > 0: creator._recording_pkgs = recording_pkgs + destdir = os.path.abspath(os.path.expanduser(creatoropts["outdir"])) + imagefile = "%s.img" % os.path.join(destdir, creator.name) + + if not os.path.exists(destdir): + os.makedirs(destdir) + elif os.path.exists(imagefile): + if msger.ask('The target image: %s already exists, need to delete it?' % imagefile): + os.unlink(imagefile) + try: creator.check_depend_tools() creator.mount(None, creatoropts["cachedir"]) diff --git a/plugins/imager/raw_plugin.py b/plugins/imager/raw_plugin.py index 1854a8d..0e9a3fc 100644 --- a/plugins/imager/raw_plugin.py +++ b/plugins/imager/raw_plugin.py @@ -78,6 +78,15 @@ class RawPlugin(ImagerPlugin): if len(recording_pkgs) > 0: creator._recording_pkgs = recording_pkgs + destdir = os.path.abspath(os.path.expanduser(creatoropts["outdir"])) + imagefile = "%s-sda.raw" % os.path.join(destdir, creator.name) + + if not os.path.exists(destdir): + os.makedirs(destdir) + elif os.path.exists(imagefile): + if msger.ask('The target image: %s already exists, need to delete it?' % imagefile): + os.unlink(imagefile) + try: creator.check_depend_tools() creator.mount(None, creatoropts["cachedir"]) -- 2.7.4