Fix for #9636: wic script should use argparse instead of optparse
cover Fix for #9636: wic script should use argparse instead of optparse
Hi,
This patchset contains two patches from Andreas J. Reichel's patchset and a fix for wic test case.
Description taken from the original patchset:
wic uses optparse and a rather complicated approach of its initialization. It is much easier to switch from the deprecated optparse to the argparse library, which also supports sub-commands, which wic heavily makes use of.
The following changes since commit 381897c64069ea43d595380a3ae913bcc79cf7e1:
build-appliance-image: Update to master head revision (2017-05-01 08:56:47 +0100)
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
Andreas J. Reichel (2):
wic: Use argparse instead of optparse
wic: Add missing text to usage and help strings
Ed Bartosh (1):
selftest: fix test_unsupported_subcommand test case
meta/lib/oeqa/selftest/wic.py | 3 +- scripts/lib/wic/engine.py | 11 ++- scripts/lib/wic/help.py | 25 +++-- scripts/wic | 213 ++++++++++++++++++++++++++---------------- 4 files changed, 156 insertions(+), 96 deletions(-)
--
Regards,
Ed
PATCH 1/3 wic: Use argparse instead of optparse
From: "Andreas J. Reichel" <[email protected]>
* optparse is deprecated and will not be developed further (see: https://docs.python.org/2/library/optparse.html)
* argparse supports subcommands, which simplifies definition of arguments and options
* reimplement help mechanism through sub-subcommands
[YOCTO #9636]
--- scripts/lib/wic/engine.py | 11 +-- scripts/lib/wic/help.py | 23 +++-- scripts/wic | 213 ++++++++++++++++++++++++++++------------------ 3 files changed, 154 insertions(+), 93 deletions(-)
scripts/lib/wic/engine.py +6 -5
@@ -201,17 +201,18 @@ def wic_list(args, scripts_path): """ Print the list of images or source plugins. """ - if len(args) < 1: + if args.list_type is None: return False - if args == ["images"]: + if args.list_type == "images": + list_canned_images(scripts_path) return True - elif args == ["source-plugins"]: + elif args.list_type == "source-plugins": list_source_plugins() return True - elif len(args) == 2 and args[1] == "help": - wks_file = args[0] + elif len(args.help_for) == 1 and args.help_for[0] == 'help': + wks_file = args.list_type fullpath = find_canned_image(scripts_path, wks_file) if not fullpath: raise WicError("No image named %s found, exiting. "
scripts/lib/wic/help.py +16 -7
@@ -56,7 +56,7 @@ def wic_help(args, usage_str, subcommands): """ Subcommand help dispatcher. """ - if len(args) == 1 or not display_help(args[1], subcommands): + if args.help_topic == None or not display_help(args.help_topic, subcommands): print(usage_str)
@@ -82,19 +82,20 @@ def invoke_subcommand(args, parser, main_command_usage, subcommands): Dispatch to subcommand handler borrowed from combo-layer. Should use argparse, but has to work in 2.6. """ - if not args: + if not args.command: logger.error("No subcommand specified, exiting") parser.print_help() return 1 - elif args[0] == "help": + elif args.command == "help": wic_help(args, main_command_usage, subcommands) - elif args[0] not in subcommands: - logger.error("Unsupported subcommand %s, exiting\n", args[0]) + elif args.command not in subcommands: + logger.error("Unsupported subcommand %s, exiting\n", args.command) parser.print_help() return 1 else: - usage = subcommands.get(args[0], subcommand_error)[1] - subcommands.get(args[0], subcommand_error)[0](args[1:], usage) + subcmd = subcommands.get(args.command, subcommand_error) + usage = subcmd[1] + subcmd[0](args, usage) ##
@@ -795,3 +796,11 @@ DESCRIPTION .wks files. """ + +wic_help_help = """ +NAME + wic help - display a help topic + +DESCRIPTION + Specify a help topic to display it. Topics are shown above. +"""
scripts/wic +132 -81
278 lines not on this page · raw message
Signature · 1 line
2.1.4
PATCH 2/3 wic: Add missing text to usage and help strings
In reply to Ed BartoshFrom: "Andreas J. Reichel" <[email protected]>
Add missing parameters -c to and remove non-existent parameter -i from usage string for 'wic create'.
--- scripts/lib/wic/help.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/lib/wic/help.py +1 -1
@@ -131,10 +131,10 @@ wic_create_usage = """ Create a new OpenEmbedded image usage: wic create <wks file or image name> [-o <DIRNAME> | --outdir <DIRNAME>] - [-i <JSON PROPERTY FILE> | --infile <JSON PROPERTY_FILE>] [-e | --image-name] [-s, --skip-build-check] [-D, --debug] [-r, --rootfs-dir] [-b, --bootimg-dir] [-k, --kernel-dir] [-n, --native-sysroot] [-f, --build-rootfs] + [-c, --compress-with] [-m, --bmap] This command creates an OpenEmbedded image based on the 'OE kickstart commands' found in the <wks file>.
Signature · 1 line
2.1.4
PATCH 3/3 selftest: fix test_unsupported_subcommand test case
In reply to Ed BartoshFixed failure of test_unsupported_subcommand caused by switching to argparser by checking that parser returns non-zero return code.
[YOCTO #9636]
--- meta/lib/oeqa/selftest/wic.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
meta/lib/oeqa/selftest/wic.py +1 -2
@@ -159,8 +159,7 @@ class Wic(oeSelfTest): @testcase(1213) def test_unsupported_subcommand(self): """Test unsupported subcommand""" - self.assertEqual(1, runCmd('wic unsupported', - ignore_status=True).status) + self.assertNotEqual(0, runCmd('wic unsupported', ignore_status=True).status) @testcase(1214) def test_no_command(self):
Signature · 1 line
2.1.4