From 12c5b275c4ccf292be362afb6a036095d6126451 Mon Sep 17 00:00:00 2001 From: Andrea Righi Date: Thu, 1 Dec 2022 10:51:11 +0100 Subject: [PATCH] annotations: allow to set notes directly and assume --query is the default command Allow to set a note directly to a config option without changing any value and also assume --query is the default command, so we don't have to specify --query explicitly to query config options. Signed-off-by: Andrea Righi --- annotations | 34 +++++++++++++++++++++++++--------- kconfig/annotations.py | 21 +++++++++++---------- 2 files changed, 36 insertions(+), 19 deletions(-) diff --git a/annotations b/annotations index 5af9ebd..78a8486 100755 --- a/annotations +++ b/annotations @@ -31,16 +31,15 @@ def make_parser(): help='Select flavour (default is "generic")') parser.add_argument('--config', '-c', action='store', help='Select a specific config option') - parser.add_argument('--note', '-n', action='store', - help='Write a specific note to a config option in annotations (used with --write)') - - ga = parser.add_argument_group(title='Action').add_mutually_exclusive_group(required=True) + parser.add_argument('--query', '-q', action='store_true', + help='Query annotations') + ga = parser.add_argument_group(title='Action').add_mutually_exclusive_group(required=False) ga.add_argument('--write', '-w', action='store', metavar='VALUE', dest='value', help='Set a specific config value in annotations (use \'null\' to remove)') - ga.add_argument('--query', '-q', action='store_true', - help='Query annotations') + ga.add_argument('--note', '-n', action='store', + help='Write a specific note to a config option in annotations') ga.add_argument('--export', '-e', action='store_true', help='Convert annotations to .config format') ga.add_argument('--import', '-i', action='store', @@ -66,6 +65,21 @@ def do_query(args): res = a.search_config(config=args.config, arch=args.arch, flavour=args.flavour) print(json.dumps(res, indent=4)) +def do_note(args): + if args.config is None: + arg_fail('error: --note requires --config') + + # Set the note in annotations + a = Annotation(args.file) + a.set(args.config, note=args.note) + + # Save back to annotations + a.save(args.file) + + # Query and print back the value + res = a.search_config(config=args.config) + print(json.dumps(res, indent=4)) + def do_write(args): if args.config is None: arg_fail('error: --write requires --config') @@ -172,10 +186,10 @@ def autodetect_annotations(args): def main(): args = _ARGPARSER.parse_args() autodetect_annotations(args) - if args.query: - do_query(args) - elif args.value: + if args.value: do_write(args) + elif args.note: + do_note(args) elif args.export: do_export(args) elif args.import_file: @@ -184,6 +198,8 @@ def main(): do_update(args) elif args.check_file: do_check(args) + else: + do_query(args) if __name__ == '__main__': main() diff --git a/kconfig/annotations.py b/kconfig/annotations.py index fa218e7..fd43a90 100644 --- a/kconfig/annotations.py +++ b/kconfig/annotations.py @@ -134,17 +134,18 @@ class Annotation(Config): def set(self, config : str, arch: str = None, flavour: str = None, value : str = None, note : str = None): - if config not in self.config: - self.config[config] = { 'policy': {} } - if arch is not None: - if flavour is not None: - flavour = f'{arch}-{flavour}' + if value is not None: + if config not in self.config: + self.config[config] = { 'policy': {} } + if arch is not None: + if flavour is not None: + flavour = f'{arch}-{flavour}' + else: + flavour = arch + self.config[config]['policy'][flavour] = value else: - flavour = arch - self.config[config]['policy'][flavour] = value - else: - for arch in self.arch: - self.config[config]['policy'][arch] = value + for arch in self.arch: + self.config[config]['policy'][arch] = value if note is not None: self.config[config]['note'] = "'" + note.replace("'", '') + "'" -- 2.31.1