zephyr/scripts/sanity_chk/ini2yaml.py
Ulf Magnusson 47ef9ba6c2 scripts: sanitycheck: Remove redundant ifs
Fixes these pylint warnings:

    scripts/sanity_chk/ini2yaml.py:25:22: R1719: The if expression can
    be replaced with 'test' (simplifiable-if-expression)

    scripts/sanity_chk/expr_parser.py:208:15: R1719: The if expression
    can be replaced with 'bool(test)' (simplifiable-if-expression)

    scripts/sanity_chk/expr_parser.py:210:15: R1719: The if expression
    can be replaced with 'bool(test)' (simplifiable-if-expression)

Also replace a redundant re.compile().match() with re.match(). compile()
doesn't help when re-compiling the regular expression each time through.

(compile() often doesn't help much in general, because the 're' module
caches compiled regexes.)

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-09-07 07:59:53 -04:00

38 lines
853 B
Python
Executable File

#!/usr/bin/env python
# SPDX-License-Identifier: Apache-2.0
import ConfigParser, os
import yaml
import sys
sample = False
in_file = sys.argv[1]
if sys.argv[2] == 'sample':
sample = True
out_file = os.path.join(os.path.dirname(in_file), sys.argv[2] + ".yaml")
config = ConfigParser.ConfigParser()
config.readfp(open(sys.argv[1]))
y = {'tests': 'tests'}
tests = []
for section in config.sections():
tc = {}
for opt in config.options(section):
value = config.get(section, opt)
if value in ['false', 'true']:
tc[opt] = value == 'true'
else:
tc[opt] = value
test = {section : tc}
tests.append(test)
y['tests'] = tests
if sample:
y['sample'] = {'name': "TBD", 'description': "TBD"}
with open(out_file, "w") as f:
yaml.dump(y, f, width=50, indent=4, default_flow_style=False)