from mic import kickstart
from mic import msger
-from mic.utils.errors import CreatorError
+from mic.utils.errors import CreatorError, Abort
from mic.utils import misc, rpmmisc, runner, fs_related as fs
class BaseImageCreator(object):
"""
self.pkgmgr = pkgmgr
+ self.__builddir = None
+ self.__bindmounts = []
+
if createopts:
# A pykickstart.KickstartParser instance."""
self.ks = createopts['ks']
# check whether destine dir exist
if os.path.exists(self.destdir):
- if msger.ask('Image dir: %s already exists, need to delete it?' % 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')
# save log by default for --release
if not createopts['logfile']:
self.target_arch = "noarch"
self._local_pkgs_path = None
- self.__builddir = None
- self.__bindmounts = []
-
self._dep_checks = ["ls", "bash", "cp", "echo", "modprobe", "passwd"]
#FIXME to be obsolete, make it configurable
def __str__(self):
return self.keyword + str(self.msg) + ', please use "--help" for more info'
+class Abort(CreatorError):
+ keyword = ''
+
class ConfigError(CreatorError):
keyword = '<config>'
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, need to delete it?' % fsdir):
+ if msger.ask('The target dir: %s already exists, cleanup and continue?' % fsdir):
import shutil
shutil.rmtree(fsdir)
+ else:
+ raise errors.Abort('Canceled')
try:
creator.check_depend_tools()
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, need to delete it?' % imagefile):
+ if msger.ask('The target image: %s already exists, cleanup and continue?' % imagefile):
os.unlink(imagefile)
+ else:
+ raise errors.Abort('Canceled')
try:
creator.check_depend_tools()
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, need to delete it?' % imagefile):
+ if msger.ask('The target image: %s already exists, cleanup and continue?' % imagefile):
os.unlink(imagefile)
+ else:
+ raise errors.Abort('Canceled')
try:
creator.check_depend_tools()
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, need to delete it?' % imagefile):
+ if msger.ask('The target image: %s already exists, cleanup and continue?' % imagefile):
os.unlink(imagefile)
+ else:
+ raise errors.Abort('Canceled')
try:
creator.check_depend_tools()
if creatoropts['release'] is None:
imagefile = "%s-sda.raw" % os.path.join(creator.destdir, creator.name)
if os.path.exists(imagefile):
- if msger.ask('The target image: %s already exists, need to delete it?' % imagefile):
+ if msger.ask('The target image: %s already exists, cleanup and continue?' % imagefile):
os.unlink(imagefile)
+ else:
+ raise errors.Abort('Canceled')
try:
creator.check_depend_tools()
except errors.Usage, usage:
msger.error(str(usage))
+ except errors.Abort, msg:
+ msger.info(str(msg))
+
except errors.CreatorError, err:
if msger.get_loglevel() == 'debug':
import traceback