mirror of
https://git.yoctoproject.org/poky
synced 2026-09-19 18:49:32 +02:00
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:
committed by
Richard Purdie
parent
3d47a212a6
commit
f5ae79da40
@@ -30,8 +30,8 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
|
|
||||||
|
from wic.errors import WicError
|
||||||
from wic.plugin import pluginmgr
|
from wic.plugin import pluginmgr
|
||||||
from wic.utils.misc import get_bitbake_var
|
from wic.utils.misc import get_bitbake_var
|
||||||
|
|
||||||
@@ -44,8 +44,7 @@ def verify_build_env():
|
|||||||
Returns True if it is, false otherwise
|
Returns True if it is, false otherwise
|
||||||
"""
|
"""
|
||||||
if not os.environ.get("BUILDDIR"):
|
if not os.environ.get("BUILDDIR"):
|
||||||
logger.error("BUILDDIR not found, exiting. (Did you forget to source oe-init-build-env?)")
|
raise WicError("BUILDDIR not found, exiting. (Did you forget to source oe-init-build-env?)")
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -180,8 +179,7 @@ def wic_create(wks_file, rootfs_dir, bootimg_dir, kernel_dir,
|
|||||||
try:
|
try:
|
||||||
oe_builddir = os.environ["BUILDDIR"]
|
oe_builddir = os.environ["BUILDDIR"]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
logger.error("BUILDDIR not found, exiting. (Did you forget to source oe-init-build-env?)")
|
raise WicError("BUILDDIR not found, exiting. (Did you forget to source oe-init-build-env?)")
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
if not os.path.exists(options.outdir):
|
if not os.path.exists(options.outdir):
|
||||||
os.makedirs(options.outdir)
|
os.makedirs(options.outdir)
|
||||||
@@ -189,8 +187,7 @@ def wic_create(wks_file, rootfs_dir, bootimg_dir, kernel_dir,
|
|||||||
pname = 'direct'
|
pname = 'direct'
|
||||||
plugin_class = pluginmgr.get_plugins('imager').get(pname)
|
plugin_class = pluginmgr.get_plugins('imager').get(pname)
|
||||||
if not plugin_class:
|
if not plugin_class:
|
||||||
logger.error('Unknown plugin: %s', pname)
|
raise WicError('Unknown plugin: %s' % pname)
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
plugin = plugin_class(wks_file, rootfs_dir, bootimg_dir, kernel_dir,
|
plugin = plugin_class(wks_file, rootfs_dir, bootimg_dir, kernel_dir,
|
||||||
native_sysroot, oe_builddir, options)
|
native_sysroot, oe_builddir, options)
|
||||||
@@ -217,11 +214,11 @@ def wic_list(args, scripts_path):
|
|||||||
wks_file = args[0]
|
wks_file = args[0]
|
||||||
fullpath = find_canned_image(scripts_path, wks_file)
|
fullpath = find_canned_image(scripts_path, wks_file)
|
||||||
if not fullpath:
|
if not fullpath:
|
||||||
logger.error("No image named %s found, exiting. "
|
raise WicError("No image named %s found, exiting. "
|
||||||
"(Use 'wic list images' to list available images, or "
|
"(Use 'wic list images' to list available images, "
|
||||||
"specify a fully-qualified OE kickstart (.wks) "
|
"or specify a fully-qualified OE kickstart (.wks) "
|
||||||
"filename)\n", wks_file)
|
"filename)" % wks_file)
|
||||||
sys.exit(1)
|
|
||||||
list_canned_image_help(scripts_path, fullpath)
|
list_canned_image_help(scripts_path, fullpath)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|||||||
@@ -26,9 +26,9 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
|
from wic.errors import WicError
|
||||||
from wic.utils.misc import exec_cmd, exec_native_cmd, get_bitbake_var
|
from wic.utils.misc import exec_cmd, exec_native_cmd, get_bitbake_var
|
||||||
from wic.plugin import pluginmgr
|
from wic.plugin import pluginmgr
|
||||||
|
|
||||||
@@ -99,9 +99,9 @@ class Partition():
|
|||||||
if self.fixed_size:
|
if self.fixed_size:
|
||||||
rootfs_size = self.fixed_size
|
rootfs_size = self.fixed_size
|
||||||
if actual_rootfs_size > rootfs_size:
|
if actual_rootfs_size > rootfs_size:
|
||||||
logger.error("Actual rootfs size (%d kB) is larger than allowed size %d kB",
|
raise WicError("Actual rootfs size (%d kB) is larger than "
|
||||||
actual_rootfs_size, rootfs_size)
|
"allowed size %d kB" %
|
||||||
sys.exit(1)
|
(actual_rootfs_size, rootfs_size))
|
||||||
else:
|
else:
|
||||||
extra_blocks = self.get_extra_block_count(actual_rootfs_size)
|
extra_blocks = self.get_extra_block_count(actual_rootfs_size)
|
||||||
if extra_blocks < self.extra_space:
|
if extra_blocks < self.extra_space:
|
||||||
@@ -132,10 +132,10 @@ class Partition():
|
|||||||
"""
|
"""
|
||||||
if not self.source:
|
if not self.source:
|
||||||
if not self.size and not self.fixed_size:
|
if not self.size and not self.fixed_size:
|
||||||
logger.error("The %s partition has a size of zero. Please "
|
raise WicError("The %s partition has a size of zero. Please "
|
||||||
"specify a non-zero --size/--fixed-size for that "
|
"specify a non-zero --size/--fixed-size for that "
|
||||||
"partition.", self.mountpoint)
|
"partition." % self.mountpoint)
|
||||||
sys.exit(1)
|
|
||||||
if self.fstype and self.fstype == "swap":
|
if self.fstype and self.fstype == "swap":
|
||||||
self.prepare_swap_partition(cr_workdir, oe_builddir,
|
self.prepare_swap_partition(cr_workdir, oe_builddir,
|
||||||
native_sysroot)
|
native_sysroot)
|
||||||
@@ -157,12 +157,11 @@ class Partition():
|
|||||||
plugins = pluginmgr.get_source_plugins()
|
plugins = pluginmgr.get_source_plugins()
|
||||||
|
|
||||||
if self.source not in plugins:
|
if self.source not in plugins:
|
||||||
logger.error("The '%s' --source specified for %s doesn't exist.\n\t"
|
raise WicError("The '%s' --source specified for %s doesn't exist.\n\t"
|
||||||
"See 'wic list source-plugins' for a list of available"
|
"See 'wic list source-plugins' for a list of available"
|
||||||
" --sources.\n\tSee 'wic help source-plugins' for "
|
" --sources.\n\tSee 'wic help source-plugins' for "
|
||||||
"details on adding a new source plugin.",
|
"details on adding a new source plugin." %
|
||||||
self.source, self.mountpoint)
|
(self.source, self.mountpoint))
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
srcparams_dict = {}
|
srcparams_dict = {}
|
||||||
if self.sourceparams:
|
if self.sourceparams:
|
||||||
@@ -192,16 +191,14 @@ class Partition():
|
|||||||
# further processing required Partition.size to be an integer, make
|
# further processing required Partition.size to be an integer, make
|
||||||
# sure that it is one
|
# sure that it is one
|
||||||
if not isinstance(self.size, int):
|
if not isinstance(self.size, int):
|
||||||
logger.error("Partition %s internal size is not an integer. "
|
raise WicError("Partition %s internal size is not an integer. "
|
||||||
"This a bug in source plugin %s and needs to be fixed.",
|
"This a bug in source plugin %s and needs to be fixed." %
|
||||||
self.mountpoint, self.source)
|
(self.mountpoint, self.source))
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
if self.fixed_size and self.size > self.fixed_size:
|
if self.fixed_size and self.size > self.fixed_size:
|
||||||
logger.error("File system image of partition %s is larger (%d kB) "
|
raise WicError("File system image of partition %s is "
|
||||||
"than its allowed size %d kB",
|
"larger (%d kB) than its allowed size %d kB" %
|
||||||
self.mountpoint, self.size, self.fixed_size)
|
(self.mountpoint, self.size, self.fixed_size))
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
def prepare_rootfs_from_fs_image(self, cr_workdir, oe_builddir,
|
def prepare_rootfs_from_fs_image(self, cr_workdir, oe_builddir,
|
||||||
rootfs_dir):
|
rootfs_dir):
|
||||||
@@ -241,9 +238,8 @@ class Partition():
|
|||||||
os.remove(rootfs)
|
os.remove(rootfs)
|
||||||
|
|
||||||
if not self.fstype:
|
if not self.fstype:
|
||||||
logger.error("File system for partition %s not specified in kickstart, "
|
raise WicError("File system for partition %s not specified in "
|
||||||
"use --fstype option", self.mountpoint)
|
"kickstart, use --fstype option" % self.mountpoint)
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
# Get rootfs size from bitbake variable if it's not set in .ks file
|
# Get rootfs size from bitbake variable if it's not set in .ks file
|
||||||
if not self.size:
|
if not self.size:
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import re
|
|||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from distutils import spawn
|
from distutils import spawn
|
||||||
|
|
||||||
|
from wic.errors import WicError
|
||||||
from wic.utils import runner
|
from wic.utils import runner
|
||||||
|
|
||||||
logger = logging.getLogger('wic')
|
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)
|
ret, out = runner.runtool(args, catch)
|
||||||
out = out.strip()
|
out = out.strip()
|
||||||
if ret != 0:
|
if ret != 0:
|
||||||
logger.error("_exec_cmd: %s returned '%s' instead of 0\noutput: %s" % \
|
raise WicError("_exec_cmd: %s returned '%s' instead of 0\noutput: %s" % \
|
||||||
(cmd_and_args, ret, out))
|
(cmd_and_args, ret, out))
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
logger.debug("_exec_cmd: output for %s (rc = %d): %s",
|
logger.debug("_exec_cmd: output for %s (rc = %d): %s",
|
||||||
cmd_and_args, ret, out)
|
cmd_and_args, ret, out)
|
||||||
|
|||||||
@@ -18,7 +18,8 @@
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
|
||||||
|
from wic.errors import WicError
|
||||||
|
|
||||||
logger = logging.getLogger('wic')
|
logger = logging.getLogger('wic')
|
||||||
|
|
||||||
@@ -72,8 +73,7 @@ def runtool(cmdln_or_args, catch=1):
|
|||||||
except OSError as err:
|
except OSError as err:
|
||||||
if err.errno == 2:
|
if err.errno == 2:
|
||||||
# [Errno 2] No such file or directory
|
# [Errno 2] No such file or directory
|
||||||
logger.error('Cannot run command: %s, lost dependency?', cmd)
|
raise WicError('Cannot run command: %s, lost dependency?' % cmd)
|
||||||
sys.exit(1)
|
|
||||||
else:
|
else:
|
||||||
raise # relay
|
raise # relay
|
||||||
finally:
|
finally:
|
||||||
|
|||||||
Reference in New Issue
Block a user