1 |
4 |
danv |
#!/usr/bin/env python3
|
2 |
|
|
###############################################################################
|
3 |
|
|
#
|
4 |
|
|
# Copyright (C) 2018
|
5 |
|
|
# ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
|
6 |
|
|
# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
|
7 |
|
|
#
|
8 |
|
|
# This program is free software: you can redistribute it and/or modify
|
9 |
|
|
# it under the terms of the GNU General Public License as published by
|
10 |
|
|
# the Free Software Foundation, either version 3 of the License, or
|
11 |
|
|
# (at your option) any later version.
|
12 |
|
|
#
|
13 |
|
|
# This program is distributed in the hope that it will be useful,
|
14 |
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
|
|
# GNU General Public License for more details.
|
17 |
|
|
#
|
18 |
|
|
# You should have received a copy of the GNU General Public License
|
19 |
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
20 |
|
|
#
|
21 |
|
|
# $Id$
|
22 |
|
|
#
|
23 |
|
|
###############################################################################
|
24 |
|
|
import sys
|
25 |
|
|
import os
|
26 |
|
|
from os.path import expandvars, dirname, basename
|
27 |
|
|
from argparse import ArgumentParser
|
28 |
|
|
from configfile import ConfigFile
|
29 |
|
|
|
30 |
|
|
if __name__ == '__main__':
|
31 |
|
|
# setup parser and parse the arguments.
|
32 |
|
|
argparser = ArgumentParser(description='Options and arguments for showing hdl_config keys values')
|
33 |
|
|
argparser.add_argument('configfile', help="Filename like 'hdl_buildset_<boardtype>.cfg'")
|
34 |
|
|
argparser.add_argument('keyname', help="Name of the key to show the value of.")
|
35 |
|
|
args = argparser.parse_args()
|
36 |
|
|
|
37 |
|
|
# resolve full name of configfile and force it to be explicit absolute or relative.
|
38 |
|
|
full_configfile_name = expandvars(args.configfile)
|
39 |
|
|
if full_configfile_name[0] != '/':
|
40 |
|
|
full_configfile_name = "./" + full_configfile_name
|
41 |
|
|
# read the file
|
42 |
|
|
cfg_info = ConfigFile(full_configfile_name)
|
43 |
|
|
cfg_info.resolve_key_references()
|
44 |
|
|
|
45 |
|
|
print("{}\n".format(os.path.expandvars(cfg_info.get_value(args.keyname, must_exist=True))))
|
46 |
|
|
|