From 5e183e319a114ce5f2caa1c06063c3045b69f762 Mon Sep 17 00:00:00 2001 From: Andrea Righi Date: Mon, 14 Nov 2022 19:00:54 +0100 Subject: [PATCH] annotations: automatically detect annotations file location Signed-off-by: Andrea Righi --- annotations | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/annotations b/annotations index 4cff368..adb397d 100755 --- a/annotations +++ b/annotations @@ -16,7 +16,7 @@ def make_parser(): ) parser.add_argument('--version', '-v', action='version', version=f'%(prog)s {VERSION}') - parser.add_argument('--file', '-f', action='store', required=True, + parser.add_argument('--file', '-f', action='store', help='Pass annotations or .config file to be parsed') parser.add_argument('--arch', '-a', action='store', help='Select architecture') @@ -102,8 +102,20 @@ def do_check(args): print(f"check-config: {good}/{total} checks passed -- exit {ret}") exit(ret) +def autodetect_annotations(args): + if args.file: + return + # If --file/-f isn't specified try to automatically determine the right + # location of the annotations file looking at debian/debian.env. + try: + with open('debian/debian.env', 'rt') as fd: + args.file = fd.read().rstrip().split('=')[1] + '/config/annotations' + except: + print('error: could not determine DEBDIR, try using: --file/-f') + def main(): args = _ARGPARSER.parse_args() + autodetect_annotations(args) if args.query: do_query(args) elif args.export: -- 2.31.1