annotations: automatically detect annotations file location
authorAndrea Righi <andrea.righi@canonical.com>
Mon, 14 Nov 2022 18:00:54 +0000 (19:00 +0100)
committerAndrea Righi <andrea.righi@canonical.com>
Mon, 14 Nov 2022 18:00:54 +0000 (19:00 +0100)
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
annotations

index 4cff368e8837e012a28010389a4b8887efa929ba..adb397df526d49224e60fcd7f46c067a3658713e 100755 (executable)
@@ -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: