if 'release' in createopts and createopts['release']:
self.name += '-' + createopts['release']
- if os.path.exists(self.destdir):
- if msger.ask("Image dir: %s already exists, cleanup and" \
- "continue?" % self.destdir):
- shutil.rmtree(self.destdir, ignore_errors = True)
- else:
- raise Abort("Canceled")
-
- # pending FEA: save log by default for --release
+ # pending FEA: save log by default for --release
if self.pack_to:
if '@NAME@' in self.pack_to:
# with this program; if not, write to the Free Software Foundation, Inc., 59
# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+import os
+import shutil
from mic import msger
+from mic.utils import errors
class _Plugin(object):
class __metaclass__(type):
class ImagerPlugin(_Plugin):
mic_plugin_type = "imager"
+ @classmethod
+ def check_image_exists(self, destdir, apacking=None, images=[], release=None):
+ # if it's a packing file, reset images
+ if apacking:
+ images = [apacking]
+
+ # release option will override images
+ if release is not None:
+ images = [os.path.basename(destdir.rstrip('/'))]
+ destdir = os.path.dirname(destdir.rstrip('/'))
+
+ for name in images:
+ if not name:
+ continue
+
+ image = os.path.join(destdir, name)
+ if not os.path.exists(image):
+ continue
+
+ if msger.ask("Target image/dir: %s already exists, "
+ "clean up and continue?" % image):
+ if os.path.isdir(image):
+ shutil.rmtree(image)
+ else:
+ os.unlink(image)
+ else:
+ raise errors.Abort("Cancled")
+
def do_create(self):
pass
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()
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()
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"])
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()
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()