* [PATCH 00/11] wic refactoring (almost done)
@ 2017-02-15 8:38 Ed Bartosh
2017-02-15 8:38 ` [PATCH 01/11] wic: setup logging in the main wic module Ed Bartosh
` (10 more replies)
0 siblings, 11 replies; 12+ messages in thread
From: Ed Bartosh @ 2017-02-15 8:38 UTC (permalink / raw)
To: openembedded-core
Hi,
This patchset takes care of logging and error handling:
- remove custom msger module in favor of standard python logging
- raise WicError exception instead of calling sys.exit
This is the one of the last changes for this time.
I'm thinking about refactoring wic plugin system, but haven't decided yet
if it makes sense to do right now or not. Other than that I'm happy with
the state of the wic codebase for now. There are still many things to improve,
but it looks and feels much better now.
The following changes since commit 10d1f08f71a623ca6d45cf0ae1afa2e880591a09:
wic: direct: move creation of PartitionedImage to __init__ (2017-02-10 16:44:03 +0200)
are available in the git repository at:
git://git.yoctoproject.org/poky-contrib ed/wic/wip
http://git.yoctoproject.org/cgit.cgi/poky-contrib/log/?h=ed/wic/wip
Ed Bartosh (11):
wic: setup logging in the main wic module
wic: use wic logger in core modules
wic: use wic logger in imager direct plugin
wic: use wic logger in wic source plugins
wic: remove msger module
wic: move errors module
wic: raise WicError in main module
wic: raise WicError in core modules
wic: raise WicError in wic plugins
wic: raise WicError instead of ImageError and CreatorError
wic: move WicError to lib/wic/__init__.py
scripts/lib/wic/__init__.py | 20 ++
scripts/lib/wic/engine.py | 28 ++-
scripts/lib/wic/help.py | 8 +-
scripts/lib/wic/ksparser.py | 7 +-
scripts/lib/wic/msger.py | 209 ---------------------
scripts/lib/wic/partition.py | 68 +++----
scripts/lib/wic/plugin.py | 24 +--
scripts/lib/wic/pluginbase.py | 12 +-
scripts/lib/wic/plugins/imager/direct.py | 87 ++++-----
scripts/lib/wic/plugins/source/bootimg-efi.py | 52 ++---
.../lib/wic/plugins/source/bootimg-partition.py | 25 +--
scripts/lib/wic/plugins/source/bootimg-pcbios.py | 41 ++--
scripts/lib/wic/plugins/source/fsimage.py | 14 +-
.../lib/wic/plugins/source/isoimage-isohybrid.py | 79 ++++----
scripts/lib/wic/plugins/source/rawcopy.py | 12 +-
scripts/lib/wic/plugins/source/rootfs.py | 21 ++-
.../lib/wic/plugins/source/rootfs_pcbios_ext.py | 54 +++---
scripts/lib/wic/utils/errors.py | 29 ---
scripts/lib/wic/utils/misc.py | 34 ++--
scripts/lib/wic/utils/runner.py | 12 +-
scripts/wic | 104 +++++-----
21 files changed, 378 insertions(+), 562 deletions(-)
delete mode 100644 scripts/lib/wic/msger.py
delete mode 100644 scripts/lib/wic/utils/errors.py
--
Regards,
Ed
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 01/11] wic: setup logging in the main wic module
2017-02-15 8:38 [PATCH 00/11] wic refactoring (almost done) Ed Bartosh
@ 2017-02-15 8:38 ` Ed Bartosh
2017-02-15 8:38 ` [PATCH 02/11] wic: use wic logger in core modules Ed Bartosh
` (9 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Ed Bartosh @ 2017-02-15 8:38 UTC (permalink / raw)
To: openembedded-core
Set up wic logger using standerd logging module.
This is going to replace custom msger module.
Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
---
scripts/wic | 77 +++++++++++++++++++++++++++++++++++--------------------------
1 file changed, 44 insertions(+), 33 deletions(-)
diff --git a/scripts/wic b/scripts/wic
index 1b7d7df..f3e93da 100755
--- a/scripts/wic
+++ b/scripts/wic
@@ -56,6 +56,23 @@ from wic.utils.errors import WicError
from wic import engine
from wic import help as hlp
+
+def wic_logger():
+ """Create and convfigure wic logger."""
+ logger = logging.getLogger('wic')
+ logger.setLevel(logging.INFO)
+
+ handler = logging.StreamHandler()
+
+ formatter = logging.Formatter('%(levelname)s: %(message)s')
+ handler.setFormatter(formatter)
+
+ logger.addHandler(handler)
+
+ return logger
+
+logger = wic_logger()
+
def rootfs_dir_to_args(krootfs_dir):
"""
Get a rootfs_dir dict and serialize to string
@@ -123,12 +140,12 @@ def wic_create_subcommand(args, usage_str):
(options, args) = parser.parse_args(args)
if len(args) != 1:
- logging.error("Wrong number of arguments, exiting\n")
+ logger.error("Wrong number of arguments, exiting\n")
parser.print_help()
sys.exit(1)
if options.build_rootfs and not bitbake_main:
- logging.error("Can't build roofs as bitbake is not in the $PATH")
+ logger.error("Can't build roofs as bitbake is not in the $PATH")
sys.exit(1)
if not options.image_name:
@@ -140,8 +157,8 @@ def wic_create_subcommand(args, usage_str):
if not val:
missed.append(opt)
if missed:
- print("The following build artifacts are not specified:")
- print(" " + ", ".join(missed))
+ logger.error("The following build artifacts are not specified: %s",
+ ", ".join(missed))
sys.exit(1)
if options.image_name:
@@ -152,23 +169,22 @@ def wic_create_subcommand(args, usage_str):
if options.vars_dir:
BB_VARS.vars_dir = options.vars_dir
- if options.build_check:
- print("Checking basic build environment...")
- if not engine.verify_build_env():
- print("Couldn't verify build environment, exiting\n")
- sys.exit(1)
- else:
- print("Done.\n")
+ if options.build_check and not engine.verify_build_env():
+ logger.error("Couldn't verify build environment, exiting\n")
+ sys.exit(1)
bootimg_dir = ""
+ if options.debug:
+ logger.setLevel(logging.DEBUG)
+
if options.image_name:
if options.build_rootfs:
argv = ["bitbake", options.image_name]
if options.debug:
argv.append("--debug")
- print("Building rootfs...\n")
+ logger.info("Building rootfs...\n")
if bitbake_main(BitBakeConfigParameters(argv),
cookerdata.CookerConfiguration()):
sys.exit(1)
@@ -179,18 +195,18 @@ def wic_create_subcommand(args, usage_str):
"wic-tools", cache=False)
else:
if options.build_rootfs:
- print("Image name is not specified, exiting. (Use -e/--image-name to specify it)\n")
+ logger.error("Image name is not specified, exiting. (Use -e/--image-name to specify it)\n")
sys.exit(1)
native_sysroot = options.native_sysroot
if not native_sysroot or not os.path.isdir(native_sysroot):
- print("Building wic-tools...\n")
+ logger.info("Building wic-tools...\n")
if bitbake_main(BitBakeConfigParameters("bitbake wic-tools".split()),
cookerdata.CookerConfiguration()):
sys.exit(1)
native_sysroot = get_bitbake_var("RECIPE_SYSROOT_NATIVE", "wic-tools")
if not native_sysroot:
- print("Unable to find the location of the native tools sysroot to use\n")
+ logger.info("Unable to find the location of the native tools sysroot to use\n")
sys.exit(1)
wks_file = args[0]
@@ -198,7 +214,7 @@ def wic_create_subcommand(args, usage_str):
if not wks_file.endswith(".wks"):
wks_file = engine.find_canned_image(scripts_path, wks_file)
if not wks_file:
- print("No image named %s found, exiting. (Use 'wic list images' "\
+ 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" % args[0])
sys.exit(1)
@@ -211,16 +227,16 @@ def wic_create_subcommand(args, usage_str):
kernel_dir = options.kernel_dir
native_sysroot = options.native_sysroot
if rootfs_dir and not os.path.isdir(rootfs_dir):
- print("--roofs-dir (-r) not found, exiting\n")
+ logger.error("--roofs-dir (-r) not found, exiting\n")
sys.exit(1)
if not os.path.isdir(bootimg_dir):
- print("--bootimg-dir (-b) not found, exiting\n")
+ logger.error("--bootimg-dir (-b) not found, exiting\n")
sys.exit(1)
if not os.path.isdir(kernel_dir):
- print("--kernel-dir (-k) not found, exiting\n")
+ logger.error("--kernel-dir (-k) not found, exiting\n")
sys.exit(1)
if not os.path.isdir(native_sysroot):
- print("--native-sysroot (-n) not found, exiting\n")
+ logger.error("--native-sysroot (-n) not found, exiting\n")
sys.exit(1)
else:
not_found = not_found_dir = ""
@@ -233,12 +249,11 @@ def wic_create_subcommand(args, usage_str):
if not_found:
if not not_found_dir:
not_found_dir = "Completely missing artifact - wrong image (.wks) used?"
- print("Build artifacts not found, exiting.")
- print(" (Please check that the build artifacts for the machine")
- print(" selected in local.conf actually exist and that they")
- print(" are the correct artifacts for the image (.wks file)).\n")
- print("The artifact that couldn't be found was %s:\n %s" % \
- (not_found, not_found_dir))
+ logger.error("Build artifacts not found, exiting.")
+ logger.info(" (Please check that the build artifacts for the machine")
+ logger.info(" selected in local.conf actually exist and that they")
+ logger.info(" are the correct artifacts for the image (.wks file)).\n")
+ logger.info("The artifact that couldn't be found was %s:\n %s", not_found, not_found_dir)
sys.exit(1)
krootfs_dir = options.rootfs_dir
@@ -248,7 +263,7 @@ def wic_create_subcommand(args, usage_str):
rootfs_dir = rootfs_dir_to_args(krootfs_dir)
- print("Creating image(s)...\n")
+ logger.info("Creating image(s)...\n")
engine.wic_create(wks_file, rootfs_dir, bootimg_dir, kernel_dir,
native_sysroot, options)
@@ -262,7 +277,7 @@ def wic_list_subcommand(args, usage_str):
args = parser.parse_args(args)[1]
if not engine.wic_list(args, scripts_path):
- logging.error("Bad list arguments, exiting\n")
+ logger.error("Bad list arguments, exiting\n")
parser.print_help()
sys.exit(1)
@@ -299,10 +314,6 @@ subcommands = {
}
-def start_logging(loglevel):
- logging.basicConfig(filename='wic.log', filemode='w', level=loglevel)
-
-
def main(argv):
parser = optparse.OptionParser(version="wic version %s" % __version__,
usage=hlp.wic_usage)
@@ -324,6 +335,6 @@ if __name__ == "__main__":
try:
sys.exit(main(sys.argv[1:]))
except WicError as err:
- print("ERROR:", err, file=sys.stderr)
+ logger.error(err)
sys.exit(1)
--
2.1.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 02/11] wic: use wic logger in core modules
2017-02-15 8:38 [PATCH 00/11] wic refactoring (almost done) Ed Bartosh
2017-02-15 8:38 ` [PATCH 01/11] wic: setup logging in the main wic module Ed Bartosh
@ 2017-02-15 8:38 ` Ed Bartosh
2017-02-15 8:38 ` [PATCH 03/11] wic: use wic logger in imager direct plugin Ed Bartosh
` (8 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Ed Bartosh @ 2017-02-15 8:38 UTC (permalink / raw)
To: openembedded-core
Replaced msger with wic logger in the core wic modules.
Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
---
scripts/lib/wic/engine.py | 19 ++++++-----
scripts/lib/wic/help.py | 8 +++--
scripts/lib/wic/ksparser.py | 7 ++--
scripts/lib/wic/partition.py | 72 +++++++++++++++++++++++------------------
scripts/lib/wic/plugin.py | 19 +++++------
scripts/lib/wic/pluginbase.py | 12 ++++---
scripts/lib/wic/utils/misc.py | 32 ++++++++++--------
scripts/lib/wic/utils/runner.py | 12 ++++---
8 files changed, 104 insertions(+), 77 deletions(-)
diff --git a/scripts/lib/wic/engine.py b/scripts/lib/wic/engine.py
index 1aa8f65..b64714c 100644
--- a/scripts/lib/wic/engine.py
+++ b/scripts/lib/wic/engine.py
@@ -28,6 +28,7 @@
# Tom Zanussi <tom.zanussi (at] linux.intel.com>
#
+import logging
import os
import sys
@@ -35,6 +36,7 @@ from wic import msger
from wic.plugin import pluginmgr
from wic.utils.misc import get_bitbake_var
+logger = logging.getLogger('wic')
def verify_build_env():
"""
@@ -43,7 +45,7 @@ def verify_build_env():
Returns True if it is, false otherwise
"""
if not os.environ.get("BUILDDIR"):
- print("BUILDDIR not found, exiting. (Did you forget to source oe-init-build-env?)")
+ logger.error("BUILDDIR not found, exiting. (Did you forget to source oe-init-build-env?)")
sys.exit(1)
return True
@@ -179,7 +181,7 @@ def wic_create(wks_file, rootfs_dir, bootimg_dir, kernel_dir,
try:
oe_builddir = os.environ["BUILDDIR"]
except KeyError:
- print("BUILDDIR not found, exiting. (Did you forget to source oe-init-build-env?)")
+ logger.error("BUILDDIR not found, exiting. (Did you forget to source oe-init-build-env?)")
sys.exit(1)
if options.debug:
@@ -191,14 +193,15 @@ 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:
- msger.error('Unknown plugin: %s' % pname)
+ logger.error('Unknown plugin: %s', pname)
+ sys.exit(1)
plugin = plugin_class(wks_file, rootfs_dir, bootimg_dir, kernel_dir,
native_sysroot, oe_builddir, options)
plugin.do_create()
- print("\nThe image(s) were created using OE kickstart file:\n %s" % wks_file)
+ logger.info("The image(s) were created using OE kickstart file:\n %s", wks_file)
def wic_list(args, scripts_path):
@@ -218,10 +221,10 @@ def wic_list(args, scripts_path):
wks_file = args[0]
fullpath = find_canned_image(scripts_path, wks_file)
if not fullpath:
- print("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)
+ 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)
list_canned_image_help(scripts_path, fullpath)
return True
diff --git a/scripts/lib/wic/help.py b/scripts/lib/wic/help.py
index 1bd411d..9b980e7 100644
--- a/scripts/lib/wic/help.py
+++ b/scripts/lib/wic/help.py
@@ -30,8 +30,10 @@ import logging
from wic.plugin import pluginmgr, PLUGIN_TYPES
+logger = logging.getLogger('wic')
+
def subcommand_error(args):
- logging.info("invalid subcommand %s", args[0])
+ logger.info("invalid subcommand %s", args[0])
def display_help(subcommand, subcommands):
@@ -81,13 +83,13 @@ def invoke_subcommand(args, parser, main_command_usage, subcommands):
Should use argparse, but has to work in 2.6.
"""
if not args:
- logging.error("No subcommand specified, exiting")
+ logger.error("No subcommand specified, exiting")
parser.print_help()
return 1
elif args[0] == "help":
wic_help(args, main_command_usage, subcommands)
elif args[0] not in subcommands:
- logging.error("Unsupported subcommand %s, exiting\n", args[0])
+ logger.error("Unsupported subcommand %s, exiting\n", args[0])
parser.print_help()
return 1
else:
diff --git a/scripts/lib/wic/ksparser.py b/scripts/lib/wic/ksparser.py
index d9fa805..c840d89 100644
--- a/scripts/lib/wic/ksparser.py
+++ b/scripts/lib/wic/ksparser.py
@@ -27,12 +27,15 @@
import os
import shlex
+import logging
+
from argparse import ArgumentParser, ArgumentError, ArgumentTypeError
-from wic import msger
from wic.engine import find_canned
from wic.partition import Partition
+logger = logging.getLogger('wic')
+
class KickStartError(Exception):
"""Custom exception."""
pass
@@ -167,7 +170,7 @@ class KickStart():
self._parse(parser, confpath)
if not self.bootloader:
- msger.warning('bootloader config not specified, using defaults')
+ logger.warning('bootloader config not specified, using defaults\n')
self.bootloader = bootloader.parse_args([])
def _parse(self, parser, confpath):
diff --git a/scripts/lib/wic/partition.py b/scripts/lib/wic/partition.py
index 754ad75..349054f 100644
--- a/scripts/lib/wic/partition.py
+++ b/scripts/lib/wic/partition.py
@@ -24,13 +24,16 @@
# Tom Zanussi <tom.zanussi (at] linux.intel.com>
# Ed Bartosh <ed.bartosh> (at] linux.intel.com>
+import logging
import os
+import sys
import tempfile
-from wic import msger
from wic.utils.misc import exec_cmd, exec_native_cmd, get_bitbake_var
from wic.plugin import pluginmgr
+logger = logging.getLogger('wic')
+
class Partition():
def __init__(self, args, lineno):
@@ -68,16 +71,16 @@ class Partition():
number of (1k) blocks we need to add to get to --size, 0 if
we're already there or beyond.
"""
- msger.debug("Requested partition size for %s: %d" % \
- (self.mountpoint, self.size))
+ logger.debug("Requested partition size for %s: %d",
+ self.mountpoint, self.size)
if not self.size:
return 0
requested_blocks = self.size
- msger.debug("Requested blocks %d, current_blocks %d" % \
- (requested_blocks, current_blocks))
+ logger.debug("Requested blocks %d, current_blocks %d",
+ requested_blocks, current_blocks)
if requested_blocks > current_blocks:
return requested_blocks - current_blocks
@@ -95,8 +98,9 @@ class Partition():
if self.fixed_size:
rootfs_size = self.fixed_size
if actual_rootfs_size > rootfs_size:
- msger.error("Actual rootfs size (%d kB) is larger than allowed size %d kB" \
- %(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)
else:
extra_blocks = self.get_extra_block_count(actual_rootfs_size)
if extra_blocks < self.extra_space:
@@ -105,8 +109,8 @@ class Partition():
rootfs_size = actual_rootfs_size + extra_blocks
rootfs_size *= self.overhead_factor
- msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \
- (extra_blocks, self.mountpoint, rootfs_size))
+ logger.debug("Added %d extra blocks to %s to get to %d total blocks",
+ extra_blocks, self.mountpoint, rootfs_size)
return rootfs_size
@@ -127,9 +131,10 @@ class Partition():
"""
if not self.source:
if not self.size and not self.fixed_size:
- msger.error("The %s partition has a size of zero. Please "
- "specify a non-zero --size/--fixed-size for that partition." % \
- self.mountpoint)
+ 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)
if self.fstype and self.fstype == "swap":
self.prepare_swap_partition(cr_workdir, oe_builddir,
native_sysroot)
@@ -151,11 +156,12 @@ class Partition():
plugins = pluginmgr.get_source_plugins()
if self.source not in plugins:
- msger.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))
+ 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)
srcparams_dict = {}
if self.sourceparams:
@@ -185,15 +191,16 @@ class Partition():
# further processing required Partition.size to be an integer, make
# sure that it is one
if not isinstance(self.size, int):
- msger.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))
+ 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)
if self.fixed_size and self.size > self.fixed_size:
- msger.error("File system image of partition %s is larger (%d kB) than its"\
- "allowed size %d kB" % (self.mountpoint,
- 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)
def prepare_rootfs_from_fs_image(self, cr_workdir, oe_builddir,
rootfs_dir):
@@ -233,8 +240,9 @@ class Partition():
os.remove(rootfs)
if not self.fstype:
- msger.error("File system for partition %s not specified in kickstart, " \
- "use --fstype option" % (self.mountpoint))
+ logger.error("File system for partition %s not specified in kickstart, "
+ "use --fstype option", self.mountpoint)
+ sys.exit(1)
# Get rootfs size from bitbake variable if it's not set in .ks file
if not self.size:
@@ -244,10 +252,10 @@ class Partition():
# IMAGE_OVERHEAD_FACTOR and IMAGE_ROOTFS_EXTRA_SPACE
rsize_bb = get_bitbake_var('ROOTFS_SIZE')
if rsize_bb:
- msger.warning('overhead-factor was specified, but size was not,'
- ' so bitbake variables will be used for the size.'
- ' In this case both IMAGE_OVERHEAD_FACTOR and '
- '--overhead-factor will be applied')
+ logger.warning('overhead-factor was specified, but size was not,'
+ ' so bitbake variables will be used for the size.'
+ ' In this case both IMAGE_OVERHEAD_FACTOR and '
+ '--overhead-factor will be applied')
self.size = int(round(float(rsize_bb)))
for prefix in ("ext", "btrfs", "vfat", "squashfs"):
@@ -403,8 +411,8 @@ class Partition():
"""
Prepare an empty squashfs partition.
"""
- msger.warning("Creating of an empty squashfs %s partition was attempted. " \
- "Proceeding as requested." % self.mountpoint)
+ logger.warning("Creating of an empty squashfs %s partition was attempted. "
+ "Proceeding as requested.", self.mountpoint)
path = "%s/fs_%s.%s" % (cr_workdir, self.label, self.fstype)
if os.path.isfile(path):
diff --git a/scripts/lib/wic/plugin.py b/scripts/lib/wic/plugin.py
index f04a034..70d3377 100644
--- a/scripts/lib/wic/plugin.py
+++ b/scripts/lib/wic/plugin.py
@@ -17,8 +17,8 @@
import os
import sys
+import logging
-from wic import msger
from wic import pluginbase
from wic.utils import errors
from wic.utils.misc import get_bitbake_var
@@ -30,6 +30,8 @@ PLUGIN_TYPES = ["imager", "source"]
PLUGIN_DIR = "/lib/wic/plugins" # relative to scripts
SCRIPTS_PLUGIN_DIR = "scripts" + PLUGIN_DIR
+logger = logging.getLogger('wic')
+
class PluginMgr():
plugin_dirs = {}
@@ -91,17 +93,16 @@ class PluginMgr():
if mod and mod != '__init__':
if mod in sys.modules:
#self.plugin_dirs[pdir] = True
- msger.warning("Module %s already exists, skip" % mod)
+ logger.warning("Module %s already exists, skip", mod)
else:
try:
pymod = __import__(mod)
self.plugin_dirs[pdir] = True
- msger.debug("Plugin module %s:%s imported"\
- % (mod, pymod.__file__))
+ logger.debug("Plugin module %s:%s imported",
+ mod, pymod.__file__)
except ImportError as err:
- msg = 'Failed to load plugin %s/%s: %s' \
- % (os.path.basename(pdir), mod, err)
- msger.warning(msg)
+ logger.warning('Failed to load plugin %s/%s: %s',
+ os.path.basename(pdir), mod, err)
del sys.path[0]
@@ -140,8 +141,8 @@ class PluginMgr():
if _source_name == source_name:
for _method_name in methods:
if not hasattr(klass, _method_name):
- msger.warning("Unimplemented %s source interface for: %s"\
- % (_method_name, _source_name))
+ logger.warning("Unimplemented %s source interface for: %s",
+ _method_name, _source_name)
return None
func = getattr(klass, _method_name)
methods[_method_name] = func
diff --git a/scripts/lib/wic/pluginbase.py b/scripts/lib/wic/pluginbase.py
index 2f747a9..aea9c02 100644
--- a/scripts/lib/wic/pluginbase.py
+++ b/scripts/lib/wic/pluginbase.py
@@ -17,9 +17,11 @@
__all__ = ['ImagerPlugin', 'SourcePlugin', 'get_plugins']
+import logging
+
from collections import defaultdict
-from wic import msger
+logger = logging.getLogger('wic')
class PluginMeta(type):
plugins = defaultdict(dict)
@@ -49,7 +51,7 @@ class SourcePlugin(PluginMeta("Plugin", (), {})):
disk image. This provides a hook to allow finalization of a
disk image e.g. to write an MBR to it.
"""
- msger.debug("SourcePlugin: do_install_disk: disk: %s" % disk_name)
+ logger.debug("SourcePlugin: do_install_disk: disk: %s", disk_name)
@classmethod
def do_stage_partition(cls, part, source_params, creator, cr_workdir,
@@ -66,7 +68,7 @@ class SourcePlugin(PluginMeta("Plugin", (), {})):
Not that get_bitbake_var() allows you to acces non-standard
variables that you might want to use for this.
"""
- msger.debug("SourcePlugin: do_stage_partition: part: %s" % part)
+ logger.debug("SourcePlugin: do_stage_partition: part: %s", part)
@classmethod
def do_configure_partition(cls, part, source_params, creator, cr_workdir,
@@ -77,7 +79,7 @@ class SourcePlugin(PluginMeta("Plugin", (), {})):
custom configuration files for a partition, for example
syslinux or grub config files.
"""
- msger.debug("SourcePlugin: do_configure_partition: part: %s" % part)
+ logger.debug("SourcePlugin: do_configure_partition: part: %s", part)
@classmethod
def do_prepare_partition(cls, part, source_params, creator, cr_workdir,
@@ -87,7 +89,7 @@ class SourcePlugin(PluginMeta("Plugin", (), {})):
Called to do the actual content population for a partition i.e. it
'prepares' the partition to be incorporated into the image.
"""
- msger.debug("SourcePlugin: do_prepare_partition: part: %s" % part)
+ logger.debug("SourcePlugin: do_prepare_partition: part: %s", part)
def get_plugins(typen):
return PluginMeta.plugins.get(typen)
diff --git a/scripts/lib/wic/utils/misc.py b/scripts/lib/wic/utils/misc.py
index edb9c5b..b7b835a 100644
--- a/scripts/lib/wic/utils/misc.py
+++ b/scripts/lib/wic/utils/misc.py
@@ -26,14 +26,17 @@
#
"""Miscellaneous functions."""
+import logging
import os
import re
+
from collections import defaultdict
from distutils import spawn
-from wic import msger
from wic.utils import runner
+logger = logging.getLogger('wic')
+
# executable -> recipe pairs for exec_native_cmd
NATIVE_RECIPES = {"bmaptool": "bmap-tools",
"grub-mkimage": "grub-efi",
@@ -61,9 +64,9 @@ def _exec_cmd(cmd_and_args, as_shell=False, catch=3):
Need to execute as_shell if the command uses wildcards
"""
- msger.debug("_exec_cmd: %s" % cmd_and_args)
+ logger.debug("_exec_cmd: %s", cmd_and_args)
args = cmd_and_args.split()
- msger.debug(args)
+ logger.debug(args)
if as_shell:
ret, out = runner.runtool(cmd_and_args, catch)
@@ -71,11 +74,12 @@ def _exec_cmd(cmd_and_args, as_shell=False, catch=3):
ret, out = runner.runtool(args, catch)
out = out.strip()
if ret != 0:
- msger.error("_exec_cmd: %s returned '%s' instead of 0\noutput: %s" % \
+ logger.error("_exec_cmd: %s returned '%s' instead of 0\noutput: %s" % \
(cmd_and_args, ret, out))
+ sys.exit(1)
- msger.debug("_exec_cmd: output for %s (rc = %d): %s" % \
- (cmd_and_args, ret, out))
+ logger.debug("_exec_cmd: output for %s (rc = %d): %s",
+ cmd_and_args, ret, out)
return ret, out
@@ -97,7 +101,7 @@ def exec_native_cmd(cmd_and_args, native_sysroot, catch=3, pseudo=""):
"""
# The reason -1 is used is because there may be "export" commands.
args = cmd_and_args.split(';')[-1].split()
- msger.debug(args)
+ logger.debug(args)
if pseudo:
cmd_and_args = pseudo + cmd_and_args
@@ -106,7 +110,7 @@ def exec_native_cmd(cmd_and_args, native_sysroot, catch=3, pseudo=""):
(native_sysroot, native_sysroot, native_sysroot)
native_cmd_and_args = "export PATH=%s:$PATH;%s" % \
(native_paths, cmd_and_args)
- msger.debug("exec_native_cmd: %s" % cmd_and_args)
+ logger.debug("exec_native_cmd: %s", cmd_and_args)
# If the command isn't in the native sysroot say we failed.
if spawn.find_executable(args[0], native_paths):
@@ -127,7 +131,7 @@ def exec_native_cmd(cmd_and_args, native_sysroot, catch=3, pseudo=""):
else:
msg += "Wic failed to find a recipe to build native %s. Please "\
"file a bug against wic.\n" % prog
- msger.error(msg)
+ logger.error(msg)
return ret, out
@@ -184,14 +188,14 @@ class BitbakeVars(defaultdict):
if image:
cmd += " %s" % image
- log_level = msger.get_loglevel()
- msger.set_loglevel('normal')
+ log_level = logger.getEffectiveLevel()
+ logger.setLevel(logging.INFO)
ret, lines = _exec_cmd(cmd)
- msger.set_loglevel(log_level)
+ logger.setLevel(log_level)
if ret:
- print("Couldn't get '%s' output." % cmd)
- print("Bitbake failed with error:\n%s\n" % lines)
+ logger.error("Couldn't get '%s' output.", cmd)
+ logger.error("Bitbake failed with error:\n%s\n", lines)
return
# Parse bitbake -e output
diff --git a/scripts/lib/wic/utils/runner.py b/scripts/lib/wic/utils/runner.py
index db536ba..d27dcc7 100644
--- a/scripts/lib/wic/utils/runner.py
+++ b/scripts/lib/wic/utils/runner.py
@@ -15,10 +15,12 @@
# with this program; if not, write to the Free Software Foundation, Inc., 59
# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+import logging
import os
import subprocess
+import sys
-from wic import msger
+logger = logging.getLogger('wic')
def runtool(cmdln_or_args, catch=1):
""" wrapper for most of the subprocess calls
@@ -70,7 +72,8 @@ def runtool(cmdln_or_args, catch=1):
except OSError as err:
if err.errno == 2:
# [Errno 2] No such file or directory
- msger.error('Cannot run command: %s, lost dependency?' % cmd)
+ logger.error('Cannot run command: %s, lost dependency?', cmd)
+ sys.exit(1)
else:
raise # relay
finally:
@@ -80,7 +83,7 @@ def runtool(cmdln_or_args, catch=1):
return (process.returncode, out)
def show(cmdln_or_args):
- # show all the message using msger.verbose
+ """Show all messages using logger.debug."""
rcode, out = runtool(cmdln_or_args, catch=3)
@@ -99,7 +102,8 @@ def show(cmdln_or_args):
msg += '\n | %s' % line
msg += '\n +----------------'
- msger.verbose(msg)
+ logger.debug(msg)
+
return rcode
def outs(cmdln_or_args, catch=1):
--
2.1.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 03/11] wic: use wic logger in imager direct plugin
2017-02-15 8:38 [PATCH 00/11] wic refactoring (almost done) Ed Bartosh
2017-02-15 8:38 ` [PATCH 01/11] wic: setup logging in the main wic module Ed Bartosh
2017-02-15 8:38 ` [PATCH 02/11] wic: use wic logger in core modules Ed Bartosh
@ 2017-02-15 8:38 ` Ed Bartosh
2017-02-15 8:38 ` [PATCH 04/11] wic: use wic logger in wic source plugins Ed Bartosh
` (7 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Ed Bartosh @ 2017-02-15 8:38 UTC (permalink / raw)
To: openembedded-core
Replaced msger with wic logger in the direct plugin.
Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
---
scripts/lib/wic/plugins/imager/direct.py | 83 +++++++++++++++++---------------
1 file changed, 43 insertions(+), 40 deletions(-)
diff --git a/scripts/lib/wic/plugins/imager/direct.py b/scripts/lib/wic/plugins/imager/direct.py
index 481d24d..2e2d26a 100644
--- a/scripts/lib/wic/plugins/imager/direct.py
+++ b/scripts/lib/wic/plugins/imager/direct.py
@@ -23,14 +23,16 @@
# AUTHORS
# Tom Zanussi <tom.zanussi (at] linux.intel.com>
#
+
+import logging
import os
import shutil
-import uuid
+import sys
import tempfile
+import uuid
from time import strftime
-from wic import msger
from wic.filemap import sparse_copy
from wic.ksparser import KickStart, KickStartError
from wic.plugin import pluginmgr
@@ -38,6 +40,8 @@ from wic.pluginbase import ImagerPlugin
from wic.utils.errors import ImageError
from wic.utils.misc import get_bitbake_var, exec_cmd, exec_native_cmd
+logger = logging.getLogger('wic')
+
class DirectPlugin(ImagerPlugin):
"""
Install a system into a file containing a partitioned disk image.
@@ -54,7 +58,8 @@ class DirectPlugin(ImagerPlugin):
try:
self.ks = KickStart(wks_file)
except KickStartError as err:
- msger.error(str(err))
+ logger.error(str(err))
+ sys.exit(1)
# parse possible 'rootfs=name' items
self.rootfs_dir = dict(rdir.split('=') for rdir in rootfs_dir.split(' '))
@@ -204,12 +209,12 @@ class DirectPlugin(ImagerPlugin):
full_path = self._image.path
# Generate .bmap
if self.bmap:
- msger.debug("Generating bmap file for %s" % disk_name)
+ logger.debug("Generating bmap file for %s", disk_name)
exec_native_cmd("bmaptool create %s -o %s.bmap" % (full_path, full_path),
self.native_sysroot)
# Compress the image
if self.compressor:
- msger.debug("Compressing disk %s with %s" % (disk_name, self.compressor))
+ logger.debug("Compressing disk %s with %s", disk_name, self.compressor)
exec_cmd("%s %s" % (self.compressor, full_path))
def print_info(self):
@@ -239,7 +244,7 @@ class DirectPlugin(ImagerPlugin):
msg += ' KERNEL_DIR: %s\n' % self.kernel_dir
msg += ' NATIVE_SYSROOT: %s\n' % self.native_sysroot
- msger.info(msg)
+ logger.info(msg)
@property
def rootdev(self):
@@ -342,7 +347,7 @@ class PartitionedImage():
partition on the disk. The 'ptable_format' parameter defines the
partition table format and may be "msdos". """
- msger.debug("Assigning %s partitions to disks" % self.ptable_format)
+ logger.debug("Assigning %s partitions to disks", self.ptable_format)
# Go through partitions in the order they are added in .ks file
for num in range(len(self.partitions)):
@@ -389,10 +394,10 @@ class PartitionedImage():
# to move forward to the next alignment point
align_sectors = (part.align * 1024 // self.sector_size) - align_sectors
- msger.debug("Realignment for %s%s with %s sectors, original"
- " offset %s, target alignment is %sK." %
- (part.disk, self.numpart, align_sectors,
- self.offset, part.align))
+ logger.debug("Realignment for %s%s with %s sectors, original"
+ " offset %s, target alignment is %sK.",
+ part.disk, self.numpart, align_sectors,
+ self.offset, part.align)
# increase the offset so we actually start the partition on right alignment
self.offset += align_sectors
@@ -413,11 +418,10 @@ class PartitionedImage():
part.type = 'logical'
part.num = self.realpart + 1
- msger.debug("Assigned %s to %s%d, sectors range %d-%d size %d "
- "sectors (%d bytes)." \
- % (part.mountpoint, part.disk, part.num,
- part.start, self.offset - 1,
- part.size_sec, part.size_sec * self.sector_size))
+ logger.debug("Assigned %s to %s%d, sectors range %d-%d size %d "
+ "sectors (%d bytes).", part.mountpoint, part.disk,
+ part.num, part.start, self.offset - 1, part.size_sec,
+ part.size_sec * self.sector_size)
# Once all the partitions have been layed out, we can calculate the
# minumim disk size
@@ -432,8 +436,8 @@ class PartitionedImage():
# Start is included to the size so we need to substract one from the end.
end = start + size - 1
- msger.debug("Added '%s' partition, sectors %d-%d, size %d sectors" %
- (parttype, start, end, size))
+ logger.debug("Added '%s' partition, sectors %d-%d, size %d sectors",
+ parttype, start, end, size)
cmd = "parted -s %s unit s mkpart %s" % (device, parttype)
if fstype:
@@ -443,20 +447,20 @@ class PartitionedImage():
return exec_native_cmd(cmd, self.native_sysroot)
def create(self):
- msger.debug("Creating sparse file %s" % self.path)
+ logger.debug("Creating sparse file %s", self.path)
with open(self.path, 'w') as sparse:
os.ftruncate(sparse.fileno(), self.min_size)
- msger.debug("Initializing partition table for %s" % self.path)
+ logger.debug("Initializing partition table for %s", self.path)
exec_native_cmd("parted -s %s mklabel %s" %
(self.path, self.ptable_format), self.native_sysroot)
- msger.debug("Set disk identifier %x" % self.identifier)
+ logger.debug("Set disk identifier %x", self.identifier)
with open(self.path, 'r+b') as img:
img.seek(0x1B8)
img.write(self.identifier.to_bytes(4, 'little'))
- msger.debug("Creating partitions")
+ logger.debug("Creating partitions")
for part in self.partitions:
if part.num == 0:
@@ -494,39 +498,39 @@ class PartitionedImage():
# even number of sectors.
if part.mountpoint == "/boot" and part.fstype in ["vfat", "msdos"] \
and part.size_sec % 2:
- msger.debug("Subtracting one sector from '%s' partition to " \
- "get even number of sectors for the partition" % \
- part.mountpoint)
+ logger.debug("Subtracting one sector from '%s' partition to "
+ "get even number of sectors for the partition",
+ part.mountpoint)
part.size_sec -= 1
self._create_partition(self.path, part.type,
parted_fs_type, part.start, part.size_sec)
if part.part_type:
- msger.debug("partition %d: set type UID to %s" % \
- (part.num, part.part_type))
+ logger.debug("partition %d: set type UID to %s",
+ part.num, part.part_type)
exec_native_cmd("sgdisk --typecode=%d:%s %s" % \
(part.num, part.part_type,
self.path), self.native_sysroot)
if part.uuid and self.ptable_format == "gpt":
- msger.debug("partition %d: set UUID to %s" % \
- (part.num, part.uuid))
+ logger.debug("partition %d: set UUID to %s",
+ part.num, part.uuid)
exec_native_cmd("sgdisk --partition-guid=%d:%s %s" % \
(part.num, part.uuid, self.path),
self.native_sysroot)
if part.label and self.ptable_format == "gpt":
- msger.debug("partition %d: set name to %s" % \
- (part.num, part.label))
+ logger.debug("partition %d: set name to %s",
+ part.num, part.label)
exec_native_cmd("parted -s %s name %d %s" % \
(self.path, part.num, part.label),
self.native_sysroot)
if part.active:
flag_name = "legacy_boot" if self.ptable_format == 'gpt' else "boot"
- msger.debug("Set '%s' flag for partition '%s' on disk '%s'" % \
- (flag_name, part.num, self.path))
+ logger.debug("Set '%s' flag for partition '%s' on disk '%s'",
+ flag_name, part.num, self.path)
exec_native_cmd("parted -s %s set %d %s on" % \
(self.path, part.num, flag_name),
self.native_sysroot)
@@ -540,8 +544,8 @@ class PartitionedImage():
# isn't necessary).
if parted_fs_type == "fat16":
if self.ptable_format == 'msdos':
- msger.debug("Disable 'lba' flag for partition '%s' on disk '%s'" % \
- (part.num, self.path))
+ logger.debug("Disable 'lba' flag for partition '%s' on disk '%s'",
+ part.num, self.path)
exec_native_cmd("parted -s %s set %d lba off" % \
(self.path, part.num),
self.native_sysroot)
@@ -552,7 +556,7 @@ class PartitionedImage():
os.remove(image)
def assemble(self):
- msger.debug("Installing partitions")
+ logger.debug("Installing partitions")
for part in self.partitions:
source = part.source_file
@@ -560,10 +564,9 @@ class PartitionedImage():
# install source_file contents into a partition
sparse_copy(source, self.path, part.start * self.sector_size)
- msger.debug("Installed %s in partition %d, sectors %d-%d, "
- "size %d sectors" % \
- (source, part.num, part.start,
- part.start + part.size_sec - 1, part.size_sec))
+ logger.debug("Installed %s in partition %d, sectors %d-%d, "
+ "size %d sectors", source, part.num, part.start,
+ part.start + part.size_sec - 1, part.size_sec)
partimage = self.path + '.p%d' % part.num
os.rename(source, partimage)
--
2.1.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 04/11] wic: use wic logger in wic source plugins
2017-02-15 8:38 [PATCH 00/11] wic refactoring (almost done) Ed Bartosh
` (2 preceding siblings ...)
2017-02-15 8:38 ` [PATCH 03/11] wic: use wic logger in imager direct plugin Ed Bartosh
@ 2017-02-15 8:38 ` Ed Bartosh
2017-02-15 8:38 ` [PATCH 05/11] wic: remove msger module Ed Bartosh
` (6 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Ed Bartosh @ 2017-02-15 8:38 UTC (permalink / raw)
To: openembedded-core
Replaced msger with wic logger in wic source plugins.
Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
---
scripts/lib/wic/plugins/source/bootimg-efi.py | 60 ++++++++------
.../lib/wic/plugins/source/bootimg-partition.py | 28 ++++---
scripts/lib/wic/plugins/source/bootimg-pcbios.py | 41 +++++----
scripts/lib/wic/plugins/source/fsimage.py | 16 ++--
.../lib/wic/plugins/source/isoimage-isohybrid.py | 96 +++++++++++++---------
scripts/lib/wic/plugins/source/rawcopy.py | 14 ++--
scripts/lib/wic/plugins/source/rootfs.py | 24 +++---
.../lib/wic/plugins/source/rootfs_pcbios_ext.py | 56 +++++++------
8 files changed, 200 insertions(+), 135 deletions(-)
diff --git a/scripts/lib/wic/plugins/source/bootimg-efi.py b/scripts/lib/wic/plugins/source/bootimg-efi.py
index 95316c8..e4c8451 100644
--- a/scripts/lib/wic/plugins/source/bootimg-efi.py
+++ b/scripts/lib/wic/plugins/source/bootimg-efi.py
@@ -24,15 +24,18 @@
# Tom Zanussi <tom.zanussi (at] linux.intel.com>
#
+import logging
import os
import shutil
+import sys
-from wic import msger
from wic.engine import get_custom_config
from wic.pluginbase import SourcePlugin
from wic.utils.misc import (exec_cmd, exec_native_cmd, get_bitbake_var,
BOOTDD_EXTRA_SPACE)
+logger = logging.getLogger('wic')
+
class BootimgEFIPlugin(SourcePlugin):
"""
Create EFI boot partition.
@@ -53,11 +56,12 @@ class BootimgEFIPlugin(SourcePlugin):
if custom_cfg:
# Use a custom configuration for grub
grubefi_conf = custom_cfg
- msger.debug("Using custom configuration file "
- "%s for grub.cfg" % configfile)
+ logger.debug("Using custom configuration file "
+ "%s for grub.cfg", configfile)
else:
- msger.error("configfile is specified but failed to "
- "get it from %s." % configfile)
+ logger.error("configfile is specified but failed to "
+ "get it from %s.", configfile)
+ sys.exit(1)
if not custom_cfg:
# Create grub configuration using parameters from wks file
@@ -75,8 +79,8 @@ class BootimgEFIPlugin(SourcePlugin):
% (kernel, creator.rootdev, bootloader.append)
grubefi_conf += "}\n"
- msger.debug("Writing grubefi config %s/hdd/boot/EFI/BOOT/grub.cfg" \
- % cr_workdir)
+ logger.debug("Writing grubefi config %s/hdd/boot/EFI/BOOT/grub.cfg",
+ cr_workdir)
cfg = open("%s/hdd/boot/EFI/BOOT/grub.cfg" % cr_workdir, "w")
cfg.write(grubefi_conf)
cfg.close()
@@ -104,15 +108,16 @@ class BootimgEFIPlugin(SourcePlugin):
# obviously we need to have a common common deploy var
bootimg_dir = get_bitbake_var("DEPLOY_DIR_IMAGE")
if not bootimg_dir:
- msger.error("Couldn't find DEPLOY_DIR_IMAGE, exiting\n")
+ logger.error("Couldn't find DEPLOY_DIR_IMAGE, exiting\n")
+ sys.exit(1)
cp_cmd = "cp %s/%s %s" % (bootimg_dir, initrd, hdddir)
exec_cmd(cp_cmd, True)
else:
- msger.debug("Ignoring missing initrd")
+ logger.debug("Ignoring missing initrd")
- msger.debug("Writing systemd-boot config %s/hdd/boot/loader/loader.conf" \
- % cr_workdir)
+ logger.debug("Writing systemd-boot config "
+ "%s/hdd/boot/loader/loader.conf", cr_workdir)
cfg = open("%s/hdd/boot/loader/loader.conf" % cr_workdir, "w")
cfg.write(loader_conf)
cfg.close()
@@ -124,11 +129,12 @@ class BootimgEFIPlugin(SourcePlugin):
if custom_cfg:
# Use a custom configuration for systemd-boot
boot_conf = custom_cfg
- msger.debug("Using custom configuration file "
- "%s for systemd-boots's boot.conf" % configfile)
+ logger.debug("Using custom configuration file "
+ "%s for systemd-boots's boot.conf", configfile)
else:
- msger.error("configfile is specified but failed to "
- "get it from %s." % configfile)
+ logger.error("configfile is specified but failed to "
+ "get it from %s.", configfile)
+ sys.exit(1)
if not custom_cfg:
# Create systemd-boot configuration using parameters from wks file
@@ -143,8 +149,8 @@ class BootimgEFIPlugin(SourcePlugin):
if initrd:
boot_conf += "initrd /%s\n" % initrd
- msger.debug("Writing systemd-boot config %s/hdd/boot/loader/entries/boot.conf" \
- % cr_workdir)
+ logger.debug("Writing systemd-boot config "
+ "%s/hdd/boot/loader/entries/boot.conf", cr_workdir)
cfg = open("%s/hdd/boot/loader/entries/boot.conf" % cr_workdir, "w")
cfg.write(boot_conf)
cfg.close()
@@ -168,9 +174,11 @@ class BootimgEFIPlugin(SourcePlugin):
elif source_params['loader'] == 'systemd-boot':
cls.do_configure_systemdboot(hdddir, creator, cr_workdir, source_params)
else:
- msger.error("unrecognized bootimg-efi loader: %s" % source_params['loader'])
+ logger.error("unrecognized bootimg-efi loader: %s", source_params['loader'])
+ sys.exit(1)
except KeyError:
- msger.error("bootimg-efi requires a loader, none specified")
+ logger.error("bootimg-efi requires a loader, none specified")
+ sys.exit(1)
@classmethod
@@ -185,7 +193,8 @@ class BootimgEFIPlugin(SourcePlugin):
if not bootimg_dir:
bootimg_dir = get_bitbake_var("DEPLOY_DIR_IMAGE")
if not bootimg_dir:
- msger.error("Couldn't find DEPLOY_DIR_IMAGE, exiting\n")
+ logger.error("Couldn't find DEPLOY_DIR_IMAGE, exiting\n")
+ sys.exit(1)
# just so the result notes display it
creator.bootimg_dir = bootimg_dir
@@ -212,9 +221,12 @@ class BootimgEFIPlugin(SourcePlugin):
cp_cmd = "cp %s/%s %s/EFI/BOOT/%s" % (bootimg_dir, mod, hdddir, mod[8:])
exec_cmd(cp_cmd, True)
else:
- msger.error("unrecognized bootimg-efi loader: %s" % source_params['loader'])
+ logger.error("unrecognized bootimg-efi loader: %s",
+ source_params['loader'])
+ sys.exit(1)
except KeyError:
- msger.error("bootimg-efi requires a loader, none specified")
+ logger.error("bootimg-efi requires a loader, none specified")
+ sys.exit(1)
startup = os.path.join(bootimg_dir, "startup.nsh")
if os.path.exists(startup):
@@ -232,8 +244,8 @@ class BootimgEFIPlugin(SourcePlugin):
blocks += extra_blocks
- msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \
- (extra_blocks, part.mountpoint, blocks))
+ logger.debug("Added %d extra blocks to %s to get to %d total blocks",
+ extra_blocks, part.mountpoint, blocks)
# dosfs image, created by mkdosfs
bootimg = "%s/boot.img" % cr_workdir
diff --git a/scripts/lib/wic/plugins/source/bootimg-partition.py b/scripts/lib/wic/plugins/source/bootimg-partition.py
index e0d9a50..b486915 100644
--- a/scripts/lib/wic/plugins/source/bootimg-partition.py
+++ b/scripts/lib/wic/plugins/source/bootimg-partition.py
@@ -23,15 +23,18 @@
# Maciej Borzecki <maciej.borzecki (at] open-rnd.pl>
#
+import logging
import os
import re
+import sys
from glob import glob
-from wic import msger
from wic.pluginbase import SourcePlugin
from wic.utils.misc import exec_cmd, get_bitbake_var
+logger = logging.getLogger('wic')
+
class BootimgPartitionPlugin(SourcePlugin):
"""
Create an image of boot partition, copying over files
@@ -78,16 +81,18 @@ class BootimgPartitionPlugin(SourcePlugin):
if not bootimg_dir:
bootimg_dir = get_bitbake_var("DEPLOY_DIR_IMAGE")
if not bootimg_dir:
- msger.error("Couldn't find DEPLOY_DIR_IMAGE, exiting\n")
+ logger.error("Couldn't find DEPLOY_DIR_IMAGE, exiting\n")
+ sys.exit(1)
- msger.debug('Bootimg dir: %s' % bootimg_dir)
+ logger.debug('Bootimg dir: %s', bootimg_dir)
boot_files = get_bitbake_var("IMAGE_BOOT_FILES")
if not boot_files:
- msger.error('No boot files defined, IMAGE_BOOT_FILES unset')
+ logger.error('No boot files defined, IMAGE_BOOT_FILES unset')
+ sys.exit(1)
- msger.debug('Boot files: %s' % boot_files)
+ logger.debug('Boot files: %s', boot_files)
# list of tuples (src_name, dst_name)
deploy_files = []
@@ -95,11 +100,12 @@ class BootimgPartitionPlugin(SourcePlugin):
if ';' in src_entry:
dst_entry = tuple(src_entry.split(';'))
if not dst_entry[0] or not dst_entry[1]:
- msger.error('Malformed boot file entry: %s' % (src_entry))
+ logger.error('Malformed boot file entry: %s', src_entry)
+ sys.exit(1)
else:
dst_entry = (src_entry, src_entry)
- msger.debug('Destination entry: %r' % (dst_entry,))
+ logger.debug('Destination entry: %r', dst_entry)
deploy_files.append(dst_entry)
for deploy_entry in deploy_files:
@@ -117,7 +123,7 @@ class BootimgPartitionPlugin(SourcePlugin):
srcs = glob(os.path.join(bootimg_dir, src))
- msger.debug('Globbed sources: %s' % (', '.join(srcs)))
+ logger.debug('Globbed sources: %s', ', '.join(srcs))
for entry in srcs:
entry_dst_name = entry_name_fn(entry)
install_task.append((entry,
@@ -129,12 +135,12 @@ class BootimgPartitionPlugin(SourcePlugin):
for task in install_task:
src_path, dst_path = task
- msger.debug('Install %s as %s' % (os.path.basename(src_path),
- dst_path))
+ logger.debug('Install %s as %s',
+ os.path.basename(src_path), dst_path)
install_cmd = "install -m 0644 -D %s %s" \
% (src_path, dst_path)
exec_cmd(install_cmd)
- msger.debug('Prepare boot partition using rootfs in %s' % (hdddir))
+ logger.debug('Prepare boot partition using rootfs in %s', hdddir)
part.prepare_rootfs(cr_workdir, oe_builddir, hdddir,
native_sysroot)
diff --git a/scripts/lib/wic/plugins/source/bootimg-pcbios.py b/scripts/lib/wic/plugins/source/bootimg-pcbios.py
index e5f6a32..590d3d6 100644
--- a/scripts/lib/wic/plugins/source/bootimg-pcbios.py
+++ b/scripts/lib/wic/plugins/source/bootimg-pcbios.py
@@ -24,9 +24,10 @@
# Tom Zanussi <tom.zanussi (at] linux.intel.com>
#
+import logging
import os
+import sys
-from wic import msger
from wic.engine import get_custom_config
from wic.utils import runner
from wic.utils.errors import ImageError
@@ -34,6 +35,8 @@ from wic.pluginbase import SourcePlugin
from wic.utils.misc import (exec_cmd, exec_native_cmd,
get_bitbake_var, BOOTDD_EXTRA_SPACE)
+logger = logging.getLogger('wic')
+
class BootimgPcbiosPlugin(SourcePlugin):
"""
Create MBR boot partition and install syslinux on it.
@@ -54,16 +57,18 @@ class BootimgPcbiosPlugin(SourcePlugin):
elif creator.ptable_format == 'gpt':
mbrfile += "gptmbr.bin"
else:
- msger.error("Unsupported partition table: %s" % creator.ptable_format)
+ logger.error("Unsupported partition table: %s", creator.ptable_format)
+ sys.exit(1)
if not os.path.exists(mbrfile):
- msger.error("Couldn't find %s. If using the -e option, do you "
- "have the right MACHINE set in local.conf? If not, "
- "is the bootimg_dir path correct?" % mbrfile)
+ logger.error("Couldn't find %s. If using the -e option, do you "
+ "have the right MACHINE set in local.conf? If not, "
+ "is the bootimg_dir path correct?", mbrfile)
+ sys.exit(1)
full_path = creator._full_path(workdir, disk_name, "direct")
- msger.debug("Installing MBR on disk %s as %s with size %s bytes" \
- % (disk_name, full_path, disk.min_size))
+ logger.debug("Installing MBR on disk %s as %s with size %s bytes",
+ disk_name, full_path, disk.min_size)
rcode = runner.show(['dd', 'if=%s' % mbrfile,
'of=%s' % full_path, 'conv=notrunc'])
@@ -90,11 +95,11 @@ class BootimgPcbiosPlugin(SourcePlugin):
if custom_cfg:
# Use a custom configuration for grub
syslinux_conf = custom_cfg
- msger.debug("Using custom configuration file "
- "%s for syslinux.cfg" % bootloader.configfile)
+ logger.debug("Using custom configuration file %s "
+ "for syslinux.cfg", bootloader.configfile)
else:
- msger.error("configfile is specified but failed to "
- "get it from %s." % bootloader.configfile)
+ logger.error("configfile is specified but failed to "
+ "get it from %s.", bootloader.configfile)
if not custom_cfg:
# Create syslinux configuration using parameters from wks file
@@ -122,8 +127,8 @@ class BootimgPcbiosPlugin(SourcePlugin):
syslinux_conf += "APPEND label=boot root=%s %s\n" % \
(creator.rootdev, bootloader.append)
- msger.debug("Writing syslinux config %s/hdd/boot/syslinux.cfg" \
- % cr_workdir)
+ logger.debug("Writing syslinux config %s/hdd/boot/syslinux.cfg",
+ cr_workdir)
cfg = open("%s/hdd/boot/syslinux.cfg" % cr_workdir, "w")
cfg.write(syslinux_conf)
cfg.close()
@@ -147,9 +152,11 @@ class BootimgPcbiosPlugin(SourcePlugin):
if not _has_syslinux(bootimg_dir):
bootimg_dir = get_bitbake_var("STAGING_DATADIR", "wic-tools")
if not bootimg_dir:
- msger.error("Couldn't find STAGING_DATADIR, exiting\n")
+ logger.error("Couldn't find STAGING_DATADIR, exiting\n")
+ sys.exit(1)
if not _has_syslinux(bootimg_dir):
- msger.error("Please build syslinux first\n")
+ logger.error("Please build syslinux first\n")
+ sys.exit(1)
# just so the result notes display it
creator.bootimg_dir = bootimg_dir
@@ -176,8 +183,8 @@ class BootimgPcbiosPlugin(SourcePlugin):
blocks += extra_blocks
- msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \
- (extra_blocks, part.mountpoint, blocks))
+ logger.debug("Added %d extra blocks to %s to get to %d total blocks",
+ extra_blocks, part.mountpoint, blocks)
# dosfs image, created by mkdosfs
bootimg = "%s/boot.img" % cr_workdir
diff --git a/scripts/lib/wic/plugins/source/fsimage.py b/scripts/lib/wic/plugins/source/fsimage.py
index 9193892..35fb78b 100644
--- a/scripts/lib/wic/plugins/source/fsimage.py
+++ b/scripts/lib/wic/plugins/source/fsimage.py
@@ -15,12 +15,15 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
+import logging
import os
+import sys
-from wic import msger
from wic.pluginbase import SourcePlugin
from wic.utils.misc import get_bitbake_var
+logger = logging.getLogger('wic')
+
class FSImagePlugin(SourcePlugin):
"""
Add an already existing filesystem image to the partition layout.
@@ -58,16 +61,17 @@ class FSImagePlugin(SourcePlugin):
if not bootimg_dir:
bootimg_dir = get_bitbake_var("DEPLOY_DIR_IMAGE")
if not bootimg_dir:
- msger.error("Couldn't find DEPLOY_DIR_IMAGE, exiting\n")
+ logger.error("Couldn't find DEPLOY_DIR_IMAGE, exiting\n")
+ sys.exit(1)
- msger.debug('Bootimg dir: %s' % bootimg_dir)
+ logger.debug('Bootimg dir: %s', bootimg_dir)
if 'file' not in source_params:
- msger.error("No file specified\n")
- return
+ logger.error("No file specified\n")
+ sys.exit(1)
src = os.path.join(bootimg_dir, source_params['file'])
- msger.debug('Preparing partition using image %s' % (src))
+ logger.debug('Preparing partition using image %s', src)
part.prepare_rootfs_from_fs_image(cr_workdir, src, "")
diff --git a/scripts/lib/wic/plugins/source/isoimage-isohybrid.py b/scripts/lib/wic/plugins/source/isoimage-isohybrid.py
index fb34235..33de6d8 100644
--- a/scripts/lib/wic/plugins/source/isoimage-isohybrid.py
+++ b/scripts/lib/wic/plugins/source/isoimage-isohybrid.py
@@ -20,16 +20,19 @@
# AUTHORS
# Mihaly Varga <mihaly.varga (at] ni.com>
+import glob
+import logging
import os
import re
import shutil
-import glob
+import sys
-from wic import msger
from wic.engine import get_custom_config
from wic.pluginbase import SourcePlugin
from wic.utils.misc import exec_cmd, exec_native_cmd, get_bitbake_var
+logger = logging.getLogger('wic')
+
class IsoImagePlugin(SourcePlugin):
"""
Create a bootable ISO image
@@ -85,8 +88,9 @@ class IsoImagePlugin(SourcePlugin):
syslinux_conf += "APPEND initrd=/initrd LABEL=boot %s\n" \
% bootloader.append
- msger.debug("Writing syslinux config %s/ISO/isolinux/isolinux.cfg" \
- % cr_workdir)
+ logger.debug("Writing syslinux config %s/ISO/isolinux/isolinux.cfg",
+ cr_workdir)
+
with open("%s/ISO/isolinux/isolinux.cfg" % cr_workdir, "w") as cfg:
cfg.write(syslinux_conf)
@@ -99,11 +103,12 @@ class IsoImagePlugin(SourcePlugin):
if configfile:
grubefi_conf = get_custom_config(configfile)
if grubefi_conf:
- msger.debug("Using custom configuration file "
- "%s for grub.cfg" % configfile)
+ logger.debug("Using custom configuration file %s for grub.cfg",
+ configfile)
else:
- msger.error("configfile is specified but failed to "
- "get it from %s." % configfile)
+ logger.error("configfile is specified "
+ "but failed to get it from %s", configfile)
+ sys.exit(1)
else:
splash = os.path.join(cr_workdir, "EFI/boot/splash.jpg")
if os.path.exists(splash):
@@ -133,8 +138,8 @@ class IsoImagePlugin(SourcePlugin):
if splashline:
grubefi_conf += "%s\n" % splashline
- msger.debug("Writing grubefi config %s/EFI/BOOT/grub.cfg" \
- % cr_workdir)
+ logger.debug("Writing grubefi config %s/EFI/BOOT/grub.cfg", cr_workdir)
+
with open("%s/EFI/BOOT/grub.cfg" % cr_workdir, "w") as cfg:
cfg.write(grubefi_conf)
@@ -148,19 +153,23 @@ class IsoImagePlugin(SourcePlugin):
if not initrd:
initrd_dir = get_bitbake_var("DEPLOY_DIR_IMAGE")
if not initrd_dir:
- msger.error("Couldn't find DEPLOY_DIR_IMAGE, exiting.\n")
+ logger.error("Couldn't find DEPLOY_DIR_IMAGE, exiting.\n")
+ sys.exit(1)
image_name = get_bitbake_var("IMAGE_BASENAME")
if not image_name:
- msger.error("Couldn't find IMAGE_BASENAME, exiting.\n")
+ logger.error("Couldn't find IMAGE_BASENAME, exiting.\n")
+ sys.exit(1)
image_type = get_bitbake_var("INITRAMFS_FSTYPES")
if not image_type:
- msger.error("Couldn't find INITRAMFS_FSTYPES, exiting.\n")
+ logger.error("Couldn't find INITRAMFS_FSTYPES, exiting.\n")
+ sys.exit(1)
target_arch = get_bitbake_var("TRANSLATED_TARGET_ARCH")
if not target_arch:
- msger.error("Couldn't find TRANSLATED_TARGET_ARCH, exiting.\n")
+ logger.error("Couldn't find TRANSLATED_TARGET_ARCH, exiting.\n")
+ sys.exit(1)
initrd = glob.glob('%s/%s*%s.%s' % (initrd_dir, image_name, target_arch, image_type))[0]
@@ -183,7 +192,8 @@ class IsoImagePlugin(SourcePlugin):
os.symlink(os.readlink("%s/sbin/init" % rootfs_dir), \
"%s/init" % initrd_dir)
else:
- msger.error("Couldn't find or build initrd, exiting.\n")
+ logger.error("Couldn't find or build initrd, exiting.\n")
+ sys.exit(1)
exec_cmd("cd %s && find . | cpio -o -H newc -R +0:+0 >./initrd.cpio " \
% initrd_dir, as_shell=True)
@@ -209,11 +219,11 @@ class IsoImagePlugin(SourcePlugin):
exec_cmd(install_cmd)
# Overwrite the name of the created image
- msger.debug("%s" % source_params)
+ logger.debug(source_params)
if 'image_name' in source_params and \
source_params['image_name'].strip():
creator.name = source_params['image_name'].strip()
- msger.debug("The name of the image is: %s" % creator.name)
+ logger.debug("The name of the image is: %s", creator.name)
@classmethod
def do_prepare_partition(cls, part, source_params, creator, cr_workdir,
@@ -229,7 +239,8 @@ class IsoImagePlugin(SourcePlugin):
if part.rootfs_dir is None:
if not 'ROOTFS_DIR' in rootfs_dir:
- msger.error("Couldn't find --rootfs-dir, exiting.\n")
+ logger.error("Couldn't find --rootfs-dir, exiting.\n")
+ sys.exit(1)
rootfs_dir = rootfs_dir['ROOTFS_DIR']
else:
if part.rootfs_dir in rootfs_dir:
@@ -237,14 +248,16 @@ class IsoImagePlugin(SourcePlugin):
elif part.rootfs_dir:
rootfs_dir = part.rootfs_dir
else:
- msg = "Couldn't find --rootfs-dir=%s connection "
- msg += "or it is not a valid path, exiting.\n"
- msger.error(msg % part.rootfs_dir)
+ logger.error("Couldn't find --rootfs-dir=%s connection "
+ "or it is not a valid path, exiting.\n",
+ part.rootfs_dir)
+ sys.exit(1)
if not os.path.isdir(rootfs_dir):
rootfs_dir = get_bitbake_var("IMAGE_ROOTFS")
if not os.path.isdir(rootfs_dir):
- msger.error("Couldn't find IMAGE_ROOTFS, exiting.\n")
+ logger.error("Couldn't find IMAGE_ROOTFS, exiting.\n")
+ sys.exit(1)
part.rootfs_dir = rootfs_dir
@@ -283,7 +296,8 @@ class IsoImagePlugin(SourcePlugin):
if source_params.get('initrd'):
initrd = source_params['initrd']
if not deploy_dir:
- msger.error("Couldn't find DEPLOY_DIR_IMAGE, exiting\n")
+ logger.error("Couldn't find DEPLOY_DIR_IMAGE, exiting\n")
+ sys.exit(1)
cp_cmd = "cp %s/%s %s" % (deploy_dir, initrd, cr_workdir)
exec_cmd(cp_cmd)
else:
@@ -326,7 +340,8 @@ class IsoImagePlugin(SourcePlugin):
# didn't contains it
target_arch = get_bitbake_var("TARGET_SYS")
if not target_arch:
- msger.error("Coludn't find target architecture\n")
+ logger.error("Coludn't find target architecture\n")
+ sys.exit(1)
if re.match("x86_64", target_arch):
grub_target = 'x86_64-efi'
@@ -335,18 +350,21 @@ class IsoImagePlugin(SourcePlugin):
grub_target = 'i386-efi'
grub_image = "bootia32.efi"
else:
- msger.error("grub-efi is incompatible with target %s\n" \
- % target_arch)
+ logger.error("grub-efi is incompatible with target %s\n",
+ target_arch)
+ sys.exit(1)
if not os.path.isfile("%s/EFI/BOOT/%s" \
% (bootimg_dir, grub_image)):
grub_path = get_bitbake_var("STAGING_LIBDIR", "wic-tools")
if not grub_path:
- msger.error("Couldn't find STAGING_LIBDIR, exiting.\n")
+ logger.error("Couldn't find STAGING_LIBDIR, exiting.\n")
+ sys.exit(1)
grub_core = "%s/grub/%s" % (grub_path, grub_target)
if not os.path.exists(grub_core):
- msger.error("Please build grub-efi first\n")
+ logger.error("Please build grub-efi first\n")
+ sys.exit(1)
grub_cmd = "grub-mkimage -p '/EFI/BOOT' "
grub_cmd += "-d %s " % grub_core
@@ -362,10 +380,12 @@ class IsoImagePlugin(SourcePlugin):
exec_native_cmd(grub_cmd, native_sysroot)
else:
- msger.error("unrecognized bootimg-efi loader: %s" \
- % source_params['loader'])
+ logger.error("unrecognized bootimg-efi loader: %s",
+ source_params['loader'])
+ sys.exit(1)
except KeyError:
- msger.error("bootimg-efi requires a loader, none specified")
+ logger.error("bootimg-efi requires a loader, none specified")
+ sys.exit(1)
if os.path.exists("%s/EFI/BOOT" % isodir):
shutil.rmtree("%s/EFI/BOOT" % isodir)
@@ -388,9 +408,8 @@ class IsoImagePlugin(SourcePlugin):
blocks = int(out.split()[0])
# Add some extra space for file system overhead
blocks += 100
- msg = "Added 100 extra blocks to %s to get to %d total blocks" \
- % (part.mountpoint, blocks)
- msger.debug(msg)
+ logger.debug("Added 100 extra blocks to %s to get to %d "
+ "total blocks", part.mountpoint, blocks)
# dosfs image for EFI boot
bootimg = "%s/efi.img" % isodir
@@ -412,7 +431,8 @@ class IsoImagePlugin(SourcePlugin):
# Prepare files for legacy boot
syslinux_dir = get_bitbake_var("STAGING_DATADIR", "wic-tools")
if not syslinux_dir:
- msger.error("Couldn't find STAGING_DATADIR, exiting.\n")
+ logger.error("Couldn't find STAGING_DATADIR, exiting.\n")
+ sys.exit(1)
if os.path.exists("%s/isolinux" % isodir):
shutil.rmtree("%s/isolinux" % isodir)
@@ -452,7 +472,7 @@ class IsoImagePlugin(SourcePlugin):
mkisofs_cmd += "-eltorito-platform 0xEF -eltorito-boot %s " % efi_img
mkisofs_cmd += "-no-emul-boot %s " % isodir
- msger.debug("running command: %s" % mkisofs_cmd)
+ logger.debug("running command: %s", mkisofs_cmd)
exec_native_cmd(mkisofs_cmd, native_sysroot)
shutil.rmtree(isodir)
@@ -478,14 +498,14 @@ class IsoImagePlugin(SourcePlugin):
full_path_iso = creator._full_path(workdir, disk_name, "iso")
isohybrid_cmd = "isohybrid -u %s" % iso_img
- msger.debug("running command: %s" % isohybrid_cmd)
+ logger.debug("running command: %s", isohybrid_cmd)
exec_native_cmd(isohybrid_cmd, native_sysroot)
# Replace the image created by direct plugin with the one created by
# mkisofs command. This is necessary because the iso image created by
# mkisofs has a very specific MBR is system area of the ISO image, and
# direct plugin adds and configures an another MBR.
- msger.debug("Replaceing the image created by direct plugin\n")
+ logger.debug("Replaceing the image created by direct plugin\n")
os.remove(disk.path)
shutil.copy2(iso_img, full_path_iso)
shutil.copy2(full_path_iso, full_path)
diff --git a/scripts/lib/wic/plugins/source/rawcopy.py b/scripts/lib/wic/plugins/source/rawcopy.py
index 4e42e3e..c5c3be3 100644
--- a/scripts/lib/wic/plugins/source/rawcopy.py
+++ b/scripts/lib/wic/plugins/source/rawcopy.py
@@ -15,13 +15,16 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
+import logging
import os
+import sys
-from wic import msger
from wic.pluginbase import SourcePlugin
from wic.utils.misc import exec_cmd, get_bitbake_var
from wic.filemap import sparse_copy
+logger = logging.getLogger('wic')
+
class RawCopyPlugin(SourcePlugin):
"""
Populate partition content from raw image file.
@@ -59,13 +62,14 @@ class RawCopyPlugin(SourcePlugin):
if not bootimg_dir:
bootimg_dir = get_bitbake_var("DEPLOY_DIR_IMAGE")
if not bootimg_dir:
- msger.error("Couldn't find DEPLOY_DIR_IMAGE, exiting\n")
+ logger.error("Couldn't find DEPLOY_DIR_IMAGE, exiting\n")
+ sys.exit(1)
- msger.debug('Bootimg dir: %s' % bootimg_dir)
+ logger.debug('Bootimg dir: %s', bootimg_dir)
if 'file' not in source_params:
- msger.error("No file specified\n")
- return
+ logger.error("No file specified\n")
+ sys.exit(1)
src = os.path.join(bootimg_dir, source_params['file'])
dst = os.path.join(cr_workdir, "%s.%s" % (source_params['file'], part.lineno))
diff --git a/scripts/lib/wic/plugins/source/rootfs.py b/scripts/lib/wic/plugins/source/rootfs.py
index 9d959fa..cfc90f6 100644
--- a/scripts/lib/wic/plugins/source/rootfs.py
+++ b/scripts/lib/wic/plugins/source/rootfs.py
@@ -25,12 +25,15 @@
# Joao Henrique Ferreira de Freitas <joaohf (at] gmail.com>
#
+import logging
import os
+import sys
-from wic import msger
from wic.pluginbase import SourcePlugin
from wic.utils.misc import get_bitbake_var
+logger = logging.getLogger('wic')
+
class RootfsPlugin(SourcePlugin):
"""
Populate partition content from a rootfs directory.
@@ -45,10 +48,10 @@ class RootfsPlugin(SourcePlugin):
image_rootfs_dir = get_bitbake_var("IMAGE_ROOTFS", rootfs_dir)
if not os.path.isdir(image_rootfs_dir):
- msg = "No valid artifact IMAGE_ROOTFS from image named"
- msg += " %s has been found at %s, exiting.\n" % \
- (rootfs_dir, image_rootfs_dir)
- msger.error(msg)
+ logger.error("No valid artifact IMAGE_ROOTFS from image named %s "
+ "has been found at %s, exiting.\n",
+ rootfs_dir, image_rootfs_dir)
+ sys.exit(1)
return image_rootfs_dir
@@ -63,8 +66,9 @@ class RootfsPlugin(SourcePlugin):
"""
if part.rootfs_dir is None:
if not 'ROOTFS_DIR' in krootfs_dir:
- msg = "Couldn't find --rootfs-dir, exiting"
- msger.error(msg)
+ logger.error("Couldn't find --rootfs-dir, exiting")
+ sys.exit(1)
+
rootfs_dir = krootfs_dir['ROOTFS_DIR']
else:
if part.rootfs_dir in krootfs_dir:
@@ -72,9 +76,9 @@ class RootfsPlugin(SourcePlugin):
elif part.rootfs_dir:
rootfs_dir = part.rootfs_dir
else:
- msg = "Couldn't find --rootfs-dir=%s connection"
- msg += " or it is not a valid path, exiting"
- msger.error(msg % part.rootfs_dir)
+ logger.error("Couldn't find --rootfs-dir=%s connection or "
+ "it is not a valid path, exiting", part.rootfs_dir)
+ sys.exit(1)
real_rootfs_dir = cls.__get_rootfs_dir(rootfs_dir)
diff --git a/scripts/lib/wic/plugins/source/rootfs_pcbios_ext.py b/scripts/lib/wic/plugins/source/rootfs_pcbios_ext.py
index 9e79a13..ed5fbdf 100644
--- a/scripts/lib/wic/plugins/source/rootfs_pcbios_ext.py
+++ b/scripts/lib/wic/plugins/source/rootfs_pcbios_ext.py
@@ -18,15 +18,18 @@
# Adrian Freihofer <adrian.freihofer (at] neratec.com>
#
+import logging
import os
import re
+import sys
-from wic import msger
from wic.utils import runner
from wic.utils.misc import get_bitbake_var, exec_cmd, exec_native_cmd
from wic.utils.errors import ImageError
from wic.pluginbase import SourcePlugin
+logger = logging.getLogger('wic')
+
def serial_console_form_kargs(kernel_args):
"""
Create SERIAL... line from kernel parameters
@@ -48,16 +51,16 @@ def serial_console_form_kargs(kernel_args):
syslinux_conf += " " + param_match.group(2)
# parity
if param_match.group(3) and param_match.group(3) != 'n':
- msger.warning("syslinux does not support parity for console. {} is ignored."
- .format(param_match.group(3)))
+ logger.warning("syslinux does not support parity for console. "
+ "%s is ignored.", param_match.group(3))
# number of bits
if param_match.group(4) and param_match.group(4) != '8':
- msger.warning("syslinux supports 8 bit console configuration only. {} is ignored."
- .format(param_match.group(4)))
+ logger.warning("syslinux supports 8 bit console configuration "
+ "only. %s is ignored.", param_match.group(4))
# flow control
if param_match.group(5) and param_match.group(5) != '':
- msger.warning("syslinux console flowcontrol configuration. {} is ignored."
- .format(param_match.group(5)))
+ logger.warning("syslinux console flowcontrol configuration. "
+ "%s is ignored.", param_match.group(5))
break
return syslinux_conf
@@ -96,10 +99,10 @@ class RootfsPlugin(SourcePlugin):
image_rootfs_dir = get_bitbake_var("IMAGE_ROOTFS", rootfs_dir)
if not os.path.isdir(image_rootfs_dir):
- msg = "No valid artifact IMAGE_ROOTFS from image named"
- msg += " %s has been found at %s, exiting.\n" % \
- (rootfs_dir, image_rootfs_dir)
- msger.error(msg)
+ logger.error("No valid artifact IMAGE_ROOTFS from image named %s "
+ "has been found at %s, exiting.\n",
+ rootfs_dir, image_rootfs_dir)
+ sys.exit(1)
return image_rootfs_dir
@@ -132,7 +135,7 @@ class RootfsPlugin(SourcePlugin):
(image_creator.rootdev, bootloader.append)
syslinux_cfg = os.path.join(image_creator.rootfs_dir['ROOTFS_DIR'], "boot", "syslinux.cfg")
- msger.debug("Writing syslinux config %s" % syslinux_cfg)
+ logger.debug("Writing syslinux config %s", syslinux_cfg)
with open(syslinux_cfg, "w") as cfg:
cfg.write(syslinux_conf)
@@ -154,15 +157,17 @@ class RootfsPlugin(SourcePlugin):
# Make sure syslinux-nomtools is available in native sysroot or fail
native_syslinux_nomtools = os.path.join(native_sysroot, "usr/bin/syslinux-nomtools")
if not is_exe(native_syslinux_nomtools):
- msger.info("building syslinux-native...")
+ logger.info("building syslinux-native...")
exec_cmd("bitbake syslinux-native")
if not is_exe(native_syslinux_nomtools):
- msger.error("Couldn't find syslinux-nomtools (%s), exiting\n" %
- native_syslinux_nomtools)
+ logger.error("Couldn't find syslinux-nomtools (%s), exiting\n",
+ native_syslinux_nomtools)
+ sys.exit(1)
if part.rootfs is None:
if 'ROOTFS_DIR' not in krootfs_dir:
- msger.error("Couldn't find --rootfs-dir, exiting")
+ logger.error("Couldn't find --rootfs-dir, exiting")
+ sys.exit(1)
rootfs_dir = krootfs_dir['ROOTFS_DIR']
else:
if part.rootfs in krootfs_dir:
@@ -170,9 +175,9 @@ class RootfsPlugin(SourcePlugin):
elif part.rootfs:
rootfs_dir = part.rootfs
else:
- msg = "Couldn't find --rootfs-dir=%s connection"
- msg += " or it is not a valid path, exiting"
- msger.error(msg % part.rootfs)
+ logger.error("Couldn't find --rootfs-dir=%s connection or "
+ "it is not a valid path, exiting", part.rootfs)
+ sys.exit(1)
real_rootfs_dir = cls._get_rootfs_dir(rootfs_dir)
@@ -198,15 +203,18 @@ class RootfsPlugin(SourcePlugin):
elif image_creator.ptable_format == 'gpt':
mbrfile += "gptmbr.bin"
else:
- msger.error("Unsupported partition table: %s" % \
- image_creator.ptable_format)
+ logger.error("Unsupported partition table: %s",
+ image_creator.ptable_format)
+ sys.exit(1)
if not os.path.exists(mbrfile):
- msger.error("Couldn't find %s. Has syslinux-native been baked?" % mbrfile)
+ logger.error("Couldn't find %s. Has syslinux-native been baked?",
+ mbrfile)
+ sys.exit(1)
full_path = disk.path
- msger.debug("Installing MBR on disk %s as %s with size %s bytes" \
- % (disk_name, full_path, disk.min_size))
+ logger.debug("Installing MBR on disk %s as %s with size %s bytes",
+ disk_name, full_path, disk.min_size)
ret_code = runner.show(['dd', 'if=%s' % mbrfile, 'of=%s' % full_path, 'conv=notrunc'])
if ret_code != 0:
--
2.1.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 05/11] wic: remove msger module
2017-02-15 8:38 [PATCH 00/11] wic refactoring (almost done) Ed Bartosh
` (3 preceding siblings ...)
2017-02-15 8:38 ` [PATCH 04/11] wic: use wic logger in wic source plugins Ed Bartosh
@ 2017-02-15 8:38 ` Ed Bartosh
2017-02-15 8:38 ` [PATCH 06/11] wic: move errors module Ed Bartosh
` (5 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Ed Bartosh @ 2017-02-15 8:38 UTC (permalink / raw)
To: openembedded-core
Removed custom logger module msger as it's replaced
by wic logger.
Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
---
scripts/lib/wic/engine.py | 4 -
scripts/lib/wic/msger.py | 209 ----------------------------------------------
2 files changed, 213 deletions(-)
delete mode 100644 scripts/lib/wic/msger.py
diff --git a/scripts/lib/wic/engine.py b/scripts/lib/wic/engine.py
index b64714c..2ccd510 100644
--- a/scripts/lib/wic/engine.py
+++ b/scripts/lib/wic/engine.py
@@ -32,7 +32,6 @@ import logging
import os
import sys
-from wic import msger
from wic.plugin import pluginmgr
from wic.utils.misc import get_bitbake_var
@@ -184,9 +183,6 @@ def wic_create(wks_file, rootfs_dir, bootimg_dir, kernel_dir,
logger.error("BUILDDIR not found, exiting. (Did you forget to source oe-init-build-env?)")
sys.exit(1)
- if options.debug:
- msger.set_loglevel('debug')
-
if not os.path.exists(options.outdir):
os.makedirs(options.outdir)
diff --git a/scripts/lib/wic/msger.py b/scripts/lib/wic/msger.py
deleted file mode 100644
index dc9b734..0000000
--- a/scripts/lib/wic/msger.py
+++ /dev/null
@@ -1,209 +0,0 @@
-#!/usr/bin/env python -tt
-# vim: ai ts=4 sts=4 et sw=4
-#
-# Copyright (c) 2009, 2010, 2011 Intel, Inc.
-#
-# This program is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by the Free
-# Software Foundation; version 2 of the License
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-# for more details.
-#
-# You should have received a copy of the GNU General Public License along
-# 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 sys
-import re
-import time
-
-__ALL__ = ['get_loglevel',
- 'set_loglevel',
- 'set_logfile',
- 'debug',
- 'verbose',
- 'info',
- 'warning',
- 'error',
- ]
-
-# COLORs in ANSI
-INFO_COLOR = 32 # green
-WARN_COLOR = 33 # yellow
-ERR_COLOR = 31 # red
-ASK_COLOR = 34 # blue
-NO_COLOR = 0
-
-PREFIX_RE = re.compile('^<(.*?)>\s*(.*)', re.S)
-
-INTERACTIVE = True
-
-LOG_LEVEL = 1
-LOG_LEVELS = {
- 'quiet': 0,
- 'normal': 1,
- 'verbose': 2,
- 'debug': 3,
- 'never': 4,
-}
-
-LOG_FILE_FP = None
-LOG_CONTENT = ''
-CATCHERR_BUFFILE_FD = -1
-CATCHERR_BUFFILE_PATH = None
-CATCHERR_SAVED_2 = -1
-
-def _general_print(head, color, msg=None, stream=None, level='normal'):
- global LOG_CONTENT
- if not stream:
- stream = sys.stdout
-
- if LOG_LEVELS[level] > LOG_LEVEL:
- # skip
- return
-
- errormsg = ''
- if CATCHERR_BUFFILE_FD > 0:
- size = os.lseek(CATCHERR_BUFFILE_FD, 0, os.SEEK_END)
- os.lseek(CATCHERR_BUFFILE_FD, 0, os.SEEK_SET)
- errormsg = os.read(CATCHERR_BUFFILE_FD, size)
- os.ftruncate(CATCHERR_BUFFILE_FD, 0)
-
- # append error msg to LOG
- if errormsg:
- LOG_CONTENT += errormsg
-
- # append normal msg to LOG
- save_msg = msg.strip() if msg else None
- if save_msg:
- timestr = time.strftime("[%m/%d %H:%M:%S %Z] ", time.localtime())
- LOG_CONTENT += timestr + save_msg + '\n'
-
- if errormsg:
- _color_print('', NO_COLOR, errormsg, stream, level)
-
- _color_print(head, color, msg, stream, level)
-
-def _color_print(head, color, msg, stream, level):
- colored = True
- if color == NO_COLOR or \
- not stream.isatty() or \
- os.getenv('ANSI_COLORS_DISABLED') is not None:
- colored = False
-
- if head.startswith('\r'):
- # need not \n at last
- newline = False
- else:
- newline = True
-
- if colored:
- head = '\033[%dm%s:\033[0m ' %(color, head)
- if not newline:
- # ESC cmd to clear line
- head = '\033[2K' + head
- else:
- if head:
- head += ': '
- if head.startswith('\r'):
- head = head.lstrip()
- newline = True
-
- if msg is not None:
- stream.write('%s%s' % (head, msg))
- if newline:
- stream.write('\n')
-
- stream.flush()
-
-def _color_perror(head, color, msg, level='normal'):
- if CATCHERR_BUFFILE_FD > 0:
- _general_print(head, color, msg, sys.stdout, level)
- else:
- _general_print(head, color, msg, sys.stderr, level)
-
-def _split_msg(head, msg):
- if isinstance(msg, list):
- msg = '\n'.join(map(str, msg))
-
- if msg.startswith('\n'):
- # means print \n at first
- msg = msg.lstrip()
- head = '\n' + head
-
- elif msg.startswith('\r'):
- # means print \r at first
- msg = msg.lstrip()
- head = '\r' + head
-
- match = PREFIX_RE.match(msg)
- if match:
- head += ' <%s>' % match.group(1)
- msg = match.group(2)
-
- return head, msg
-
-def get_loglevel():
- return next((k for k, v in LOG_LEVELS.items() if v == LOG_LEVEL))
-
-def set_loglevel(level):
- global LOG_LEVEL
- if level not in LOG_LEVELS:
- # no effect
- return
-
- LOG_LEVEL = LOG_LEVELS[level]
-
-def set_interactive(mode=True):
- global INTERACTIVE
- if mode:
- INTERACTIVE = True
- else:
- INTERACTIVE = False
-
-def log(msg=''):
- # log msg to LOG_CONTENT then save to logfile
- global LOG_CONTENT
- if msg:
- LOG_CONTENT += msg
-
-def info(msg):
- head, msg = _split_msg('Info', msg)
- _general_print(head, INFO_COLOR, msg)
-
-def verbose(msg):
- head, msg = _split_msg('Verbose', msg)
- _general_print(head, INFO_COLOR, msg, level='verbose')
-
-def warning(msg):
- head, msg = _split_msg('Warning', msg)
- _color_perror(head, WARN_COLOR, msg)
-
-def debug(msg):
- head, msg = _split_msg('Debug', msg)
- _color_perror(head, ERR_COLOR, msg, level='debug')
-
-def error(msg):
- head, msg = _split_msg('Error', msg)
- _color_perror(head, ERR_COLOR, msg)
- sys.exit(1)
-
-def set_logfile(fpath):
- global LOG_FILE_FP
-
- def _savelogf():
- if LOG_FILE_FP:
- with open(LOG_FILE_FP, 'w') as log:
- log.write(LOG_CONTENT)
-
- if LOG_FILE_FP is not None:
- warning('duplicate log file configuration')
-
- LOG_FILE_FP = fpath
-
- import atexit
- atexit.register(_savelogf)
--
2.1.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 06/11] wic: move errors module
2017-02-15 8:38 [PATCH 00/11] wic refactoring (almost done) Ed Bartosh
` (4 preceding siblings ...)
2017-02-15 8:38 ` [PATCH 05/11] wic: remove msger module Ed Bartosh
@ 2017-02-15 8:38 ` Ed Bartosh
2017-02-15 8:38 ` [PATCH 07/11] wic: raise WicError in main module Ed Bartosh
` (4 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Ed Bartosh @ 2017-02-15 8:38 UTC (permalink / raw)
To: openembedded-core
Moved from lib/wic/utils/ to lib/wic as this is a core module.
Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
---
scripts/lib/wic/{utils => }/errors.py | 0
scripts/lib/wic/plugin.py | 4 ++--
scripts/lib/wic/plugins/imager/direct.py | 2 +-
scripts/lib/wic/plugins/source/bootimg-pcbios.py | 2 +-
scripts/lib/wic/plugins/source/rootfs_pcbios_ext.py | 2 +-
scripts/wic | 3 +--
6 files changed, 6 insertions(+), 7 deletions(-)
rename scripts/lib/wic/{utils => }/errors.py (100%)
diff --git a/scripts/lib/wic/utils/errors.py b/scripts/lib/wic/errors.py
similarity index 100%
rename from scripts/lib/wic/utils/errors.py
rename to scripts/lib/wic/errors.py
diff --git a/scripts/lib/wic/plugin.py b/scripts/lib/wic/plugin.py
index 70d3377..31311ad 100644
--- a/scripts/lib/wic/plugin.py
+++ b/scripts/lib/wic/plugin.py
@@ -19,8 +19,8 @@ import os
import sys
import logging
+from wic.errors import CreatorError
from wic import pluginbase
-from wic.utils import errors
from wic.utils.misc import get_bitbake_var
__ALL__ = ['PluginMgr', 'pluginmgr']
@@ -110,7 +110,7 @@ class PluginMgr():
""" the return value is dict of name:class pairs """
if ptype not in PLUGIN_TYPES:
- raise errors.CreatorError('%s is not valid plugin type' % ptype)
+ raise CreatorError('%s is not valid plugin type' % ptype)
plugins_dir = self._build_plugin_dir_list(self.plugin_dir, ptype)
diff --git a/scripts/lib/wic/plugins/imager/direct.py b/scripts/lib/wic/plugins/imager/direct.py
index 2e2d26a..e51c8be 100644
--- a/scripts/lib/wic/plugins/imager/direct.py
+++ b/scripts/lib/wic/plugins/imager/direct.py
@@ -33,11 +33,11 @@ import uuid
from time import strftime
+from wic.errors import ImageError
from wic.filemap import sparse_copy
from wic.ksparser import KickStart, KickStartError
from wic.plugin import pluginmgr
from wic.pluginbase import ImagerPlugin
-from wic.utils.errors import ImageError
from wic.utils.misc import get_bitbake_var, exec_cmd, exec_native_cmd
logger = logging.getLogger('wic')
diff --git a/scripts/lib/wic/plugins/source/bootimg-pcbios.py b/scripts/lib/wic/plugins/source/bootimg-pcbios.py
index 590d3d6..8f53fa2 100644
--- a/scripts/lib/wic/plugins/source/bootimg-pcbios.py
+++ b/scripts/lib/wic/plugins/source/bootimg-pcbios.py
@@ -29,8 +29,8 @@ import os
import sys
from wic.engine import get_custom_config
+from wic.errors import ImageError
from wic.utils import runner
-from wic.utils.errors import ImageError
from wic.pluginbase import SourcePlugin
from wic.utils.misc import (exec_cmd, exec_native_cmd,
get_bitbake_var, BOOTDD_EXTRA_SPACE)
diff --git a/scripts/lib/wic/plugins/source/rootfs_pcbios_ext.py b/scripts/lib/wic/plugins/source/rootfs_pcbios_ext.py
index ed5fbdf..850aa5a 100644
--- a/scripts/lib/wic/plugins/source/rootfs_pcbios_ext.py
+++ b/scripts/lib/wic/plugins/source/rootfs_pcbios_ext.py
@@ -23,9 +23,9 @@ import os
import re
import sys
+from wic.errors import ImageError
from wic.utils import runner
from wic.utils.misc import get_bitbake_var, exec_cmd, exec_native_cmd
-from wic.utils.errors import ImageError
from wic.pluginbase import SourcePlugin
logger = logging.getLogger('wic')
diff --git a/scripts/wic b/scripts/wic
index f3e93da..b12c743 100755
--- a/scripts/wic
+++ b/scripts/wic
@@ -51,8 +51,8 @@ if bitbake_exe:
else:
bitbake_main = None
+from wic.errors import WicError
from wic.utils.misc import get_bitbake_var, BB_VARS
-from wic.utils.errors import WicError
from wic import engine
from wic import help as hlp
@@ -337,4 +337,3 @@ if __name__ == "__main__":
except WicError as err:
logger.error(err)
sys.exit(1)
-
--
2.1.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 07/11] wic: raise WicError in main module
2017-02-15 8:38 [PATCH 00/11] wic refactoring (almost done) Ed Bartosh
` (5 preceding siblings ...)
2017-02-15 8:38 ` [PATCH 06/11] wic: move errors module Ed Bartosh
@ 2017-02-15 8:38 ` Ed Bartosh
2017-02-15 8:38 ` [PATCH 08/11] wic: raise WicError in core modules Ed Bartosh
` (3 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Ed Bartosh @ 2017-02-15 8:38 UTC (permalink / raw)
To: openembedded-core
Replaced sys.exit with raising WicError in main module.
Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
---
scripts/wic | 56 +++++++++++++++++++++++---------------------------------
1 file changed, 23 insertions(+), 33 deletions(-)
diff --git a/scripts/wic b/scripts/wic
index b12c743..b8be5b8 100755
--- a/scripts/wic
+++ b/scripts/wic
@@ -140,13 +140,11 @@ def wic_create_subcommand(args, usage_str):
(options, args) = parser.parse_args(args)
if len(args) != 1:
- logger.error("Wrong number of arguments, exiting\n")
parser.print_help()
- sys.exit(1)
+ raise WicError("Wrong number of arguments, exiting")
if options.build_rootfs and not bitbake_main:
- logger.error("Can't build roofs as bitbake is not in the $PATH")
- sys.exit(1)
+ raise WicError("Can't build roofs as bitbake is not in the $PATH")
if not options.image_name:
missed = []
@@ -157,9 +155,8 @@ def wic_create_subcommand(args, usage_str):
if not val:
missed.append(opt)
if missed:
- logger.error("The following build artifacts are not specified: %s",
- ", ".join(missed))
- sys.exit(1)
+ raise WicError("The following build artifacts are not specified: %s" %
+ ", ".join(missed))
if options.image_name:
BB_VARS.default_image = options.image_name
@@ -170,8 +167,7 @@ def wic_create_subcommand(args, usage_str):
BB_VARS.vars_dir = options.vars_dir
if options.build_check and not engine.verify_build_env():
- logger.error("Couldn't verify build environment, exiting\n")
- sys.exit(1)
+ raise WicError("Couldn't verify build environment, exiting")
bootimg_dir = ""
@@ -187,7 +183,7 @@ def wic_create_subcommand(args, usage_str):
logger.info("Building rootfs...\n")
if bitbake_main(BitBakeConfigParameters(argv),
cookerdata.CookerConfiguration()):
- sys.exit(1)
+ raise WicError("bitbake exited with error")
rootfs_dir = get_bitbake_var("IMAGE_ROOTFS", options.image_name)
kernel_dir = get_bitbake_var("DEPLOY_DIR_IMAGE", options.image_name)
@@ -195,29 +191,28 @@ def wic_create_subcommand(args, usage_str):
"wic-tools", cache=False)
else:
if options.build_rootfs:
- logger.error("Image name is not specified, exiting. (Use -e/--image-name to specify it)\n")
- sys.exit(1)
+ raise WicError("Image name is not specified, exiting. "
+ "(Use -e/--image-name to specify it)")
native_sysroot = options.native_sysroot
if not native_sysroot or not os.path.isdir(native_sysroot):
logger.info("Building wic-tools...\n")
if bitbake_main(BitBakeConfigParameters("bitbake wic-tools".split()),
cookerdata.CookerConfiguration()):
- sys.exit(1)
+ raise WicError("bitbake wic-tools failed")
native_sysroot = get_bitbake_var("RECIPE_SYSROOT_NATIVE", "wic-tools")
if not native_sysroot:
- logger.info("Unable to find the location of the native tools sysroot to use\n")
- sys.exit(1)
+ raise WicError("Unable to find the location of the native "
+ "tools sysroot to use")
wks_file = args[0]
if not wks_file.endswith(".wks"):
wks_file = engine.find_canned_image(scripts_path, wks_file)
if not wks_file:
- 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" % args[0])
- 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)" % args[0])
if not options.image_name:
rootfs_dir = ''
@@ -227,17 +222,13 @@ def wic_create_subcommand(args, usage_str):
kernel_dir = options.kernel_dir
native_sysroot = options.native_sysroot
if rootfs_dir and not os.path.isdir(rootfs_dir):
- logger.error("--roofs-dir (-r) not found, exiting\n")
- sys.exit(1)
+ raise WicError("--roofs-dir (-r) not found, exiting")
if not os.path.isdir(bootimg_dir):
- logger.error("--bootimg-dir (-b) not found, exiting\n")
- sys.exit(1)
+ raise WicError("--bootimg-dir (-b) not found, exiting")
if not os.path.isdir(kernel_dir):
- logger.error("--kernel-dir (-k) not found, exiting\n")
- sys.exit(1)
+ raise WicError("--kernel-dir (-k) not found, exiting")
if not os.path.isdir(native_sysroot):
- logger.error("--native-sysroot (-n) not found, exiting\n")
- sys.exit(1)
+ raise WicError("--native-sysroot (-n) not found, exiting")
else:
not_found = not_found_dir = ""
if not os.path.isdir(rootfs_dir):
@@ -249,12 +240,11 @@ def wic_create_subcommand(args, usage_str):
if not_found:
if not not_found_dir:
not_found_dir = "Completely missing artifact - wrong image (.wks) used?"
- logger.error("Build artifacts not found, exiting.")
+ logger.info("Build artifacts not found, exiting.")
logger.info(" (Please check that the build artifacts for the machine")
logger.info(" selected in local.conf actually exist and that they")
logger.info(" are the correct artifacts for the image (.wks file)).\n")
- logger.info("The artifact that couldn't be found was %s:\n %s", not_found, not_found_dir)
- sys.exit(1)
+ raise WicError("The artifact that couldn't be found was %s:\n %s", not_found, not_found_dir)
krootfs_dir = options.rootfs_dir
if krootfs_dir is None:
@@ -277,9 +267,8 @@ def wic_list_subcommand(args, usage_str):
args = parser.parse_args(args)[1]
if not engine.wic_list(args, scripts_path):
- logger.error("Bad list arguments, exiting\n")
parser.print_help()
- sys.exit(1)
+ raise WicError("Bad list arguments, exiting")
def wic_help_topic_subcommand(args, usage_str):
@@ -326,7 +315,7 @@ def main(argv):
if args[0] == "help":
if len(args) == 1:
parser.print_help()
- sys.exit(1)
+ raise WicError("help command requires parameter")
return hlp.invoke_subcommand(args, parser, hlp.wic_help_usage, subcommands)
@@ -335,5 +324,6 @@ if __name__ == "__main__":
try:
sys.exit(main(sys.argv[1:]))
except WicError as err:
+ print()
logger.error(err)
sys.exit(1)
--
2.1.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 08/11] wic: raise WicError in core modules
2017-02-15 8:38 [PATCH 00/11] wic refactoring (almost done) Ed Bartosh
` (6 preceding siblings ...)
2017-02-15 8:38 ` [PATCH 07/11] wic: raise WicError in main module Ed Bartosh
@ 2017-02-15 8:38 ` Ed Bartosh
2017-02-15 8:38 ` [PATCH 09/11] wic: raise WicError in wic plugins Ed Bartosh
` (2 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Ed Bartosh @ 2017-02-15 8:38 UTC (permalink / raw)
To: openembedded-core
Replaced sys.exit with raising WicError in the core wic modules.
Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
---
scripts/lib/wic/engine.py | 21 ++++++++-----------
scripts/lib/wic/partition.py | 46 +++++++++++++++++++----------------------
scripts/lib/wic/utils/misc.py | 6 +++---
scripts/lib/wic/utils/runner.py | 6 +++---
4 files changed, 36 insertions(+), 43 deletions(-)
diff --git a/scripts/lib/wic/engine.py b/scripts/lib/wic/engine.py
index 2ccd510..38a68ed 100644
--- a/scripts/lib/wic/engine.py
+++ b/scripts/lib/wic/engine.py
@@ -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
diff --git a/scripts/lib/wic/partition.py b/scripts/lib/wic/partition.py
index 349054f..c5c439a 100644
--- a/scripts/lib/wic/partition.py
+++ b/scripts/lib/wic/partition.py
@@ -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
@@ -98,9 +98,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:
@@ -131,10 +131,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)
@@ -156,12 +156,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:
@@ -191,16 +190,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):
@@ -240,9 +237,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:
diff --git a/scripts/lib/wic/utils/misc.py b/scripts/lib/wic/utils/misc.py
index b7b835a..94fdab2 100644
--- a/scripts/lib/wic/utils/misc.py
+++ b/scripts/lib/wic/utils/misc.py
@@ -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)
diff --git a/scripts/lib/wic/utils/runner.py b/scripts/lib/wic/utils/runner.py
index d27dcc7..5ede192 100644
--- a/scripts/lib/wic/utils/runner.py
+++ b/scripts/lib/wic/utils/runner.py
@@ -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:
--
2.1.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 09/11] wic: raise WicError in wic plugins
2017-02-15 8:38 [PATCH 00/11] wic refactoring (almost done) Ed Bartosh
` (7 preceding siblings ...)
2017-02-15 8:38 ` [PATCH 08/11] wic: raise WicError in core modules Ed Bartosh
@ 2017-02-15 8:38 ` Ed Bartosh
2017-02-15 8:38 ` [PATCH 10/11] wic: raise WicError instead of ImageError and CreatorError Ed Bartosh
2017-02-15 8:38 ` [PATCH 11/11] wic: move WicError to lib/wic/__init__.py Ed Bartosh
10 siblings, 0 replies; 12+ messages in thread
From: Ed Bartosh @ 2017-02-15 8:38 UTC (permalink / raw)
To: openembedded-core
Replaced sys.exit with raising WicError in wic plugins.
Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
---
scripts/lib/wic/plugins/imager/direct.py | 6 +--
scripts/lib/wic/plugins/source/bootimg-efi.py | 32 +++++------
.../lib/wic/plugins/source/bootimg-partition.py | 11 ++--
scripts/lib/wic/plugins/source/bootimg-pcbios.py | 20 +++----
scripts/lib/wic/plugins/source/fsimage.py | 8 ++-
.../lib/wic/plugins/source/isoimage-isohybrid.py | 63 ++++++++--------------
scripts/lib/wic/plugins/source/rawcopy.py | 8 ++-
scripts/lib/wic/plugins/source/rootfs.py | 17 +++---
.../lib/wic/plugins/source/rootfs_pcbios_ext.py | 34 +++++-------
9 files changed, 75 insertions(+), 124 deletions(-)
diff --git a/scripts/lib/wic/plugins/imager/direct.py b/scripts/lib/wic/plugins/imager/direct.py
index e51c8be..9c8a230 100644
--- a/scripts/lib/wic/plugins/imager/direct.py
+++ b/scripts/lib/wic/plugins/imager/direct.py
@@ -27,13 +27,12 @@
import logging
import os
import shutil
-import sys
import tempfile
import uuid
from time import strftime
-from wic.errors import ImageError
+from wic.errors import ImageError, WicError
from wic.filemap import sparse_copy
from wic.ksparser import KickStart, KickStartError
from wic.plugin import pluginmgr
@@ -58,8 +57,7 @@ class DirectPlugin(ImagerPlugin):
try:
self.ks = KickStart(wks_file)
except KickStartError as err:
- logger.error(str(err))
- sys.exit(1)
+ raise WicError(str(err))
# parse possible 'rootfs=name' items
self.rootfs_dir = dict(rdir.split('=') for rdir in rootfs_dir.split(' '))
diff --git a/scripts/lib/wic/plugins/source/bootimg-efi.py b/scripts/lib/wic/plugins/source/bootimg-efi.py
index e4c8451..1f018fa 100644
--- a/scripts/lib/wic/plugins/source/bootimg-efi.py
+++ b/scripts/lib/wic/plugins/source/bootimg-efi.py
@@ -27,8 +27,8 @@
import logging
import os
import shutil
-import sys
+from wic.errors import WicError
from wic.engine import get_custom_config
from wic.pluginbase import SourcePlugin
from wic.utils.misc import (exec_cmd, exec_native_cmd, get_bitbake_var,
@@ -59,9 +59,8 @@ class BootimgEFIPlugin(SourcePlugin):
logger.debug("Using custom configuration file "
"%s for grub.cfg", configfile)
else:
- logger.error("configfile is specified but failed to "
- "get it from %s.", configfile)
- sys.exit(1)
+ raise WicError("configfile is specified but failed to "
+ "get it from %s." % configfile)
if not custom_cfg:
# Create grub configuration using parameters from wks file
@@ -108,8 +107,7 @@ class BootimgEFIPlugin(SourcePlugin):
# obviously we need to have a common common deploy var
bootimg_dir = get_bitbake_var("DEPLOY_DIR_IMAGE")
if not bootimg_dir:
- logger.error("Couldn't find DEPLOY_DIR_IMAGE, exiting\n")
- sys.exit(1)
+ raise WicError("Couldn't find DEPLOY_DIR_IMAGE, exiting")
cp_cmd = "cp %s/%s %s" % (bootimg_dir, initrd, hdddir)
exec_cmd(cp_cmd, True)
@@ -132,9 +130,8 @@ class BootimgEFIPlugin(SourcePlugin):
logger.debug("Using custom configuration file "
"%s for systemd-boots's boot.conf", configfile)
else:
- logger.error("configfile is specified but failed to "
- "get it from %s.", configfile)
- sys.exit(1)
+ raise WicError("configfile is specified but failed to "
+ "get it from %s.", configfile)
if not custom_cfg:
# Create systemd-boot configuration using parameters from wks file
@@ -174,11 +171,9 @@ class BootimgEFIPlugin(SourcePlugin):
elif source_params['loader'] == 'systemd-boot':
cls.do_configure_systemdboot(hdddir, creator, cr_workdir, source_params)
else:
- logger.error("unrecognized bootimg-efi loader: %s", source_params['loader'])
- sys.exit(1)
+ raise WicError("unrecognized bootimg-efi loader: %s" % source_params['loader'])
except KeyError:
- logger.error("bootimg-efi requires a loader, none specified")
- sys.exit(1)
+ raise WicError("bootimg-efi requires a loader, none specified")
@classmethod
@@ -193,8 +188,7 @@ class BootimgEFIPlugin(SourcePlugin):
if not bootimg_dir:
bootimg_dir = get_bitbake_var("DEPLOY_DIR_IMAGE")
if not bootimg_dir:
- logger.error("Couldn't find DEPLOY_DIR_IMAGE, exiting\n")
- sys.exit(1)
+ raise WicError("Couldn't find DEPLOY_DIR_IMAGE, exiting")
# just so the result notes display it
creator.bootimg_dir = bootimg_dir
@@ -221,12 +215,10 @@ class BootimgEFIPlugin(SourcePlugin):
cp_cmd = "cp %s/%s %s/EFI/BOOT/%s" % (bootimg_dir, mod, hdddir, mod[8:])
exec_cmd(cp_cmd, True)
else:
- logger.error("unrecognized bootimg-efi loader: %s",
- source_params['loader'])
- sys.exit(1)
+ raise WicError("unrecognized bootimg-efi loader: %s" %
+ source_params['loader'])
except KeyError:
- logger.error("bootimg-efi requires a loader, none specified")
- sys.exit(1)
+ raise WicError("bootimg-efi requires a loader, none specified")
startup = os.path.join(bootimg_dir, "startup.nsh")
if os.path.exists(startup):
diff --git a/scripts/lib/wic/plugins/source/bootimg-partition.py b/scripts/lib/wic/plugins/source/bootimg-partition.py
index b486915..e9724a6 100644
--- a/scripts/lib/wic/plugins/source/bootimg-partition.py
+++ b/scripts/lib/wic/plugins/source/bootimg-partition.py
@@ -26,10 +26,10 @@
import logging
import os
import re
-import sys
from glob import glob
+from wic.errors import WicError
from wic.pluginbase import SourcePlugin
from wic.utils.misc import exec_cmd, get_bitbake_var
@@ -81,16 +81,14 @@ class BootimgPartitionPlugin(SourcePlugin):
if not bootimg_dir:
bootimg_dir = get_bitbake_var("DEPLOY_DIR_IMAGE")
if not bootimg_dir:
- logger.error("Couldn't find DEPLOY_DIR_IMAGE, exiting\n")
- sys.exit(1)
+ raise WicError("Couldn't find DEPLOY_DIR_IMAGE, exiting")
logger.debug('Bootimg dir: %s', bootimg_dir)
boot_files = get_bitbake_var("IMAGE_BOOT_FILES")
if not boot_files:
- logger.error('No boot files defined, IMAGE_BOOT_FILES unset')
- sys.exit(1)
+ raise WicError('No boot files defined, IMAGE_BOOT_FILES unset')
logger.debug('Boot files: %s', boot_files)
@@ -100,8 +98,7 @@ class BootimgPartitionPlugin(SourcePlugin):
if ';' in src_entry:
dst_entry = tuple(src_entry.split(';'))
if not dst_entry[0] or not dst_entry[1]:
- logger.error('Malformed boot file entry: %s', src_entry)
- sys.exit(1)
+ raise WicError('Malformed boot file entry: %s' % src_entry)
else:
dst_entry = (src_entry, src_entry)
diff --git a/scripts/lib/wic/plugins/source/bootimg-pcbios.py b/scripts/lib/wic/plugins/source/bootimg-pcbios.py
index 8f53fa2..2ded2da 100644
--- a/scripts/lib/wic/plugins/source/bootimg-pcbios.py
+++ b/scripts/lib/wic/plugins/source/bootimg-pcbios.py
@@ -26,10 +26,9 @@
import logging
import os
-import sys
from wic.engine import get_custom_config
-from wic.errors import ImageError
+from wic.errors import ImageError, WicError
from wic.utils import runner
from wic.pluginbase import SourcePlugin
from wic.utils.misc import (exec_cmd, exec_native_cmd,
@@ -57,14 +56,13 @@ class BootimgPcbiosPlugin(SourcePlugin):
elif creator.ptable_format == 'gpt':
mbrfile += "gptmbr.bin"
else:
- logger.error("Unsupported partition table: %s", creator.ptable_format)
- sys.exit(1)
+ raise WicError("Unsupported partition table: %s" %
+ creator.ptable_format)
if not os.path.exists(mbrfile):
- logger.error("Couldn't find %s. If using the -e option, do you "
- "have the right MACHINE set in local.conf? If not, "
- "is the bootimg_dir path correct?", mbrfile)
- sys.exit(1)
+ raise WicError("Couldn't find %s. If using the -e option, do you "
+ "have the right MACHINE set in local.conf? If not, "
+ "is the bootimg_dir path correct?" % mbrfile)
full_path = creator._full_path(workdir, disk_name, "direct")
logger.debug("Installing MBR on disk %s as %s with size %s bytes",
@@ -152,11 +150,9 @@ class BootimgPcbiosPlugin(SourcePlugin):
if not _has_syslinux(bootimg_dir):
bootimg_dir = get_bitbake_var("STAGING_DATADIR", "wic-tools")
if not bootimg_dir:
- logger.error("Couldn't find STAGING_DATADIR, exiting\n")
- sys.exit(1)
+ raise WicError("Couldn't find STAGING_DATADIR, exiting")
if not _has_syslinux(bootimg_dir):
- logger.error("Please build syslinux first\n")
- sys.exit(1)
+ raise WicError("Please build syslinux first")
# just so the result notes display it
creator.bootimg_dir = bootimg_dir
diff --git a/scripts/lib/wic/plugins/source/fsimage.py b/scripts/lib/wic/plugins/source/fsimage.py
index 35fb78b..67fc6d1 100644
--- a/scripts/lib/wic/plugins/source/fsimage.py
+++ b/scripts/lib/wic/plugins/source/fsimage.py
@@ -17,8 +17,8 @@
import logging
import os
-import sys
+from wic.errors import WicError
from wic.pluginbase import SourcePlugin
from wic.utils.misc import get_bitbake_var
@@ -61,14 +61,12 @@ class FSImagePlugin(SourcePlugin):
if not bootimg_dir:
bootimg_dir = get_bitbake_var("DEPLOY_DIR_IMAGE")
if not bootimg_dir:
- logger.error("Couldn't find DEPLOY_DIR_IMAGE, exiting\n")
- sys.exit(1)
+ raise WicError("Couldn't find DEPLOY_DIR_IMAGE, exiting")
logger.debug('Bootimg dir: %s', bootimg_dir)
if 'file' not in source_params:
- logger.error("No file specified\n")
- sys.exit(1)
+ raise WicError("No file specified")
src = os.path.join(bootimg_dir, source_params['file'])
diff --git a/scripts/lib/wic/plugins/source/isoimage-isohybrid.py b/scripts/lib/wic/plugins/source/isoimage-isohybrid.py
index 33de6d8..df86acc 100644
--- a/scripts/lib/wic/plugins/source/isoimage-isohybrid.py
+++ b/scripts/lib/wic/plugins/source/isoimage-isohybrid.py
@@ -25,8 +25,8 @@ import logging
import os
import re
import shutil
-import sys
+from wic.errors import WicError
from wic.engine import get_custom_config
from wic.pluginbase import SourcePlugin
from wic.utils.misc import exec_cmd, exec_native_cmd, get_bitbake_var
@@ -106,9 +106,8 @@ class IsoImagePlugin(SourcePlugin):
logger.debug("Using custom configuration file %s for grub.cfg",
configfile)
else:
- logger.error("configfile is specified "
- "but failed to get it from %s", configfile)
- sys.exit(1)
+ raise WicError("configfile is specified "
+ "but failed to get it from %s", configfile)
else:
splash = os.path.join(cr_workdir, "EFI/boot/splash.jpg")
if os.path.exists(splash):
@@ -153,23 +152,19 @@ class IsoImagePlugin(SourcePlugin):
if not initrd:
initrd_dir = get_bitbake_var("DEPLOY_DIR_IMAGE")
if not initrd_dir:
- logger.error("Couldn't find DEPLOY_DIR_IMAGE, exiting.\n")
- sys.exit(1)
+ raise WicError("Couldn't find DEPLOY_DIR_IMAGE, exiting.")
image_name = get_bitbake_var("IMAGE_BASENAME")
if not image_name:
- logger.error("Couldn't find IMAGE_BASENAME, exiting.\n")
- sys.exit(1)
+ raise WicError("Couldn't find IMAGE_BASENAME, exiting.")
image_type = get_bitbake_var("INITRAMFS_FSTYPES")
if not image_type:
- logger.error("Couldn't find INITRAMFS_FSTYPES, exiting.\n")
- sys.exit(1)
+ raise WicError("Couldn't find INITRAMFS_FSTYPES, exiting.")
target_arch = get_bitbake_var("TRANSLATED_TARGET_ARCH")
if not target_arch:
- logger.error("Couldn't find TRANSLATED_TARGET_ARCH, exiting.\n")
- sys.exit(1)
+ raise WicError("Couldn't find TRANSLATED_TARGET_ARCH, exiting.")
initrd = glob.glob('%s/%s*%s.%s' % (initrd_dir, image_name, target_arch, image_type))[0]
@@ -192,8 +187,7 @@ class IsoImagePlugin(SourcePlugin):
os.symlink(os.readlink("%s/sbin/init" % rootfs_dir), \
"%s/init" % initrd_dir)
else:
- logger.error("Couldn't find or build initrd, exiting.\n")
- sys.exit(1)
+ raise WicError("Couldn't find or build initrd, exiting.")
exec_cmd("cd %s && find . | cpio -o -H newc -R +0:+0 >./initrd.cpio " \
% initrd_dir, as_shell=True)
@@ -239,8 +233,7 @@ class IsoImagePlugin(SourcePlugin):
if part.rootfs_dir is None:
if not 'ROOTFS_DIR' in rootfs_dir:
- logger.error("Couldn't find --rootfs-dir, exiting.\n")
- sys.exit(1)
+ raise WicError("Couldn't find --rootfs-dir, exiting.")
rootfs_dir = rootfs_dir['ROOTFS_DIR']
else:
if part.rootfs_dir in rootfs_dir:
@@ -248,16 +241,14 @@ class IsoImagePlugin(SourcePlugin):
elif part.rootfs_dir:
rootfs_dir = part.rootfs_dir
else:
- logger.error("Couldn't find --rootfs-dir=%s connection "
- "or it is not a valid path, exiting.\n",
- part.rootfs_dir)
- sys.exit(1)
+ raise WicError("Couldn't find --rootfs-dir=%s connection "
+ "or it is not a valid path, exiting." %
+ part.rootfs_dir)
if not os.path.isdir(rootfs_dir):
rootfs_dir = get_bitbake_var("IMAGE_ROOTFS")
if not os.path.isdir(rootfs_dir):
- logger.error("Couldn't find IMAGE_ROOTFS, exiting.\n")
- sys.exit(1)
+ raise WicError("Couldn't find IMAGE_ROOTFS, exiting.")
part.rootfs_dir = rootfs_dir
@@ -296,8 +287,7 @@ class IsoImagePlugin(SourcePlugin):
if source_params.get('initrd'):
initrd = source_params['initrd']
if not deploy_dir:
- logger.error("Couldn't find DEPLOY_DIR_IMAGE, exiting\n")
- sys.exit(1)
+ raise WicError("Couldn't find DEPLOY_DIR_IMAGE, exiting")
cp_cmd = "cp %s/%s %s" % (deploy_dir, initrd, cr_workdir)
exec_cmd(cp_cmd)
else:
@@ -340,8 +330,7 @@ class IsoImagePlugin(SourcePlugin):
# didn't contains it
target_arch = get_bitbake_var("TARGET_SYS")
if not target_arch:
- logger.error("Coludn't find target architecture\n")
- sys.exit(1)
+ raise WicError("Coludn't find target architecture")
if re.match("x86_64", target_arch):
grub_target = 'x86_64-efi'
@@ -350,21 +339,18 @@ class IsoImagePlugin(SourcePlugin):
grub_target = 'i386-efi'
grub_image = "bootia32.efi"
else:
- logger.error("grub-efi is incompatible with target %s\n",
- target_arch)
- sys.exit(1)
+ raise WicError("grub-efi is incompatible with target %s" %
+ target_arch)
if not os.path.isfile("%s/EFI/BOOT/%s" \
% (bootimg_dir, grub_image)):
grub_path = get_bitbake_var("STAGING_LIBDIR", "wic-tools")
if not grub_path:
- logger.error("Couldn't find STAGING_LIBDIR, exiting.\n")
- sys.exit(1)
+ raise WicError("Couldn't find STAGING_LIBDIR, exiting.")
grub_core = "%s/grub/%s" % (grub_path, grub_target)
if not os.path.exists(grub_core):
- logger.error("Please build grub-efi first\n")
- sys.exit(1)
+ raise WicError("Please build grub-efi first")
grub_cmd = "grub-mkimage -p '/EFI/BOOT' "
grub_cmd += "-d %s " % grub_core
@@ -380,12 +366,10 @@ class IsoImagePlugin(SourcePlugin):
exec_native_cmd(grub_cmd, native_sysroot)
else:
- logger.error("unrecognized bootimg-efi loader: %s",
- source_params['loader'])
- sys.exit(1)
+ raise WicError("unrecognized bootimg-efi loader: %s" %
+ source_params['loader'])
except KeyError:
- logger.error("bootimg-efi requires a loader, none specified")
- sys.exit(1)
+ raise WicError("bootimg-efi requires a loader, none specified")
if os.path.exists("%s/EFI/BOOT" % isodir):
shutil.rmtree("%s/EFI/BOOT" % isodir)
@@ -431,8 +415,7 @@ class IsoImagePlugin(SourcePlugin):
# Prepare files for legacy boot
syslinux_dir = get_bitbake_var("STAGING_DATADIR", "wic-tools")
if not syslinux_dir:
- logger.error("Couldn't find STAGING_DATADIR, exiting.\n")
- sys.exit(1)
+ raise WicError("Couldn't find STAGING_DATADIR, exiting.")
if os.path.exists("%s/isolinux" % isodir):
shutil.rmtree("%s/isolinux" % isodir)
diff --git a/scripts/lib/wic/plugins/source/rawcopy.py b/scripts/lib/wic/plugins/source/rawcopy.py
index c5c3be3..5612809 100644
--- a/scripts/lib/wic/plugins/source/rawcopy.py
+++ b/scripts/lib/wic/plugins/source/rawcopy.py
@@ -17,8 +17,8 @@
import logging
import os
-import sys
+from wic.errors import WicError
from wic.pluginbase import SourcePlugin
from wic.utils.misc import exec_cmd, get_bitbake_var
from wic.filemap import sparse_copy
@@ -62,14 +62,12 @@ class RawCopyPlugin(SourcePlugin):
if not bootimg_dir:
bootimg_dir = get_bitbake_var("DEPLOY_DIR_IMAGE")
if not bootimg_dir:
- logger.error("Couldn't find DEPLOY_DIR_IMAGE, exiting\n")
- sys.exit(1)
+ raise WicError("Couldn't find DEPLOY_DIR_IMAGE, exiting")
logger.debug('Bootimg dir: %s', bootimg_dir)
if 'file' not in source_params:
- logger.error("No file specified\n")
- sys.exit(1)
+ raise WicError("No file specified")
src = os.path.join(bootimg_dir, source_params['file'])
dst = os.path.join(cr_workdir, "%s.%s" % (source_params['file'], part.lineno))
diff --git a/scripts/lib/wic/plugins/source/rootfs.py b/scripts/lib/wic/plugins/source/rootfs.py
index cfc90f6..e58469a 100644
--- a/scripts/lib/wic/plugins/source/rootfs.py
+++ b/scripts/lib/wic/plugins/source/rootfs.py
@@ -27,8 +27,8 @@
import logging
import os
-import sys
+from wic.errors import WicError
from wic.pluginbase import SourcePlugin
from wic.utils.misc import get_bitbake_var
@@ -48,10 +48,9 @@ class RootfsPlugin(SourcePlugin):
image_rootfs_dir = get_bitbake_var("IMAGE_ROOTFS", rootfs_dir)
if not os.path.isdir(image_rootfs_dir):
- logger.error("No valid artifact IMAGE_ROOTFS from image named %s "
- "has been found at %s, exiting.\n",
- rootfs_dir, image_rootfs_dir)
- sys.exit(1)
+ raise WicError("No valid artifact IMAGE_ROOTFS from image "
+ "named %s has been found at %s, exiting." %
+ (rootfs_dir, image_rootfs_dir))
return image_rootfs_dir
@@ -66,8 +65,7 @@ class RootfsPlugin(SourcePlugin):
"""
if part.rootfs_dir is None:
if not 'ROOTFS_DIR' in krootfs_dir:
- logger.error("Couldn't find --rootfs-dir, exiting")
- sys.exit(1)
+ raise WicError("Couldn't find --rootfs-dir, exiting")
rootfs_dir = krootfs_dir['ROOTFS_DIR']
else:
@@ -76,9 +74,8 @@ class RootfsPlugin(SourcePlugin):
elif part.rootfs_dir:
rootfs_dir = part.rootfs_dir
else:
- logger.error("Couldn't find --rootfs-dir=%s connection or "
- "it is not a valid path, exiting", part.rootfs_dir)
- sys.exit(1)
+ raise WicError("Couldn't find --rootfs-dir=%s connection or "
+ "it is not a valid path, exiting" % part.rootfs_dir)
real_rootfs_dir = cls.__get_rootfs_dir(rootfs_dir)
diff --git a/scripts/lib/wic/plugins/source/rootfs_pcbios_ext.py b/scripts/lib/wic/plugins/source/rootfs_pcbios_ext.py
index 850aa5a..4cc3a39 100644
--- a/scripts/lib/wic/plugins/source/rootfs_pcbios_ext.py
+++ b/scripts/lib/wic/plugins/source/rootfs_pcbios_ext.py
@@ -21,9 +21,8 @@
import logging
import os
import re
-import sys
-from wic.errors import ImageError
+from wic.errors import ImageError, WicError
from wic.utils import runner
from wic.utils.misc import get_bitbake_var, exec_cmd, exec_native_cmd
from wic.pluginbase import SourcePlugin
@@ -99,10 +98,9 @@ class RootfsPlugin(SourcePlugin):
image_rootfs_dir = get_bitbake_var("IMAGE_ROOTFS", rootfs_dir)
if not os.path.isdir(image_rootfs_dir):
- logger.error("No valid artifact IMAGE_ROOTFS from image named %s "
- "has been found at %s, exiting.\n",
- rootfs_dir, image_rootfs_dir)
- sys.exit(1)
+ raise WicError("No valid artifact IMAGE_ROOTFS from image named %s "
+ "has been found at %s, exiting." %
+ (rootfs_dir, image_rootfs_dir))
return image_rootfs_dir
@@ -160,14 +158,12 @@ class RootfsPlugin(SourcePlugin):
logger.info("building syslinux-native...")
exec_cmd("bitbake syslinux-native")
if not is_exe(native_syslinux_nomtools):
- logger.error("Couldn't find syslinux-nomtools (%s), exiting\n",
- native_syslinux_nomtools)
- sys.exit(1)
+ raise WicError("Couldn't find syslinux-nomtools (%s), exiting" %
+ native_syslinux_nomtools)
if part.rootfs is None:
if 'ROOTFS_DIR' not in krootfs_dir:
- logger.error("Couldn't find --rootfs-dir, exiting")
- sys.exit(1)
+ raise WicError("Couldn't find --rootfs-dir, exiting")
rootfs_dir = krootfs_dir['ROOTFS_DIR']
else:
if part.rootfs in krootfs_dir:
@@ -175,9 +171,8 @@ class RootfsPlugin(SourcePlugin):
elif part.rootfs:
rootfs_dir = part.rootfs
else:
- logger.error("Couldn't find --rootfs-dir=%s connection or "
- "it is not a valid path, exiting", part.rootfs)
- sys.exit(1)
+ raise WicError("Couldn't find --rootfs-dir=%s connection or "
+ "it is not a valid path, exiting" % part.rootfs)
real_rootfs_dir = cls._get_rootfs_dir(rootfs_dir)
@@ -203,15 +198,12 @@ class RootfsPlugin(SourcePlugin):
elif image_creator.ptable_format == 'gpt':
mbrfile += "gptmbr.bin"
else:
- logger.error("Unsupported partition table: %s",
- image_creator.ptable_format)
- sys.exit(1)
+ raise WicError("Unsupported partition table: %s" %
+ image_creator.ptable_format)
if not os.path.exists(mbrfile):
- logger.error("Couldn't find %s. Has syslinux-native been baked?",
- mbrfile)
- sys.exit(1)
-
+ raise WicError("Couldn't find %s. Has syslinux-native been baked?",
+ mbrfile)
full_path = disk.path
logger.debug("Installing MBR on disk %s as %s with size %s bytes",
disk_name, full_path, disk.min_size)
--
2.1.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 10/11] wic: raise WicError instead of ImageError and CreatorError
2017-02-15 8:38 [PATCH 00/11] wic refactoring (almost done) Ed Bartosh
` (8 preceding siblings ...)
2017-02-15 8:38 ` [PATCH 09/11] wic: raise WicError in wic plugins Ed Bartosh
@ 2017-02-15 8:38 ` Ed Bartosh
2017-02-15 8:38 ` [PATCH 11/11] wic: move WicError to lib/wic/__init__.py Ed Bartosh
10 siblings, 0 replies; 12+ messages in thread
From: Ed Bartosh @ 2017-02-15 8:38 UTC (permalink / raw)
To: openembedded-core
There is no need to raise special exceptions. Raising
WicError should be enough.
Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
---
scripts/lib/wic/plugin.py | 4 ++--
scripts/lib/wic/plugins/imager/direct.py | 6 +++---
scripts/lib/wic/plugins/source/bootimg-pcbios.py | 4 ++--
scripts/lib/wic/plugins/source/rootfs_pcbios_ext.py | 4 ++--
4 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/scripts/lib/wic/plugin.py b/scripts/lib/wic/plugin.py
index 31311ad..0e98da5 100644
--- a/scripts/lib/wic/plugin.py
+++ b/scripts/lib/wic/plugin.py
@@ -19,7 +19,7 @@ import os
import sys
import logging
-from wic.errors import CreatorError
+from wic.errors import WicError
from wic import pluginbase
from wic.utils.misc import get_bitbake_var
@@ -110,7 +110,7 @@ class PluginMgr():
""" the return value is dict of name:class pairs """
if ptype not in PLUGIN_TYPES:
- raise CreatorError('%s is not valid plugin type' % ptype)
+ raise WicError('%s is not valid plugin type' % ptype)
plugins_dir = self._build_plugin_dir_list(self.plugin_dir, ptype)
diff --git a/scripts/lib/wic/plugins/imager/direct.py b/scripts/lib/wic/plugins/imager/direct.py
index 9c8a230..5b20ca9 100644
--- a/scripts/lib/wic/plugins/imager/direct.py
+++ b/scripts/lib/wic/plugins/imager/direct.py
@@ -32,7 +32,7 @@ import uuid
from time import strftime
-from wic.errors import ImageError, WicError
+from wic.errors import WicError
from wic.filemap import sparse_copy
from wic.ksparser import KickStart, KickStartError
from wic.plugin import pluginmgr
@@ -355,8 +355,8 @@ class PartitionedImage():
# The --part-type can also be implemented for MBR partitions,
# in which case it would map to the 1-byte "partition type"
# filed at offset 3 of the partition entry.
- raise ImageError("setting custom partition type is not " \
- "implemented for msdos partitions")
+ raise WicError("setting custom partition type is not " \
+ "implemented for msdos partitions")
# Get the disk where the partition is located
self.numpart += 1
diff --git a/scripts/lib/wic/plugins/source/bootimg-pcbios.py b/scripts/lib/wic/plugins/source/bootimg-pcbios.py
index 2ded2da..c3a0e4e 100644
--- a/scripts/lib/wic/plugins/source/bootimg-pcbios.py
+++ b/scripts/lib/wic/plugins/source/bootimg-pcbios.py
@@ -28,7 +28,7 @@ import logging
import os
from wic.engine import get_custom_config
-from wic.errors import ImageError, WicError
+from wic.errors import WicError
from wic.utils import runner
from wic.pluginbase import SourcePlugin
from wic.utils.misc import (exec_cmd, exec_native_cmd,
@@ -71,7 +71,7 @@ class BootimgPcbiosPlugin(SourcePlugin):
rcode = runner.show(['dd', 'if=%s' % mbrfile,
'of=%s' % full_path, 'conv=notrunc'])
if rcode != 0:
- raise ImageError("Unable to set MBR to %s" % full_path)
+ raise WicError("Unable to set MBR to %s" % full_path)
@classmethod
def do_configure_partition(cls, part, source_params, creator, cr_workdir,
diff --git a/scripts/lib/wic/plugins/source/rootfs_pcbios_ext.py b/scripts/lib/wic/plugins/source/rootfs_pcbios_ext.py
index 4cc3a39..cf0eec2 100644
--- a/scripts/lib/wic/plugins/source/rootfs_pcbios_ext.py
+++ b/scripts/lib/wic/plugins/source/rootfs_pcbios_ext.py
@@ -22,7 +22,7 @@ import logging
import os
import re
-from wic.errors import ImageError, WicError
+from wic.errors import WicError
from wic.utils import runner
from wic.utils.misc import get_bitbake_var, exec_cmd, exec_native_cmd
from wic.pluginbase import SourcePlugin
@@ -210,4 +210,4 @@ class RootfsPlugin(SourcePlugin):
ret_code = runner.show(['dd', 'if=%s' % mbrfile, 'of=%s' % full_path, 'conv=notrunc'])
if ret_code != 0:
- raise ImageError("Unable to set MBR to %s" % full_path)
+ raise WicError("Unable to set MBR to %s" % full_path)
--
2.1.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 11/11] wic: move WicError to lib/wic/__init__.py
2017-02-15 8:38 [PATCH 00/11] wic refactoring (almost done) Ed Bartosh
` (9 preceding siblings ...)
2017-02-15 8:38 ` [PATCH 10/11] wic: raise WicError instead of ImageError and CreatorError Ed Bartosh
@ 2017-02-15 8:38 ` Ed Bartosh
10 siblings, 0 replies; 12+ messages in thread
From: Ed Bartosh @ 2017-02-15 8:38 UTC (permalink / raw)
To: openembedded-core
Removed unused exceptions from error.py
Moved definition of WicError to lib/wic/__init__.py
Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
---
scripts/lib/wic/__init__.py | 20 +++++++++++++++
scripts/lib/wic/engine.py | 2 +-
scripts/lib/wic/errors.py | 29 ----------------------
scripts/lib/wic/partition.py | 2 +-
scripts/lib/wic/plugin.py | 3 +--
scripts/lib/wic/plugins/imager/direct.py | 2 +-
scripts/lib/wic/plugins/source/bootimg-efi.py | 2 +-
.../lib/wic/plugins/source/bootimg-partition.py | 2 +-
scripts/lib/wic/plugins/source/bootimg-pcbios.py | 2 +-
scripts/lib/wic/plugins/source/fsimage.py | 2 +-
.../lib/wic/plugins/source/isoimage-isohybrid.py | 2 +-
scripts/lib/wic/plugins/source/rawcopy.py | 2 +-
scripts/lib/wic/plugins/source/rootfs.py | 2 +-
.../lib/wic/plugins/source/rootfs_pcbios_ext.py | 2 +-
scripts/lib/wic/utils/misc.py | 2 +-
scripts/lib/wic/utils/runner.py | 2 +-
scripts/wic | 2 +-
17 files changed, 35 insertions(+), 45 deletions(-)
delete mode 100644 scripts/lib/wic/errors.py
diff --git a/scripts/lib/wic/__init__.py b/scripts/lib/wic/__init__.py
index e69de29..85876b1 100644
--- a/scripts/lib/wic/__init__.py
+++ b/scripts/lib/wic/__init__.py
@@ -0,0 +1,20 @@
+#!/usr/bin/env python -tt
+#
+# Copyright (c) 2007 Red Hat, Inc.
+# Copyright (c) 2011 Intel, Inc.
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the Free
+# Software Foundation; version 2 of the License
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc., 59
+# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+class WicError(Exception):
+ pass
diff --git a/scripts/lib/wic/engine.py b/scripts/lib/wic/engine.py
index 38a68ed..c29924b 100644
--- a/scripts/lib/wic/engine.py
+++ b/scripts/lib/wic/engine.py
@@ -31,7 +31,7 @@
import logging
import os
-from wic.errors import WicError
+from wic import WicError
from wic.plugin import pluginmgr
from wic.utils.misc import get_bitbake_var
diff --git a/scripts/lib/wic/errors.py b/scripts/lib/wic/errors.py
deleted file mode 100644
index d1b514d..0000000
--- a/scripts/lib/wic/errors.py
+++ /dev/null
@@ -1,29 +0,0 @@
-#!/usr/bin/env python -tt
-#
-# Copyright (c) 2007 Red Hat, Inc.
-# Copyright (c) 2011 Intel, Inc.
-#
-# This program is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by the Free
-# Software Foundation; version 2 of the License
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-# for more details.
-#
-# You should have received a copy of the GNU General Public License along
-# with this program; if not, write to the Free Software Foundation, Inc., 59
-# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-class WicError(Exception):
- pass
-
-class CreatorError(WicError):
- pass
-
-class Usage(WicError):
- pass
-
-class ImageError(WicError):
- pass
diff --git a/scripts/lib/wic/partition.py b/scripts/lib/wic/partition.py
index c5c439a..6a82299 100644
--- a/scripts/lib/wic/partition.py
+++ b/scripts/lib/wic/partition.py
@@ -28,7 +28,7 @@ import logging
import os
import tempfile
-from wic.errors import WicError
+from wic import WicError
from wic.utils.misc import exec_cmd, exec_native_cmd, get_bitbake_var
from wic.plugin import pluginmgr
diff --git a/scripts/lib/wic/plugin.py b/scripts/lib/wic/plugin.py
index 0e98da5..ac55ecf 100644
--- a/scripts/lib/wic/plugin.py
+++ b/scripts/lib/wic/plugin.py
@@ -19,8 +19,7 @@ import os
import sys
import logging
-from wic.errors import WicError
-from wic import pluginbase
+from wic import pluginbase, WicError
from wic.utils.misc import get_bitbake_var
__ALL__ = ['PluginMgr', 'pluginmgr']
diff --git a/scripts/lib/wic/plugins/imager/direct.py b/scripts/lib/wic/plugins/imager/direct.py
index 5b20ca9..6d1ed8c 100644
--- a/scripts/lib/wic/plugins/imager/direct.py
+++ b/scripts/lib/wic/plugins/imager/direct.py
@@ -32,7 +32,7 @@ import uuid
from time import strftime
-from wic.errors import WicError
+from wic import WicError
from wic.filemap import sparse_copy
from wic.ksparser import KickStart, KickStartError
from wic.plugin import pluginmgr
diff --git a/scripts/lib/wic/plugins/source/bootimg-efi.py b/scripts/lib/wic/plugins/source/bootimg-efi.py
index 1f018fa..2d793a5 100644
--- a/scripts/lib/wic/plugins/source/bootimg-efi.py
+++ b/scripts/lib/wic/plugins/source/bootimg-efi.py
@@ -28,7 +28,7 @@ import logging
import os
import shutil
-from wic.errors import WicError
+from wic import WicError
from wic.engine import get_custom_config
from wic.pluginbase import SourcePlugin
from wic.utils.misc import (exec_cmd, exec_native_cmd, get_bitbake_var,
diff --git a/scripts/lib/wic/plugins/source/bootimg-partition.py b/scripts/lib/wic/plugins/source/bootimg-partition.py
index e9724a6..373e8d8 100644
--- a/scripts/lib/wic/plugins/source/bootimg-partition.py
+++ b/scripts/lib/wic/plugins/source/bootimg-partition.py
@@ -29,7 +29,7 @@ import re
from glob import glob
-from wic.errors import WicError
+from wic import WicError
from wic.pluginbase import SourcePlugin
from wic.utils.misc import exec_cmd, get_bitbake_var
diff --git a/scripts/lib/wic/plugins/source/bootimg-pcbios.py b/scripts/lib/wic/plugins/source/bootimg-pcbios.py
index c3a0e4e..74c75a0 100644
--- a/scripts/lib/wic/plugins/source/bootimg-pcbios.py
+++ b/scripts/lib/wic/plugins/source/bootimg-pcbios.py
@@ -27,8 +27,8 @@
import logging
import os
+from wic import WicError
from wic.engine import get_custom_config
-from wic.errors import WicError
from wic.utils import runner
from wic.pluginbase import SourcePlugin
from wic.utils.misc import (exec_cmd, exec_native_cmd,
diff --git a/scripts/lib/wic/plugins/source/fsimage.py b/scripts/lib/wic/plugins/source/fsimage.py
index 67fc6d1..8fbe44d 100644
--- a/scripts/lib/wic/plugins/source/fsimage.py
+++ b/scripts/lib/wic/plugins/source/fsimage.py
@@ -18,7 +18,7 @@
import logging
import os
-from wic.errors import WicError
+from wic import WicError
from wic.pluginbase import SourcePlugin
from wic.utils.misc import get_bitbake_var
diff --git a/scripts/lib/wic/plugins/source/isoimage-isohybrid.py b/scripts/lib/wic/plugins/source/isoimage-isohybrid.py
index df86acc..1ceba62 100644
--- a/scripts/lib/wic/plugins/source/isoimage-isohybrid.py
+++ b/scripts/lib/wic/plugins/source/isoimage-isohybrid.py
@@ -26,7 +26,7 @@ import os
import re
import shutil
-from wic.errors import WicError
+from wic import WicError
from wic.engine import get_custom_config
from wic.pluginbase import SourcePlugin
from wic.utils.misc import exec_cmd, exec_native_cmd, get_bitbake_var
diff --git a/scripts/lib/wic/plugins/source/rawcopy.py b/scripts/lib/wic/plugins/source/rawcopy.py
index 5612809..12348ae 100644
--- a/scripts/lib/wic/plugins/source/rawcopy.py
+++ b/scripts/lib/wic/plugins/source/rawcopy.py
@@ -18,7 +18,7 @@
import logging
import os
-from wic.errors import WicError
+from wic import WicError
from wic.pluginbase import SourcePlugin
from wic.utils.misc import exec_cmd, get_bitbake_var
from wic.filemap import sparse_copy
diff --git a/scripts/lib/wic/plugins/source/rootfs.py b/scripts/lib/wic/plugins/source/rootfs.py
index e58469a..0ae62c7 100644
--- a/scripts/lib/wic/plugins/source/rootfs.py
+++ b/scripts/lib/wic/plugins/source/rootfs.py
@@ -28,7 +28,7 @@
import logging
import os
-from wic.errors import WicError
+from wic import WicError
from wic.pluginbase import SourcePlugin
from wic.utils.misc import get_bitbake_var
diff --git a/scripts/lib/wic/plugins/source/rootfs_pcbios_ext.py b/scripts/lib/wic/plugins/source/rootfs_pcbios_ext.py
index cf0eec2..94f80d0 100644
--- a/scripts/lib/wic/plugins/source/rootfs_pcbios_ext.py
+++ b/scripts/lib/wic/plugins/source/rootfs_pcbios_ext.py
@@ -22,7 +22,7 @@ import logging
import os
import re
-from wic.errors import WicError
+from wic import WicError
from wic.utils import runner
from wic.utils.misc import get_bitbake_var, exec_cmd, exec_native_cmd
from wic.pluginbase import SourcePlugin
diff --git a/scripts/lib/wic/utils/misc.py b/scripts/lib/wic/utils/misc.py
index 94fdab2..4b822f0 100644
--- a/scripts/lib/wic/utils/misc.py
+++ b/scripts/lib/wic/utils/misc.py
@@ -33,7 +33,7 @@ import re
from collections import defaultdict
from distutils import spawn
-from wic.errors import WicError
+from wic import WicError
from wic.utils import runner
logger = logging.getLogger('wic')
diff --git a/scripts/lib/wic/utils/runner.py b/scripts/lib/wic/utils/runner.py
index 5ede192..56d7ea3 100644
--- a/scripts/lib/wic/utils/runner.py
+++ b/scripts/lib/wic/utils/runner.py
@@ -19,7 +19,7 @@ import logging
import os
import subprocess
-from wic.errors import WicError
+from wic import WicError
logger = logging.getLogger('wic')
diff --git a/scripts/wic b/scripts/wic
index b8be5b8..e6780a1 100755
--- a/scripts/wic
+++ b/scripts/wic
@@ -51,7 +51,7 @@ if bitbake_exe:
else:
bitbake_main = None
-from wic.errors import WicError
+from wic import WicError
from wic.utils.misc import get_bitbake_var, BB_VARS
from wic import engine
from wic import help as hlp
--
2.1.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
end of thread, other threads:[~2017-02-15 9:02 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-02-15 8:38 [PATCH 00/11] wic refactoring (almost done) Ed Bartosh
2017-02-15 8:38 ` [PATCH 01/11] wic: setup logging in the main wic module Ed Bartosh
2017-02-15 8:38 ` [PATCH 02/11] wic: use wic logger in core modules Ed Bartosh
2017-02-15 8:38 ` [PATCH 03/11] wic: use wic logger in imager direct plugin Ed Bartosh
2017-02-15 8:38 ` [PATCH 04/11] wic: use wic logger in wic source plugins Ed Bartosh
2017-02-15 8:38 ` [PATCH 05/11] wic: remove msger module Ed Bartosh
2017-02-15 8:38 ` [PATCH 06/11] wic: move errors module Ed Bartosh
2017-02-15 8:38 ` [PATCH 07/11] wic: raise WicError in main module Ed Bartosh
2017-02-15 8:38 ` [PATCH 08/11] wic: raise WicError in core modules Ed Bartosh
2017-02-15 8:38 ` [PATCH 09/11] wic: raise WicError in wic plugins Ed Bartosh
2017-02-15 8:38 ` [PATCH 10/11] wic: raise WicError instead of ImageError and CreatorError Ed Bartosh
2017-02-15 8:38 ` [PATCH 11/11] wic: move WicError to lib/wic/__init__.py Ed Bartosh
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox