
Using config/sysinv/sysinv/sysinv as example of setup for pep8/flake8. Fix reported errors for config.py. Story: 2010816 Task: 48450 Change-Id: Ia0e511fd827b5d697a6b41b7064d13ab64efb779 Signed-off-by: Michel Thebeau <Michel.Thebeau@windriver.com>
50 lines
1020 B
Python
Executable File
50 lines
1020 B
Python
Executable File
#!/usr/bin/python3
|
|
|
|
import sys
|
|
import yaml
|
|
|
|
|
|
def print_help():
|
|
print("./config.py <config_file> <key>",
|
|
file=sys.stderr)
|
|
|
|
|
|
def readvalue(config_file, key):
|
|
|
|
try:
|
|
with open(config_file, 'r', encoding="utf-8") as f:
|
|
data = yaml.load(f, Loader=yaml.Loader)
|
|
|
|
value = data[key]
|
|
print(value)
|
|
|
|
except yaml.YAMLError as e:
|
|
print('YAMLError: %s' % e, file=sys.stderr)
|
|
except KeyError as e:
|
|
print('KeyError: %s' % e, file=sys.stderr)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
args = sys.argv[1:]
|
|
|
|
if '--help' in args:
|
|
print_help()
|
|
sys.exit(1)
|
|
|
|
if len(args) == 2:
|
|
input_file = args[0]
|
|
input_key = args[1]
|
|
readvalue(input_file, input_key)
|
|
|
|
elif len(args) < 2:
|
|
print("Error: missing required arguments.",
|
|
file=sys.stderr)
|
|
print_help()
|
|
sys.exit(1)
|
|
|
|
else:
|
|
print("Error: too many arguments.",
|
|
file=sys.stderr)
|
|
print_help()
|
|
sys.exit(1)
|