diff options
| author | Johannes Schneider <johannes.schneider@leica-geosystems.com> | 2025-10-12 19:47:27 +0200 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2025-10-14 11:24:57 +0100 |
| commit | 7320e59aecbaac830d912dd4c0e68b5963c25db4 (patch) | |
| tree | 3e9a591cb64398f3028f813e9d820bf71afaa593 /bitbake/bin | |
| parent | 897f3020daa12ae9e70943c82f780515b1666e9b (diff) | |
| download | poky-7320e59aecbaac830d912dd4c0e68b5963c25db4.tar.gz | |
bitbake: bitbake-setup: commandline: use subsubparser for settings {list,set,unset}
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>
(Bitbake rev: 8b582ef8dd0cef0192d4c0104bcd9b5d642d132c)
Signed-off-by: Johannes Schneider <johannes.schneider@leica-geosystems.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/bin')
| -rwxr-xr-x | bitbake/bin/bitbake-setup | 50 |
1 files changed, 31 insertions, 19 deletions
diff --git a/bitbake/bin/bitbake-setup b/bitbake/bin/bitbake-setup index 94e38b472c..38bb8099fd 100755 --- a/bitbake/bin/bitbake-setup +++ b/bitbake/bin/bitbake-setup | |||
| @@ -670,22 +670,20 @@ def change_setting(top_dir, args): | |||
| 670 | settings_path = default_settings_path(top_dir) | 670 | settings_path = default_settings_path(top_dir) |
| 671 | settings = load_settings(settings_path) | 671 | settings = load_settings(settings_path) |
| 672 | 672 | ||
| 673 | if args.section and args.key and args.value: | 673 | if args.subcommand == 'set': |
| 674 | if args.section not in settings.keys(): | 674 | if args.section not in settings.keys(): |
| 675 | settings[args.section] = {} | 675 | settings[args.section] = {} |
| 676 | settings[args.section][args.key] = args.value | 676 | settings[args.section][args.setting] = args.value |
| 677 | print("Setting '{}' in section '{}' is changed to '{}'".format(args.key, args.section, args.value)) | 677 | print(f"From section '{args.section}' the setting '{args.setting}' was changed to '{args.value}'") |
| 678 | if args.unset: | 678 | if args.subcommand == 'unset': |
| 679 | section = args.unset[0] | 679 | if args.section in settings.keys() and args.setting in settings[args.section].keys(): |
| 680 | setting = args.unset[1] | 680 | del settings[args.section][args.setting] |
| 681 | if section in settings.keys() and setting in settings[section].keys(): | 681 | print(f"From section '{args.section}' the setting '{args.setting}' has been removed") |
| 682 | del settings[section][setting] | ||
| 683 | print("Setting '{} in section '{}' is removed".format(setting, section)) | ||
| 684 | 682 | ||
| 685 | os.makedirs(os.path.dirname(settings_path), exist_ok=True) | 683 | os.makedirs(os.path.dirname(settings_path), exist_ok=True) |
| 686 | with open(settings_path, 'w') as settingsfile: | 684 | with open(settings_path, 'w') as settingsfile: |
| 687 | settings.write(settingsfile) | 685 | settings.write(settingsfile) |
| 688 | print("New settings written to {}".format(settings_path)) | 686 | print(f"Settings written to {settings_path}") |
| 689 | 687 | ||
| 690 | def list_settings(all_settings): | 688 | def list_settings(all_settings): |
| 691 | for section, section_settings in all_settings.items(): | 689 | for section, section_settings in all_settings.items(): |
| @@ -693,9 +691,9 @@ def list_settings(all_settings): | |||
| 693 | print("{} {} {}".format(section, key, value)) | 691 | print("{} {} {}".format(section, key, value)) |
| 694 | 692 | ||
| 695 | def settings_func(top_dir, all_settings, args): | 693 | def settings_func(top_dir, all_settings, args): |
| 696 | if args.list: | 694 | if args.subcommand == 'list': |
| 697 | list_settings(all_settings) | 695 | list_settings(all_settings) |
| 698 | else: | 696 | elif args.subcommand == 'set' or args.subcommand == 'unset': |
| 699 | change_setting(top_dir, args) | 697 | change_setting(top_dir, args) |
| 700 | 698 | ||
| 701 | def get_build_dir_via_bbpath(): | 699 | def get_build_dir_via_bbpath(): |
| @@ -784,15 +782,29 @@ def main(): | |||
| 784 | parser_install_buildtools.add_argument('--force', action='store_true', help='Force a reinstall of buildtools over the previous installation.') | 782 | parser_install_buildtools.add_argument('--force', action='store_true', help='Force a reinstall of buildtools over the previous installation.') |
| 785 | parser_install_buildtools.set_defaults(func=install_buildtools) | 783 | parser_install_buildtools.set_defaults(func=install_buildtools) |
| 786 | 784 | ||
| 787 | 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)') | 785 | parser_settings_arg_global = argparse.ArgumentParser(add_help=False) |
| 788 | parser_settings.add_argument('section', nargs='?', help="Section in a settings file, typically 'default'") | 786 | 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") |
| 789 | parser_settings.add_argument('key', nargs='?', help="Name of the setting") | 787 | |
| 790 | parser_settings.add_argument('value', nargs='?', help="Value of the setting") | 788 | parser_settings = subparsers.add_parser('settings', parents=[parser_settings_arg_global], |
| 791 | 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") | 789 | 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)') |
| 792 | 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") | ||
| 793 | parser_settings.add_argument('-l' ,'--list', action='store_true', help="List all settings with their values") | ||
| 794 | parser_settings.set_defaults(func=settings_func) | 790 | parser_settings.set_defaults(func=settings_func) |
| 795 | 791 | ||
| 792 | subparser_settings = parser_settings.add_subparsers(dest="subcommand", required=True, help="The action to perform on the settings file") | ||
| 793 | |||
| 794 | parser_settings_list = subparser_settings.add_parser('list', | ||
| 795 | help="List all settings with their values") | ||
| 796 | |||
| 797 | parser_settings_set = subparser_settings.add_parser('set', parents=[parser_settings_arg_global], | ||
| 798 | help="In a Section, set a setting to a certain value") | ||
| 799 | parser_settings_set.add_argument("section", metavar="<section>", help="Section in a settings file, typically 'default'") | ||
| 800 | parser_settings_set.add_argument("setting", metavar="<setting>", help="Name of a setting") | ||
| 801 | parser_settings_set.add_argument("value", metavar="<value>", help="The setting value") | ||
| 802 | |||
| 803 | parser_settings_unset = subparser_settings.add_parser('unset', parents=[parser_settings_arg_global], | ||
| 804 | help="Unset a setting, e.g. 'bitbake-setup settings unset default registry' would revert to the registry setting in a global settings file") | ||
| 805 | parser_settings_unset.add_argument("section", metavar="<section>", help="Section in a settings file, typically 'default'") | ||
| 806 | parser_settings_unset.add_argument("setting", metavar="<setting>", help="The setting to remove") | ||
| 807 | |||
| 796 | args = parser.parse_args() | 808 | args = parser.parse_args() |
| 797 | 809 | ||
| 798 | logging.basicConfig(stream=sys.stdout) | 810 | logging.basicConfig(stream=sys.stdout) |
