Skip to content

Commit 3afbfd6

Browse files
author
Cruz Monrreal
authored
Merge pull request #6580 from theotherjimmy/cleanup-get-config
Cleanup get_config (mbed compile --config)
2 parents 259f9fd + e80d994 commit 3afbfd6

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

tools/get_config.py

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
"""
1919
from __future__ import print_function
2020
import sys
21-
from os.path import isdir, abspath, dirname, join
22-
from os import _exit
21+
from os.path import abspath, dirname, join
2322

2423
# Be sure that the tools directory is in the search path
2524
ROOT = abspath(join(dirname(__file__), ".."))
@@ -31,20 +30,20 @@
3130
from tools.build_api import get_config
3231
from tools.config import Config
3332
from tools.utils import argparse_filestring_type
34-
try:
35-
import tools.private_settings as ps
36-
except:
37-
ps = object()
3833

3934
if __name__ == '__main__':
4035
# Parse Options
4136
parser = get_default_options_parser(add_clean=False, add_options=False)
42-
parser.add_argument("--source", dest="source_dir", type=argparse_filestring_type, required=True,
43-
default=[], help="The source (input) directory", action="append")
44-
parser.add_argument("--prefix", dest="prefix", action="append",
45-
default=[], help="Restrict listing to parameters that have this prefix")
46-
parser.add_argument("-v", "--verbose", action="store_true", dest="verbose",
47-
default=False, help="Verbose diagnostic output")
37+
parser.add_argument(
38+
"--source", dest="source_dir", type=argparse_filestring_type,
39+
required=True, default=[], help="The source (input) directory",
40+
action="append")
41+
parser.add_argument(
42+
"--prefix", dest="prefix", action="append", default=[],
43+
help="Restrict listing to parameters that have this prefix")
44+
parser.add_argument(
45+
"-v", "--verbose", action="store_true", dest="verbose", default=False,
46+
help="Verbose diagnostic output")
4847

4948
options = parser.parse_args()
5049

@@ -61,25 +60,27 @@
6160
options.prefix = options.prefix or [""]
6261

6362
try:
64-
params, macros, features = get_config(options.source_dir, target, toolchain)
63+
params, macros, features = get_config(
64+
options.source_dir, target, toolchain)
6565
if not params and not macros:
6666
print("No configuration data available.")
67-
_exit(0)
67+
sys.exit(0)
6868
if params:
6969
print("Configuration parameters")
7070
print("------------------------")
71-
for p in sorted(params):
72-
for s in options.prefix:
73-
if p.startswith(s):
74-
print(str(params[p]) if not options.verbose else params[p].get_verbose_description())
75-
break
71+
for p in sorted(list(params.keys())):
72+
if any(p.startswith(s) for s in options.prefix):
73+
if options.verbose:
74+
print(params[p].get_verbose_description())
75+
else:
76+
print(str(params[p]))
7677
print("")
7778

7879
print("Macros")
7980
print("------")
80-
if macros:
81-
print('Defined with "macros":', Config.config_macros_to_macros(macros))
82-
print("Generated from configuration parameters:", Config.parameters_to_macros(params))
81+
for m in Config.config_macros_to_macros(macros):
82+
if any(m.startswith(s) for s in options.prefix):
83+
print(m)
8384

8485
except KeyboardInterrupt as e:
8586
print("\n[CTRL+c] exit")

0 commit comments

Comments
 (0)