'CONFIG_BINDGEN_VERSION_TEXT',
)
+
def make_parser():
parser = argparse.ArgumentParser(
description='Manage Ubuntu kernel .config and annotations',
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')
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')
exit(1)
os.system(f'vim -t {args.config}')
+
def do_note(args):
if args.config is None:
arg_fail('error: --note requires --config')
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')
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')
if conf:
print(a.to_config(conf))
+
def do_import(args):
if args.arch is None:
arg_fail('error: --arch is required with --import')
# 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')
# Save back to annotations
a.save(args.file)
+
def do_check(args):
# Determine arch and flavour
if args.arch is None:
print(f"check-config: {good}/{total} checks passed -- exit {ret}")
exit(ret)
+
def autodetect_annotations(args):
if args.file:
return
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)
else:
do_query(args)
+
if __name__ == '__main__':
main()
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):
"""
""" 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
self.config[m.group(1)] = literal_eval("'" + m.group(2) + "'")
continue
+
class Annotation(Config):
"""
Parse body of annotations file