wic: raise WicError in main module

Replaced sys.exit with raising WicError in main module.

(From OE-Core rev: b7c19f1ee8b850806c73ccd6f99c42d94a725fc9)

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Ed Bartosh 2017-02-14 22:00:48 +02:00 committed by Richard Purdie
parent 79c066b298
commit 3d47a212a6
1 changed files with 23 additions and 33 deletions

View File

@ -142,13 +142,11 @@ def wic_create_subcommand(args, usage_str):
(options, args) = parser.parse_args(args) (options, args) = parser.parse_args(args)
if len(args) != 1: if len(args) != 1:
logger.error("Wrong number of arguments, exiting\n")
parser.print_help() parser.print_help()
sys.exit(1) raise WicError("Wrong number of arguments, exiting")
if options.build_rootfs and not bitbake_main: if options.build_rootfs and not bitbake_main:
logger.error("Can't build roofs as bitbake is not in the $PATH") raise WicError("Can't build roofs as bitbake is not in the $PATH")
sys.exit(1)
if not options.image_name: if not options.image_name:
missed = [] missed = []
@ -159,9 +157,8 @@ def wic_create_subcommand(args, usage_str):
if not val: if not val:
missed.append(opt) missed.append(opt)
if missed: if missed:
logger.error("The following build artifacts are not specified: %s", raise WicError("The following build artifacts are not specified: %s" %
", ".join(missed)) ", ".join(missed))
sys.exit(1)
if options.image_name: if options.image_name:
BB_VARS.default_image = options.image_name BB_VARS.default_image = options.image_name
@ -172,8 +169,7 @@ def wic_create_subcommand(args, usage_str):
BB_VARS.vars_dir = options.vars_dir BB_VARS.vars_dir = options.vars_dir
if options.build_check and not engine.verify_build_env(): if options.build_check and not engine.verify_build_env():
logger.error("Couldn't verify build environment, exiting\n") raise WicError("Couldn't verify build environment, exiting")
sys.exit(1)
bootimg_dir = "" bootimg_dir = ""
@ -189,7 +185,7 @@ def wic_create_subcommand(args, usage_str):
logger.info("Building rootfs...\n") logger.info("Building rootfs...\n")
if bitbake_main(BitBakeConfigParameters(argv), if bitbake_main(BitBakeConfigParameters(argv),
cookerdata.CookerConfiguration()): cookerdata.CookerConfiguration()):
sys.exit(1) raise WicError("bitbake exited with error")
rootfs_dir = get_bitbake_var("IMAGE_ROOTFS", options.image_name) rootfs_dir = get_bitbake_var("IMAGE_ROOTFS", options.image_name)
kernel_dir = get_bitbake_var("DEPLOY_DIR_IMAGE", options.image_name) kernel_dir = get_bitbake_var("DEPLOY_DIR_IMAGE", options.image_name)
@ -197,29 +193,28 @@ def wic_create_subcommand(args, usage_str):
"wic-tools", cache=False) "wic-tools", cache=False)
else: else:
if options.build_rootfs: if options.build_rootfs:
logger.error("Image name is not specified, exiting. (Use -e/--image-name to specify it)\n") raise WicError("Image name is not specified, exiting. "
sys.exit(1) "(Use -e/--image-name to specify it)")
native_sysroot = options.native_sysroot native_sysroot = options.native_sysroot
if not native_sysroot or not os.path.isdir(native_sysroot): if not native_sysroot or not os.path.isdir(native_sysroot):
logger.info("Building wic-tools...\n") logger.info("Building wic-tools...\n")
if bitbake_main(BitBakeConfigParameters("bitbake wic-tools".split()), if bitbake_main(BitBakeConfigParameters("bitbake wic-tools".split()),
cookerdata.CookerConfiguration()): cookerdata.CookerConfiguration()):
sys.exit(1) raise WicError("bitbake wic-tools failed")
native_sysroot = get_bitbake_var("RECIPE_SYSROOT_NATIVE", "wic-tools") native_sysroot = get_bitbake_var("RECIPE_SYSROOT_NATIVE", "wic-tools")
if not native_sysroot: if not native_sysroot:
logger.info("Unable to find the location of the native tools sysroot to use\n") raise WicError("Unable to find the location of the native "
sys.exit(1) "tools sysroot to use")
wks_file = args[0] wks_file = args[0]
if not wks_file.endswith(".wks"): if not wks_file.endswith(".wks"):
wks_file = engine.find_canned_image(scripts_path, wks_file) wks_file = engine.find_canned_image(scripts_path, wks_file)
if not wks_file: if not wks_file:
logger.error("No image named %s found, exiting. (Use 'wic list images' "\ raise WicError("No image named %s found, exiting. (Use 'wic list images' "
"to list available images, or specify a fully-qualified OE "\ "to list available images, or specify a fully-qualified OE "
"kickstart (.wks) filename)\n" % args[0]) "kickstart (.wks) filename)" % args[0])
sys.exit(1)
if not options.image_name: if not options.image_name:
rootfs_dir = '' rootfs_dir = ''
@ -229,17 +224,13 @@ def wic_create_subcommand(args, usage_str):
kernel_dir = options.kernel_dir kernel_dir = options.kernel_dir
native_sysroot = options.native_sysroot native_sysroot = options.native_sysroot
if rootfs_dir and not os.path.isdir(rootfs_dir): if rootfs_dir and not os.path.isdir(rootfs_dir):
logger.error("--roofs-dir (-r) not found, exiting\n") raise WicError("--roofs-dir (-r) not found, exiting")
sys.exit(1)
if not os.path.isdir(bootimg_dir): if not os.path.isdir(bootimg_dir):
logger.error("--bootimg-dir (-b) not found, exiting\n") raise WicError("--bootimg-dir (-b) not found, exiting")
sys.exit(1)
if not os.path.isdir(kernel_dir): if not os.path.isdir(kernel_dir):
logger.error("--kernel-dir (-k) not found, exiting\n") raise WicError("--kernel-dir (-k) not found, exiting")
sys.exit(1)
if not os.path.isdir(native_sysroot): if not os.path.isdir(native_sysroot):
logger.error("--native-sysroot (-n) not found, exiting\n") raise WicError("--native-sysroot (-n) not found, exiting")
sys.exit(1)
else: else:
not_found = not_found_dir = "" not_found = not_found_dir = ""
if not os.path.isdir(rootfs_dir): if not os.path.isdir(rootfs_dir):
@ -251,12 +242,11 @@ def wic_create_subcommand(args, usage_str):
if not_found: if not_found:
if not not_found_dir: if not not_found_dir:
not_found_dir = "Completely missing artifact - wrong image (.wks) used?" 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(" (Please check that the build artifacts for the machine")
logger.info(" selected in local.conf actually exist and that they") 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(" 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) raise WicError("The artifact that couldn't be found was %s:\n %s", not_found, not_found_dir)
sys.exit(1)
krootfs_dir = options.rootfs_dir krootfs_dir = options.rootfs_dir
if krootfs_dir is None: if krootfs_dir is None:
@ -279,9 +269,8 @@ def wic_list_subcommand(args, usage_str):
args = parser.parse_args(args)[1] args = parser.parse_args(args)[1]
if not engine.wic_list(args, scripts_path): if not engine.wic_list(args, scripts_path):
logger.error("Bad list arguments, exiting\n")
parser.print_help() parser.print_help()
sys.exit(1) raise WicError("Bad list arguments, exiting")
def wic_help_topic_subcommand(args, usage_str): def wic_help_topic_subcommand(args, usage_str):
@ -328,7 +317,7 @@ def main(argv):
if args[0] == "help": if args[0] == "help":
if len(args) == 1: if len(args) == 1:
parser.print_help() parser.print_help()
sys.exit(1) raise WicError("help command requires parameter")
return hlp.invoke_subcommand(args, parser, hlp.wic_help_usage, subcommands) return hlp.invoke_subcommand(args, parser, hlp.wic_help_usage, subcommands)
@ -337,5 +326,6 @@ if __name__ == "__main__":
try: try:
sys.exit(main(sys.argv[1:])) sys.exit(main(sys.argv[1:]))
except WicError as err: except WicError as err:
print()
logger.error(err) logger.error(err)
sys.exit(1) sys.exit(1)