summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorGui Chen <gui.chen@intel.com>2012-06-06 11:41:11 +0800
committerJF Ding <jian-feng.ding@intel.com>2012-06-06 14:48:30 +0800
commit732c139fd467c489ed6a0b718799d0432c9b029a (patch)
treea9cd1a3f6ce15bf850d2f72d80446d46726ea952 /plugins
parent99c4bda93815856c1c2c1c356b8099965374c31b (diff)
downloadmic-732c139fd467c489ed6a0b718799d0432c9b029a.tar.gz
mic-732c139fd467c489ed6a0b718799d0432c9b029a.tar.bz2
mic-732c139fd467c489ed6a0b718799d0432c9b029a.zip
centralized interface to check existing images
new api: ImagerPlugin::check_image_exists this change will fix a bug for --pack-to handling Signed-off-by: Gui Chen <gui.chen@intel.com>
Diffstat (limited to 'plugins')
-rw-r--r--plugins/imager/fs_plugin.py12
-rw-r--r--plugins/imager/livecd_plugin.py11
-rw-r--r--plugins/imager/liveusb_plugin.py12
-rw-r--r--plugins/imager/loop_plugin.py16
-rw-r--r--plugins/imager/raw_plugin.py14
5 files changed, 22 insertions, 43 deletions
diff --git a/plugins/imager/fs_plugin.py b/plugins/imager/fs_plugin.py
index 59c610e..aceb653 100644
--- a/plugins/imager/fs_plugin.py
+++ b/plugins/imager/fs_plugin.py
@@ -90,14 +90,10 @@ class FsPlugin(ImagerPlugin):
if len(recording_pkgs) > 0:
creator._recording_pkgs = recording_pkgs
- if creatoropts['release'] is None:
- fsdir = os.path.join(creator.destdir, creator.name)
- if os.path.exists(fsdir):
- if msger.ask('The target dir: %s already exists, cleanup and continue?' % fsdir):
- import shutil
- shutil.rmtree(fsdir)
- else:
- raise errors.Abort('Canceled')
+ self.check_image_exists(creator.destdir,
+ creator.pack_to,
+ [creator.name],
+ creatoropts['release'])
try:
creator.check_depend_tools()
diff --git a/plugins/imager/livecd_plugin.py b/plugins/imager/livecd_plugin.py
index 7828e5c..5b9349f 100644
--- a/plugins/imager/livecd_plugin.py
+++ b/plugins/imager/livecd_plugin.py
@@ -89,13 +89,10 @@ class LiveCDPlugin(ImagerPlugin):
if len(recording_pkgs) > 0:
creator._recording_pkgs = recording_pkgs
- if creatoropts['release'] is None:
- imagefile = "%s.iso" % os.path.join(creator.destdir, creator.name)
- if os.path.exists(imagefile):
- if msger.ask('The target image: %s already exists, cleanup and continue?' % imagefile):
- os.unlink(imagefile)
- else:
- raise errors.Abort('Canceled')
+ self.check_image_exists(creator.destdir,
+ creator.pack_to,
+ [creator.name + ".iso"],
+ creatoropts['release'])
try:
creator.check_depend_tools()
diff --git a/plugins/imager/liveusb_plugin.py b/plugins/imager/liveusb_plugin.py
index 45fd308..c5735aa 100644
--- a/plugins/imager/liveusb_plugin.py
+++ b/plugins/imager/liveusb_plugin.py
@@ -91,14 +91,10 @@ class LiveUSBPlugin(ImagerPlugin):
if len(recording_pkgs) > 0:
creator._recording_pkgs = recording_pkgs
- if creatoropts['release'] is None:
- imagefile = "%s.usbimg" % os.path.join(creator.destdir, creator.name)
- if os.path.exists(imagefile):
- if msger.ask('The target image: %s already exists, cleanup and continue?' % imagefile):
- os.unlink(imagefile)
- else:
- raise errors.Abort('Canceled')
-
+ self.check_image_exists(creator.destdir,
+ creator.pack_to,
+ [creator.name + ".usbimg"],
+ creatoropts['release'])
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 de9c431..52f2c42 100644
--- a/plugins/imager/loop_plugin.py
+++ b/plugins/imager/loop_plugin.py
@@ -97,18 +97,10 @@ class LoopPlugin(ImagerPlugin):
if len(recording_pkgs) > 0:
creator._recording_pkgs = recording_pkgs
- if creatoropts['release'] is None:
- if creatoropts['pack_to']:
- imagefile = "%s" % os.path.join(creator.destdir, creator.pack_to)
- else:
- imagefile = "%s.img" % os.path.join(creator.destdir, creator.name)
-
- if os.path.exists(imagefile):
- if msger.ask('The target image: %s already exists, cleanup '
- 'and continue?' % imagefile):
- os.unlink(imagefile)
- else:
- raise errors.Abort('Canceled')
+ self.check_image_exists(creator.destdir,
+ creator.pack_to,
+ [creator.name + ".img"],
+ creatoropts['release'])
try:
creator.check_depend_tools()
diff --git a/plugins/imager/raw_plugin.py b/plugins/imager/raw_plugin.py
index 6fbb35f..f156606 100644
--- a/plugins/imager/raw_plugin.py
+++ b/plugins/imager/raw_plugin.py
@@ -94,14 +94,12 @@ class RawPlugin(ImagerPlugin):
if len(recording_pkgs) > 0:
creator._recording_pkgs = recording_pkgs
- if creatoropts['release'] is None:
- for item in creator.get_diskinfo():
- imagefile = "%s-%s.raw" % (os.path.join(creator.destdir, creator.name), item['name'])
- if os.path.exists(imagefile):
- if msger.ask('The target image: %s already exists, cleanup and continue?' % imagefile):
- os.unlink(imagefile)
- else:
- raise errors.Abort('Canceled')
+ images = ["%s-%s.raw" % (creator.name, part['name'])
+ for part in creator.get_diskinfo()]
+ self.check_image_exists(creator.destdir,
+ creator.pack_to,
+ images,
+ creatoropts['release'])
try:
creator.check_depend_tools()