From 8af1c8da7de52a604f1b621cadd0411975bfb236 Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Sat, 2 Dec 2023 01:09:46 +0600 Subject: [PATCH] Add script which extracts config values --- scripts/getConfigVal.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 scripts/getConfigVal.py diff --git a/scripts/getConfigVal.py b/scripts/getConfigVal.py new file mode 100644 index 000000000..5e27c8e24 --- /dev/null +++ b/scripts/getConfigVal.py @@ -0,0 +1,22 @@ +""" +Script used to extract values from section-less configs. + +Used in linux image build process. +""" + +import argparse +import configparser +import os + + +parser = argparse.ArgumentParser(description='Extract values from section-less configs') +parser.add_argument('path', help='path to config file') +parser.add_argument('variable', help='variable name') +args = parser.parse_args() + +with open(os.path.expanduser(args.path), 'r') as file: + text = file.read() + +config = configparser.ConfigParser() +config.read_string(f'[root]\n{text}') +print(config.get('root', args.variable))