Give prompt info if target image file exist.
authorZhang Qiang <qiang.z.zhang@intel.com>
Wed, 26 Oct 2011 03:09:47 +0000 (11:09 +0800)
committerZhang Qiang <qiang.z.zhang@intel.com>
Wed, 26 Oct 2011 03:09:47 +0000 (11:09 +0800)
mic/imager/baseimager.py
plugins/imager/livecd_plugin.py
plugins/imager/liveusb_plugin.py
plugins/imager/loop_plugin.py
plugins/imager/raw_plugin.py

index 0a6c1ea..55fd011 100644 (file)
@@ -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))
index 831b4c2..9b67cf5 100644 (file)
@@ -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"])
index 27e8100..a8da871 100644 (file)
@@ -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"])
index 21ceeee..81d9ce8 100644 (file)
@@ -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"])
index 1854a8d..0e9a3fc 100644 (file)
@@ -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"])