sb/rtems-kernel-config-check: Reformat using yapf

This commit is contained in:
Chris Johns 2022-09-08 07:34:12 +10:00
parent bf079c1f24
commit be25beed29

View File

@ -1,5 +1,4 @@
#! /usr/bin/env python #! /usr/bin/env python
""" """
SPDX-License-Identifier: BSD-2-Clause SPDX-License-Identifier: BSD-2-Clause
@ -36,14 +35,15 @@ from os.path import exists
try: try:
import ConfigParser import ConfigParser
configparser = ConfigParser # used for python2 configparser = ConfigParser # used for python2
except ImportError: except ImportError:
try: try:
import configparser # used for python3 import configparser # used for python3
except ImportError: except ImportError:
print("Could not import configparser. Exiting...", file = sys.stderr) print("Could not import configparser. Exiting...", file=sys.stderr)
sys.exit(1) sys.exit(1)
def run(): def run():
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("config", help="path to config file") parser.add_argument("config", help="path to config file")
@ -51,79 +51,56 @@ def run():
"-a", "-a",
"--arch", "--arch",
help="return target architecture specified in the config", help="return target architecture specified in the config",
action="store_true" action="store_true")
) parser.add_argument("-b",
parser.add_argument( "--bsp",
"-b", help="return BSP specified in the config",
"--bsp", action="store_true")
help="return BSP specified in the config",
action="store_true"
)
parser.add_argument( parser.add_argument(
"-c", "-c",
"--arch-bsp", "--arch-bsp",
help="return target architecture and BSP specified in the config", help="return target architecture and BSP specified in the config",
action="store_true" action="store_true")
) parser.add_argument("-v",
parser.add_argument( "--rtems-version",
"-v", help="version of RTEMS",
"--rtems-version", type=int,
help="version of RTEMS", default=6)
type=int, parser.add_argument("-t",
default=6 "--target",
) help="return target (<arch-rtems<rtems-version>)",
parser.add_argument( action="store_true")
"-t",
"--target",
help="return target (<arch-rtems<rtems-version>)",
action="store_true"
)
args = parser.parse_args() args = parser.parse_args()
config = configparser.ConfigParser() config = configparser.ConfigParser()
if args.config[-4:] != ".ini": if args.config[-4:] != ".ini":
print( print("The config file is missing an *.ini extension.",
"The config file is missing an *.ini extension.", file=sys.stderr)
file = sys.stderr
)
sys.exit(1) sys.exit(1)
try: try:
config.read(args.config) config.read(args.config)
except configparser.MissingSectionHeaderError: except configparser.MissingSectionHeaderError:
print( print("There is no section header in the config file", file=sys.stderr)
"There is no section header in the config file",
file = sys.stderr
)
sys.exit(1) sys.exit(1)
except configparser.ParsingError: except configparser.ParsingError:
print( print("An exception occured when parsing the config file",
"An exception occured when parsing the config file", file=sys.stderr)
file = sys.stderr
)
sys.exit(1) sys.exit(1)
except: except:
print( print("An unknown exception occured", file=sys.stderr)
"An unknown exception occured",
file = sys.stderr
)
if len(config.sections()) != 1: if len(config.sections()) != 1:
print( print("You can only have one arch/bsp section in your config.",
"You can only have one arch/bsp section in your config.", file=sys.stderr)
file = sys.stderr
)
sys.exit(1) sys.exit(1)
arch_bsp_str = config.sections()[0] arch_bsp_str = config.sections()[0]
if arch_bsp_str.find("/") == -1: if arch_bsp_str.find("/") == -1:
print( print("arch/bsp section in config is missing '/'", file=sys.stderr)
"arch/bsp section in config is missing '/'",
file = sys.stderr
)
sys.exit(1) sys.exit(1)
if ( args.arch or args.bsp) and args.arch_bsp: if (args.arch or args.bsp) and args.arch_bsp:
args.arch = False args.arch = False
if args.arch: if args.arch:
@ -143,5 +120,6 @@ def run():
print(arch + "-rtems" + str(args.rtems_version)) print(arch + "-rtems" + str(args.rtems_version))
return return
if __name__ == "__main__": if __name__ == "__main__":
run() run()