summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbitbake/bin/bitbake-setup50
-rw-r--r--bitbake/lib/bb/tests/setup.py20
2 files changed, 41 insertions, 29 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
690def list_settings(all_settings): 688def 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
695def settings_func(top_dir, all_settings, args): 693def 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
701def get_build_dir_via_bbpath(): 699def 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)
diff --git a/bitbake/lib/bb/tests/setup.py b/bitbake/lib/bb/tests/setup.py
index b238926b29..e320cdf56f 100644
--- a/bitbake/lib/bb/tests/setup.py
+++ b/bitbake/lib/bb/tests/setup.py
@@ -232,25 +232,25 @@ print("BBPATH is {{}}".format(os.environ["BBPATH"]))
232 self.runbbsetup("--help") 232 self.runbbsetup("--help")
233 233
234 # set up global location for top-dir-prefix 234 # set up global location for top-dir-prefix
235 out = self.runbbsetup("settings --global default top-dir-prefix {}".format(self.tempdir)) 235 out = self.runbbsetup("settings set --global default top-dir-prefix {}".format(self.tempdir))
236 settings_path = "{}/global-config".format(self.tempdir) 236 settings_path = "{}/global-config".format(self.tempdir)
237 self.assertIn(settings_path, out[0]) 237 self.assertIn(settings_path, out[0])
238 self.assertIn("Setting 'top-dir-prefix' in section 'default' is changed to", out[0]) 238 self.assertIn("From section 'default' the setting 'top-dir-prefix' was changed to", out[0])
239 self.assertIn("New settings written to".format(settings_path), out[0]) 239 self.assertIn("Settings written to".format(settings_path), out[0])
240 out = self.runbbsetup("settings --global default dl-dir {}".format(os.path.join(self.tempdir, 'downloads'))) 240 out = self.runbbsetup("settings set --global default dl-dir {}".format(os.path.join(self.tempdir, 'downloads')))
241 self.assertIn("Setting 'dl-dir' in section 'default' is changed to", out[0]) 241 self.assertIn("From section 'default' the setting 'dl-dir' was changed to", out[0])
242 self.assertIn("New settings written to".format(settings_path), out[0]) 242 self.assertIn("Settings written to".format(settings_path), out[0])
243 243
244 # check that writing settings works and then adjust them to point to 244 # check that writing settings works and then adjust them to point to
245 # test registry repo 245 # test registry repo
246 out = self.runbbsetup("settings default registry 'git://{};protocol=file;branch=master;rev=master'".format(self.registrypath)) 246 out = self.runbbsetup("settings set default registry 'git://{};protocol=file;branch=master;rev=master'".format(self.registrypath))
247 settings_path = "{}/bitbake-builds/settings.conf".format(self.tempdir) 247 settings_path = "{}/bitbake-builds/settings.conf".format(self.tempdir)
248 self.assertIn(settings_path, out[0]) 248 self.assertIn(settings_path, out[0])
249 self.assertIn("Setting 'registry' in section 'default' is changed to", out[0]) 249 self.assertIn("From section 'default' the setting 'registry' was changed to", out[0])
250 self.assertIn("New settings written to".format(settings_path), out[0]) 250 self.assertIn("Settings written to".format(settings_path), out[0])
251 251
252 # check that listing settings works 252 # check that listing settings works
253 out = self.runbbsetup("settings --list") 253 out = self.runbbsetup("settings list")
254 self.assertIn("default top-dir-prefix {}".format(self.tempdir), out[0]) 254 self.assertIn("default top-dir-prefix {}".format(self.tempdir), out[0])
255 self.assertIn("default dl-dir {}".format(os.path.join(self.tempdir, 'downloads')), out[0]) 255 self.assertIn("default dl-dir {}".format(os.path.join(self.tempdir, 'downloads')), out[0])
256 self.assertIn("default registry {}".format('git://{};protocol=file;branch=master;rev=master'.format(self.registrypath)), out[0]) 256 self.assertIn("default registry {}".format('git://{};protocol=file;branch=master;rev=master'.format(self.registrypath)), out[0])