wic: raise WicError in wic plugins

Replaced sys.exit with raising WicError in wic plugins.

(From OE-Core rev: 92e8c81c941597eb2b4b61d5c28833e4826888f8)

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Ed Bartosh 2017-02-14 23:07:35 +02:00 committed by Richard Purdie
parent f5ae79da40
commit 8da175607c
9 changed files with 75 additions and 124 deletions

View File

@ -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(' '))

View File

@ -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):

View File

@ -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)

View File

@ -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

View File

@ -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'])

View File

@ -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)

View File

@ -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))

View File

@ -28,10 +28,10 @@
import logging
import os
import shutil
import sys
from oe.path import copyhardlinktree
from wic.errors import WicError
from wic.pluginbase import SourcePlugin
from wic.utils.misc import get_bitbake_var, exec_cmd
@ -51,10 +51,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
@ -69,8 +68,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:
@ -79,9 +77,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)

View File

@ -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)