raise error instead of msger.error
authorGui Chen <gui.chen@intel.com>
Tue, 22 Oct 2013 03:43:42 +0000 (23:43 -0400)
committerGerrit Code Review <gerrit2@otctools.jf.intel.com>
Wed, 23 Oct 2013 03:18:03 +0000 (20:18 -0700)
mic uses too many msger.error to exit the program directly,
it's not safe, except main loop, other logic should raise
error as possible

Change-Id: I4fa0c05998b78c3bb9b12148e7dfd6c04bad8251
Signed-off-by: Gui Chen <gui.chen@intel.com>
mic/conf.py
mic/creator.py
mic/imager/loop.py
mic/utils/fs_related.py
mic/utils/runner.py
plugins/imager/loop_plugin.py

index 8b982cb..5c14c5d 100644 (file)
@@ -121,7 +121,7 @@ class ConfigMgr(object):
 
     def __set_ksconf(self, ksconf):
         if not os.path.isfile(ksconf):
-            msger.error('Cannot find ks file: %s' % ksconf)
+            raise errors.KsError('Cannot find ks file: %s' % ksconf)
 
         self.__ksconf = ksconf
         self._parse_kickstart(ksconf)
@@ -155,7 +155,7 @@ class ConfigMgr(object):
             if m:
                 scheme = m.group(1)
                 if scheme not in ('http', 'https', 'ftp', 'socks'):
-                    msger.error("%s: proxy scheme is incorrect" % siteconf)
+                    raise errors.ConfigError("%s: proxy scheme is incorrect" % siteconf)
             else:
                 msger.warning("%s: proxy url w/o scheme, use http as default"
                               % siteconf)
@@ -230,7 +230,7 @@ class ConfigMgr(object):
 
     def set_runtime(self, runtime):
         if runtime not in ("bootstrap", "native"):
-            msger.error("Invalid runtime mode: %s" % runtime)
+            raise errors.CreatorError("Invalid runtime mode: %s" % runtime)
 
         if misc.get_distro()[0] in ("tizen", "Tizen"):
             runtime = "native"
index 8a36f03..e27c8a1 100644 (file)
@@ -199,8 +199,8 @@ class Creator(cmdln.Cmdln):
         for cdir in ('outdir', 'cachedir'):
             if os.path.exists(configmgr.create[cdir]) \
               and not os.path.isdir(configmgr.create[cdir]):
-                msger.error('Invalid directory specified: %s' \
-                            % configmgr.create[cdir])
+                raise errors.Usage('Invalid directory specified: %s' \
+                                   % configmgr.create[cdir])
             if not os.path.exists(configmgr.create[cdir]):
                 os.makedirs(configmgr.create[cdir])
                 if os.getenv('SUDO_UID', '') and os.getenv('SUDO_GID', ''):
@@ -210,7 +210,7 @@ class Creator(cmdln.Cmdln):
 
         if self.options.local_pkgs_path is not None:
             if not os.path.exists(self.options.local_pkgs_path):
-                msger.error('Local pkgs directory: \'%s\' not exist' \
+                raise errors.Usage('Local pkgs directory: \'%s\' not exist' \
                               % self.options.local_pkgs_path)
             configmgr.create['local_pkgs_path'] = self.options.local_pkgs_path
 
@@ -289,7 +289,7 @@ class Creator(cmdln.Cmdln):
             except cmdln.CmdlnUserError, ex:
                 msg = "%s: %s\nTry '%s help' for info.\n"\
                       % (self.name, ex, self.name)
-                msger.error(msg)
+                raise errors.Usage(msg)
 
             except cmdln.StopOptionProcessing, ex:
                 return 0
index 4d05ef2..85ffe5d 100644 (file)
@@ -341,7 +341,7 @@ class LoopImageCreator(BaseImageCreator):
             elif fstype in ("vfat", "msdos"):
                 MyDiskMount = fs.VfatDiskMount
             else:
-                msger.error('Cannot support fstype: %s' % fstype)
+                raise MountError('Cannot support fstype: %s' % fstype)
 
             loop['loop'] = MyDiskMount(fs.SparseLoopbackDisk(
                                            os.path.join(self.__imgdir, imgname),
index 8b4d93f..1a6bf96 100644 (file)
@@ -898,7 +898,7 @@ class LoopDevice(object):
                 self.cleanup()
                 self.device = None
             except MountError, e:
-                msger.error("%s" % e)
+                raise CreatorError("%s" % e)
 
     def cleanup(self):
 
index fded3c9..5c9eee1 100644 (file)
@@ -70,7 +70,7 @@ def runtool(cmdln_or_args, catch=1):
     except OSError, e:
         if e.errno == 2:
             # [Errno 2] No such file or directory
-            msger.error('Cannot run command: %s, lost dependency?' % cmd)
+            raise errors.CreatorError('Cannot run command: %s, lost dependency?' % cmd)
         else:
             raise # relay
     finally:
index 8f4b030..fd1f057 100644 (file)
@@ -158,7 +158,7 @@ class LoopPlugin(ImagerPlugin):
             elif fstype in ("vfat", "msdos"):
                 myDiskMount = fs_related.VfatDiskMount
             else:
-                msger.error("Cannot support fstype: %s" % fstype)
+                raise errors.CreatorError("Cannot support fstype: %s" % fstype)
 
             name = os.path.join(tmpdir, name)
             size = size * 1024L * 1024L