From 00c5085505d4ae8b5128784dfe163ec9792d3ca2 Mon Sep 17 00:00:00 2001 From: Juerg Haefliger Date: Fri, 10 Feb 2023 08:34:13 +0100 Subject: [PATCH] Fix flake8 violations Signed-off-by: Juerg Haefliger --- annotations | 16 ++++++++++++++++ kconfig/annotations.py | 3 +++ 2 files changed, 19 insertions(+) diff --git a/annotations b/annotations index 5caa3b2..7e7ff5e 100755 --- a/annotations +++ b/annotations @@ -28,6 +28,7 @@ SKIP_CONFIGS = ( 'CONFIG_BINDGEN_VERSION_TEXT', ) + def make_parser(): parser = argparse.ArgumentParser( description='Manage Ubuntu kernel .config and annotations', @@ -68,18 +69,22 @@ def make_parser(): help='Validate kernel .config with annotations') return parser + _ARGPARSER = make_parser() + def arg_fail(message): print(message) _ARGPARSER.print_usage() exit(1) + def print_result(config, res): if res is not None and config not in res: res = {config or '*': res} print(json.dumps(res, indent=4)) + def do_query(args): if args.arch is None and args.flavour is not None: arg_fail('error: --flavour requires --arch') @@ -87,11 +92,13 @@ def do_query(args): res = a.search_config(config=args.config, arch=args.arch, flavour=args.flavour) print_result(args.config, res) + def do_autocomplete(args): a = Annotation(args.file) res = (c.removeprefix('CONFIG_') for c in a.search_config()) print('complete -W "{}" annotations'.format(' '.join(res))) + def do_source(args): if args.config is None: arg_fail('error: --source requires --config') @@ -100,6 +107,7 @@ def do_source(args): exit(1) os.system(f'vim -t {args.config}') + def do_note(args): if args.config is None: arg_fail('error: --note requires --config') @@ -116,6 +124,7 @@ def do_note(args): res = a.search_config(config=args.config) print_result(args.config, res) + def do_write(args): if args.config is None: arg_fail('error: --write requires --config') @@ -135,6 +144,7 @@ def do_write(args): res = a.search_config(config=args.config) print_result(args.config, res) + def do_export(args): if args.arch is None: arg_fail('error: --export requires --arch') @@ -143,6 +153,7 @@ def do_export(args): if conf: print(a.to_config(conf)) + def do_import(args): if args.arch is None: arg_fail('error: --arch is required with --import') @@ -159,6 +170,7 @@ def do_import(args): # Save back to annotations a.save(args.file) + def do_update(args): if args.arch is None: arg_fail('error: --arch is required with --update') @@ -174,6 +186,7 @@ def do_update(args): # Save back to annotations a.save(args.file) + def do_check(args): # Determine arch and flavour if args.arch is None: @@ -210,6 +223,7 @@ def do_check(args): print(f"check-config: {good}/{total} checks passed -- exit {ret}") exit(ret) + def autodetect_annotations(args): if args.file: return @@ -221,6 +235,7 @@ def autodetect_annotations(args): except Exception: arg_fail('error: could not determine DEBDIR, try using: --file/-f') + def main(): # Prevent broken pipe errors when showing output in pipe to other tools # (less for example) @@ -252,5 +267,6 @@ def main(): else: do_query(args) + if __name__ == '__main__': main() diff --git a/kconfig/annotations.py b/kconfig/annotations.py index 1711257..19fb544 100644 --- a/kconfig/annotations.py +++ b/kconfig/annotations.py @@ -10,6 +10,7 @@ import tempfile from ast import literal_eval from os.path import dirname, abspath + class Config(object): def __init__(self, fname: str, arch: str = None, flavour: str = None): """ @@ -28,6 +29,7 @@ class Config(object): """ Return a JSON representation of the config """ return json.dumps(self.config, indent=4) + class KConfig(Config): """ Parse a .config file, individual config options can be accessed via @@ -45,6 +47,7 @@ class KConfig(Config): self.config[m.group(1)] = literal_eval("'" + m.group(2) + "'") continue + class Annotation(Config): """ Parse body of annotations file -- 2.31.1