bitbake-setup: correct 'setting' to 'settings' in a couple of help texts
PATCH 1/5 bitbake-setup: correct 'setting' to 'settings' in a couple of help texts
From: Alexander Kanavin <[email protected]>
--- bin/bitbake-setup | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
bin/bitbake-setup +2 -2
@@ -787,7 +787,7 @@ def main(): parser_settings.add_argument('key', nargs='?', help="Name of the setting") parser_settings.add_argument('value', nargs='?', help="Value of the setting") parser_settings.add_argument('--global', action='store_true', help="Modify the setting in a global settings file, rather than one specific to a top directory") - parser_settings.add_argument('--unset', nargs=2, help="Unset a setting, e.g. 'bitbake-setup setting --unset default registry' would revert to the registry setting in a global settings file") + parser_settings.add_argument('--unset', nargs=2, help="Unset a setting, e.g. 'bitbake-setup settings --unset default registry' would revert to the registry setting in a global settings file") parser_settings.add_argument('-l' ,'--list', action='store_true', help="List all settings with their values") parser_settings.set_defaults(func=settings_func)
@@ -834,7 +834,7 @@ def main(): settings_func(top_dir, all_settings, args) return - print('Bitbake-setup is using {} as top directory ("bitbake-setup setting --help" shows how to change it).\n'.format(top_dir, global_settings_path(args))) + print('Bitbake-setup is using {} as top directory ("bitbake-setup settings --help" shows how to change it).\n'.format(top_dir, global_settings_path(args))) d = init_bb_cache(top_dir, all_settings, args) args.func(top_dir, all_settings, args, d)
Signature · 1 line
2.39.5
PATCH 2/5 bitbake-setup: init: suggest removing a partially initialized top-dir
From: Johannes Schneider <[email protected]>
In cases where the first call to 'init' failed or was aborted before creating the 'build/init-build-env' has been created, a user can get
stuck: a second call to init aborts, suggesting 'status' or 'update' but these to refuse because the --build-dir is not valid.
Guide the user by adding a suggestion to start over from scratch.
--- bin/bitbake-setup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
bin/bitbake-setup +1 -1
@@ -443,7 +443,7 @@ def init_config(top_dir, settings, args, d): builddir = os.path.join(os.path.abspath(top_dir), args.build_dir_name or "{}-{}".format(upstream_config['name']," ".join(upstream_config['non-interactive-cmdline-options'][1:]).replace(" ","-").replace("/","_"))) if os.path.exists(os.path.join(builddir, "layers")): - print("Build already initialized in {}\nUse 'bitbake-setup status' to check if it needs to be updated or 'bitbake-setup update' to perform the update.".format(builddir)) + print(f"Build already initialized in:\n {builddir}\nUse 'bitbake-setup status' to check if it needs to be updated, or 'bitbake-setup update' to perform the update.\nIf you would like to start over and re-initialize a build in this directory, remove it, and run 'bitbake-setup init' again.") return print("Initializing a build in\n {}".format(builddir))
Signature · 1 line
2.39.5
PATCH 3/5 bitbake-setup: use args.cmdline_settings for --settings
In reply to Alexander KanavinFrom: Johannes Schneider <[email protected]>
To align the storage destination with the internally used variable name. This makes room for having another option use 'args.setting'
--- bin/bitbake-setup | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
bin/bitbake-setup +4 -3
@@ -752,7 +752,8 @@ def main(): parser.add_argument('--color', choices=['auto', 'always', 'never'], default='auto', help='Colorize output (where %(metavar)s is %(choices)s)', metavar='COLOR') parser.add_argument('--no-network', action='store_true', help='Do not check whether configuration repositories and layer repositories have been updated; use only the local cache.') parser.add_argument('--global-settings', action='store', help='Path to the global settings file.') - parser.add_argument('--setting', default=[], action='append', nargs=3, help='Modify a setting (for this bitbake-setup invocation only), for example "--setting default top-dir-prefix /path/to/top/dir".') + parser.add_argument('--setting', default=[], dest='cmdline_settings', action='append', nargs=3, + help='Modify a setting (for this bitbake-setup invocation only), for example "--setting default top-dir-prefix /path/to/top/dir".') subparsers = parser.add_subparsers()
@@ -822,13 +823,13 @@ def main(): } global_settings = load_settings(global_settings_path(args)) - top_dir = get_top_dir(args, merge_settings(builtin_settings, global_settings, {}, args.setting)) + top_dir = get_top_dir(args, merge_settings(builtin_settings, global_settings, {}, args.cmdline_settings)) # This cannot be set with the rest of the builtin settings as top_dir needs to be determined first builtin_settings['default']['dl-dir'] = os.path.join(top_dir, '.bitbake-setup-downloads') topdir_settings = load_settings(default_settings_path(top_dir)) - all_settings = merge_settings(builtin_settings, global_settings, topdir_settings, args.setting) + all_settings = merge_settings(builtin_settings, global_settings, topdir_settings, args.cmdline_settings) if args.func == settings_func: settings_func(top_dir, all_settings, args)
Signature · 1 line
2.39.5
PATCH 4/5 bitbake-setup: add 'metavar' for self-descriptive parameters
In reply to Alexander KanavinFrom: Johannes Schneider <[email protected]>
Add a metavar to the argparse options to have a self-descriptive help text. Otherwise argpase defaults to use the argument name in all-uppercase.
Before:
usage: bitbake-setup [-h] [-d] [-q] [--color COLOR] [--no-network] [--global-settings GLOBAL_SETTINGS] [--setting SETTING SETTING SETTING]
{list,init,status,update,install-buildtools,settings} ...
After:
usage: bitbake-setup [-h] [-d] [-q] [--color COLOR] [--no-network] [--global-settings PATH] [--setting SECTION SETTING VALUE]
{list,init,status,update,install-buildtools,settings} ...
--- bin/bitbake-setup | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
bin/bitbake-setup +3 -2
@@ -751,8 +751,9 @@ def main(): parser.add_argument('-q', '--quiet', help='Print only errors', action='store_true') parser.add_argument('--color', choices=['auto', 'always', 'never'], default='auto', help='Colorize output (where %(metavar)s is %(choices)s)', metavar='COLOR') parser.add_argument('--no-network', action='store_true', help='Do not check whether configuration repositories and layer repositories have been updated; use only the local cache.') - parser.add_argument('--global-settings', action='store', help='Path to the global settings file.') - parser.add_argument('--setting', default=[], dest='cmdline_settings', action='append', nargs=3, + parser.add_argument('--global-settings', action='store', metavar='PATH', help='Path to the global settings file.') + parser.add_argument('--setting', default=[], action='append', dest='cmdline_settings', + nargs=3, metavar=('SECTION', 'SETTING', 'VALUE'), help='Modify a setting (for this bitbake-setup invocation only), for example "--setting default top-dir-prefix /path/to/top/dir".') subparsers = parser.add_subparsers()
Signature · 1 line
2.39.5
PATCH 5/5 bitbake-setup: commandline: use subsubparser for settings {list,set,unset}
In reply to Alexander KanavinFrom: Johannes Schneider <[email protected]>
Previously the sub-command 'settings' would take any number of arguments and then silently do nothing if the number wasn't three.
The help text was also not clear about this, marking the positionals separately as optional:
usage: bitbake-setup settings [-h] [--global] [--unset UNSET UNSET] [-l] [section] [key] [value]
The '--unset SECTION SETTING' also did not integrate too well, as it had its own positional arguments for section+setting.
For a bit more consistency and a explorable help, a sub-subparser is added, that provides the commands:
bitbake-setup settings list
bitbake-setup settings set foo bar baz
bitbake-setup settings unset foo bar
with a '--global' that is added from a stand-alone parent parser, so that it shows up in all sub-command help texts.
The new help text now reads:
usage: bitbake-setup settings [-h] [--global] {list,set,unset} ...
and the respective sub commands:
usage: bitbake-setup settings list [-h] [--global]
usage: bitbake-setup settings set [-h] [--global] <section> <setting> <value>
usage: bitbake-setup settings unset [-h] [--global] <section> <setting>
--- bin/bitbake-setup | 50 +++++++++++++++++++++++++++---------------- lib/bb/tests/setup.py | 20 ++++++++--------- 2 files changed, 41 insertions(+), 29 deletions(-)
bin/bitbake-setup +31 -19
@@ -670,22 +670,20 @@ def change_setting(top_dir, args): settings_path = default_settings_path(top_dir) settings = load_settings(settings_path) - if args.section and args.key and args.value: + if args.subcommand == 'set': if args.section not in settings.keys(): settings[args.section] = {} - settings[args.section][args.key] = args.value - print("Setting '{}' in section '{}' is changed to '{}'".format(args.key, args.section, args.value)) - if args.unset: - section = args.unset[0] - setting = args.unset[1] - if section in settings.keys() and setting in settings[section].keys(): - del settings[section][setting] - print("Setting '{} in section '{}' is removed".format(setting, section)) + settings[args.section][args.setting] = args.value + print(f"From section '{args.section}' the setting '{args.setting}' was changed to '{args.value}'") + if args.subcommand == 'unset': + if args.section in settings.keys() and args.setting in settings[args.section].keys(): + del settings[args.section][args.setting] + print(f"From section '{args.section}' the setting '{args.setting}' has been removed") os.makedirs(os.path.dirname(settings_path), exist_ok=True) with open(settings_path, 'w') as settingsfile: settings.write(settingsfile) - print("New settings written to {}".format(settings_path)) + print(f"Settings written to {settings_path}") def list_settings(all_settings): for section, section_settings in all_settings.items():
@@ -693,9 +691,9 @@ def list_settings(all_settings): print("{} {} {}".format(section, key, value)) def settings_func(top_dir, all_settings, args): - if args.list: + if args.subcommand == 'list': list_settings(all_settings) - else: + elif args.subcommand == 'set' or args.subcommand == 'unset': change_setting(top_dir, args) def get_build_dir_via_bbpath():
@@ -784,15 +782,29 @@ def main(): parser_install_buildtools.add_argument('--force', action='store_true', help='Force a reinstall of buildtools over the previous installation.') parser_install_buildtools.set_defaults(func=install_buildtools) - parser_settings = subparsers.add_parser('settings', help='List current settings, or set or unset a setting in a settings file (e.g. the default prefix and name of the top directory, the location of build configuration registry, downloads directory and other settings specific to a top directory)') - parser_settings.add_argument('section', nargs='?', help="Section in a settings file, typically 'default'") - parser_settings.add_argument('key', nargs='?', help="Name of the setting") - parser_settings.add_argument('value', nargs='?', help="Value of the setting") - parser_settings.add_argument('--global', action='store_true', help="Modify the setting in a global settings file, rather than one specific to a top directory") - parser_settings.add_argument('--unset', nargs=2, help="Unset a setting, e.g. 'bitbake-setup settings --unset default registry' would revert to the registry setting in a global settings file") - parser_settings.add_argument('-l' ,'--list', action='store_true', help="List all settings with their values") + parser_settings_arg_global = argparse.ArgumentParser(add_help=False) + parser_settings_arg_global.add_argument('--global', action='store_true', help="Modify the setting in a global settings file, rather than one specific to a top directory") + + parser_settings = subparsers.add_parser('settings', parents=[parser_settings_arg_global], + help='List current settings, or set or unset a setting in a settings file (e.g. the default prefix and name of the top directory, the location of build configuration registry, downloads directory and other settings specific to a top directory)') parser_settings.set_defaults(func=settings_func) + subparser_settings = parser_settings.add_subparsers(dest="subcommand", required=True, help="The action to perform on the settings file") + + parser_settings_list = subparser_settings.add_parser('list', + help="List all settings with their values") + + parser_settings_set = subparser_settings.add_parser('set', parents=[parser_settings_arg_global], + help="In a Section, set a setting to a certain value") + parser_settings_set.add_argument("section", metavar="<section>", help="Section in a settings file, typically 'default'") + parser_settings_set.add_argument("setting", metavar="<setting>", help="Name of a setting") + parser_settings_set.add_argument("value", metavar="<value>", help="The setting value") + + parser_settings_unset = subparser_settings.add_parser('unset', parents=[parser_settings_arg_global], + help="Unset a setting, e.g. 'bitbake-setup settings unset default registry' would revert to the registry setting in a global settings file") + parser_settings_unset.add_argument("section", metavar="<section>", help="Section in a settings file, typically 'default'") + parser_settings_unset.add_argument("setting", metavar="<setting>", help="The setting to remove") + args = parser.parse_args() logging.basicConfig(stream=sys.stdout)
lib/bb/tests/setup.py +10 -10
@@ -232,25 +232,25 @@ print("BBPATH is {{}}".format(os.environ["BBPATH"])) self.runbbsetup("--help") # set up global location for top-dir-prefix - out = self.runbbsetup("settings --global default top-dir-prefix {}".format(self.tempdir)) + out = self.runbbsetup("settings set --global default top-dir-prefix {}".format(self.tempdir)) settings_path = "{}/global-config".format(self.tempdir) self.assertIn(settings_path, out[0]) - self.assertIn("Setting 'top-dir-prefix' in section 'default' is changed to", out[0]) - self.assertIn("New settings written to".format(settings_path), out[0]) - out = self.runbbsetup("settings --global default dl-dir {}".format(os.path.join(self.tempdir, 'downloads'))) - self.assertIn("Setting 'dl-dir' in section 'default' is changed to", out[0]) - self.assertIn("New settings written to".format(settings_path), out[0]) + self.assertIn("From section 'default' the setting 'top-dir-prefix' was changed to", out[0]) + self.assertIn("Settings written to".format(settings_path), out[0]) + out = self.runbbsetup("settings set --global default dl-dir {}".format(os.path.join(self.tempdir, 'downloads'))) + self.assertIn("From section 'default' the setting 'dl-dir' was changed to", out[0]) + self.assertIn("Settings written to".format(settings_path), out[0]) # check that writing settings works and then adjust them to point to # test registry repo - out = self.runbbsetup("settings default registry 'git://{};protocol=file;branch=master;rev=master'".format(self.registrypath)) + out = self.runbbsetup("settings set default registry 'git://{};protocol=file;branch=master;rev=master'".format(self.registrypath)) settings_path = "{}/bitbake-builds/settings.conf".format(self.tempdir) self.assertIn(settings_path, out[0]) - self.assertIn("Setting 'registry' in section 'default' is changed to", out[0]) - self.assertIn("New settings written to".format(settings_path), out[0]) + self.assertIn("From section 'default' the setting 'registry' was changed to", out[0]) + self.assertIn("Settings written to".format(settings_path), out[0]) # check that listing settings works - out = self.runbbsetup("settings --list") + out = self.runbbsetup("settings list") self.assertIn("default top-dir-prefix {}".format(self.tempdir), out[0]) self.assertIn("default dl-dir {}".format(os.path.join(self.tempdir, 'downloads')), out[0]) self.assertIn("default registry {}".format('git://{};protocol=file;branch=master;rev=master'.format(self.registrypath)), out[0])
Signature · 1 line
2.39.5
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [bitbake-devel] [PATCH 5/5] bitbake-setup: commandline: use subsubparser for settings {list,set,unset}
Quoted 7 lines · Alexander Kanavin via lists.openembedded.org
The new help text now reads:
usage: bitbake-setup settings [-h] [--global] {list,set,unset} ...and the respective sub commands:
usage: bitbake-setup settings list [-h] [--global]
usage: bitbake-setup settings set [-h] [--global] <section> <setting> <value>
usage: bitbake-setup settings unset [-h] [--global] <section> <setting>
A note from me: I'm well aware this changes the settings UI yet again, at the 11th hour, and I'm feeling slightly uneasy sending it, but I still think it's a worthy improvement:
- currently bitbake-setup tries to mimic older versions of 'git config' UI. But those older versions offer a confusing, convoluted mess, and shouldn't be imitated. This change adds a nice bit of structure and clarity to the operations, and follows what recently released versions of 'git config' do [1].
- the principle of reading global/local/commandline levels of settings and not creating them unless asked to and all other existing functionality is retained
- the needed tweak is basically inserting 'set' into places where a setting is set, so it's a small one
- something like this should be done now, otherwise we're stuck with a sub-optimal UI.
[1] https://git-scm.com/docs/git-config (see also 'deprecated modes' section for the obsoleted UI)
Alex