wic: raise WicError in core modules

Replaced sys.exit with raising WicError in the core wic modules.

(From OE-Core rev: 1b11437fb25ece5b3eede52344b071e875fa738f)

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Ed Bartosh 2017-02-14 22:21:38 +02:00 committed by Richard Purdie
parent 3d47a212a6
commit f5ae79da40
4 changed files with 36 additions and 43 deletions

View File

@ -30,8 +30,8 @@
import logging
import os
import sys
from wic.errors import WicError
from wic.plugin import pluginmgr
from wic.utils.misc import get_bitbake_var
@ -44,8 +44,7 @@ def verify_build_env():
Returns True if it is, false otherwise
"""
if not os.environ.get("BUILDDIR"):
logger.error("BUILDDIR not found, exiting. (Did you forget to source oe-init-build-env?)")
sys.exit(1)
raise WicError("BUILDDIR not found, exiting. (Did you forget to source oe-init-build-env?)")
return True
@ -180,8 +179,7 @@ def wic_create(wks_file, rootfs_dir, bootimg_dir, kernel_dir,
try:
oe_builddir = os.environ["BUILDDIR"]
except KeyError:
logger.error("BUILDDIR not found, exiting. (Did you forget to source oe-init-build-env?)")
sys.exit(1)
raise WicError("BUILDDIR not found, exiting. (Did you forget to source oe-init-build-env?)")
if not os.path.exists(options.outdir):
os.makedirs(options.outdir)
@ -189,8 +187,7 @@ def wic_create(wks_file, rootfs_dir, bootimg_dir, kernel_dir,
pname = 'direct'
plugin_class = pluginmgr.get_plugins('imager').get(pname)
if not plugin_class:
logger.error('Unknown plugin: %s', pname)
sys.exit(1)
raise WicError('Unknown plugin: %s' % pname)
plugin = plugin_class(wks_file, rootfs_dir, bootimg_dir, kernel_dir,
native_sysroot, oe_builddir, options)
@ -217,11 +214,11 @@ def wic_list(args, scripts_path):
wks_file = args[0]
fullpath = find_canned_image(scripts_path, wks_file)
if not fullpath:
logger.error("No image named %s found, exiting. "
"(Use 'wic list images' to list available images, or "
"specify a fully-qualified OE kickstart (.wks) "
"filename)\n", wks_file)
sys.exit(1)
raise WicError("No image named %s found, exiting. "
"(Use 'wic list images' to list available images, "
"or specify a fully-qualified OE kickstart (.wks) "
"filename)" % wks_file)
list_canned_image_help(scripts_path, fullpath)
return True

View File

@ -26,9 +26,9 @@
import logging
import os
import sys
import tempfile
from wic.errors import WicError
from wic.utils.misc import exec_cmd, exec_native_cmd, get_bitbake_var
from wic.plugin import pluginmgr
@ -99,9 +99,9 @@ class Partition():
if self.fixed_size:
rootfs_size = self.fixed_size
if actual_rootfs_size > rootfs_size:
logger.error("Actual rootfs size (%d kB) is larger than allowed size %d kB",
actual_rootfs_size, rootfs_size)
sys.exit(1)
raise WicError("Actual rootfs size (%d kB) is larger than "
"allowed size %d kB" %
(actual_rootfs_size, rootfs_size))
else:
extra_blocks = self.get_extra_block_count(actual_rootfs_size)
if extra_blocks < self.extra_space:
@ -132,10 +132,10 @@ class Partition():
"""
if not self.source:
if not self.size and not self.fixed_size:
logger.error("The %s partition has a size of zero. Please "
"specify a non-zero --size/--fixed-size for that "
"partition.", self.mountpoint)
sys.exit(1)
raise WicError("The %s partition has a size of zero. Please "
"specify a non-zero --size/--fixed-size for that "
"partition." % self.mountpoint)
if self.fstype and self.fstype == "swap":
self.prepare_swap_partition(cr_workdir, oe_builddir,
native_sysroot)
@ -157,12 +157,11 @@ class Partition():
plugins = pluginmgr.get_source_plugins()
if self.source not in plugins:
logger.error("The '%s' --source specified for %s doesn't exist.\n\t"
"See 'wic list source-plugins' for a list of available"
" --sources.\n\tSee 'wic help source-plugins' for "
"details on adding a new source plugin.",
self.source, self.mountpoint)
sys.exit(1)
raise WicError("The '%s' --source specified for %s doesn't exist.\n\t"
"See 'wic list source-plugins' for a list of available"
" --sources.\n\tSee 'wic help source-plugins' for "
"details on adding a new source plugin." %
(self.source, self.mountpoint))
srcparams_dict = {}
if self.sourceparams:
@ -192,16 +191,14 @@ class Partition():
# further processing required Partition.size to be an integer, make
# sure that it is one
if not isinstance(self.size, int):
logger.error("Partition %s internal size is not an integer. "
"This a bug in source plugin %s and needs to be fixed.",
self.mountpoint, self.source)
sys.exit(1)
raise WicError("Partition %s internal size is not an integer. "
"This a bug in source plugin %s and needs to be fixed." %
(self.mountpoint, self.source))
if self.fixed_size and self.size > self.fixed_size:
logger.error("File system image of partition %s is larger (%d kB) "
"than its allowed size %d kB",
self.mountpoint, self.size, self.fixed_size)
sys.exit(1)
raise WicError("File system image of partition %s is "
"larger (%d kB) than its allowed size %d kB" %
(self.mountpoint, self.size, self.fixed_size))
def prepare_rootfs_from_fs_image(self, cr_workdir, oe_builddir,
rootfs_dir):
@ -241,9 +238,8 @@ class Partition():
os.remove(rootfs)
if not self.fstype:
logger.error("File system for partition %s not specified in kickstart, "
"use --fstype option", self.mountpoint)
sys.exit(1)
raise WicError("File system for partition %s not specified in "
"kickstart, use --fstype option" % self.mountpoint)
# Get rootfs size from bitbake variable if it's not set in .ks file
if not self.size:

View File

@ -33,6 +33,7 @@ import re
from collections import defaultdict
from distutils import spawn
from wic.errors import WicError
from wic.utils import runner
logger = logging.getLogger('wic')
@ -74,9 +75,8 @@ def _exec_cmd(cmd_and_args, as_shell=False, catch=3):
ret, out = runner.runtool(args, catch)
out = out.strip()
if ret != 0:
logger.error("_exec_cmd: %s returned '%s' instead of 0\noutput: %s" % \
(cmd_and_args, ret, out))
sys.exit(1)
raise WicError("_exec_cmd: %s returned '%s' instead of 0\noutput: %s" % \
(cmd_and_args, ret, out))
logger.debug("_exec_cmd: output for %s (rc = %d): %s",
cmd_and_args, ret, out)

View File

@ -18,7 +18,8 @@
import logging
import os
import subprocess
import sys
from wic.errors import WicError
logger = logging.getLogger('wic')
@ -72,8 +73,7 @@ def runtool(cmdln_or_args, catch=1):
except OSError as err:
if err.errno == 2:
# [Errno 2] No such file or directory
logger.error('Cannot run command: %s, lost dependency?', cmd)
sys.exit(1)
raise WicError('Cannot run command: %s, lost dependency?' % cmd)
else:
raise # relay
finally: