PyLint errors fixed
Signed-off-by: Archana <archana.madhavan@silabs.com> Signed-off-by: Asfandyar Orakzai <asfandyar.orakzai@silabs.com>
This commit is contained in:
parent
04cfe34639
commit
314380564c
1 changed files with 23 additions and 17 deletions
|
@ -23,9 +23,10 @@
|
|||
import sys
|
||||
import os
|
||||
import json
|
||||
from jsonschema import validate
|
||||
from typing import Tuple
|
||||
import argparse
|
||||
import jsonschema
|
||||
from jsonschema import validate
|
||||
import jinja2
|
||||
from mbedtls_dev import build_tree
|
||||
|
||||
|
@ -38,10 +39,11 @@ def render(template_path: str, driver_jsoncontext: list) -> str:
|
|||
keep_trailing_newline=True)
|
||||
template = environment.get_template(os.path.basename(template_path))
|
||||
|
||||
return template.render(drivers = driver_jsoncontext)
|
||||
return template.render(drivers=driver_jsoncontext)
|
||||
|
||||
|
||||
def generate_driver_wrapper_file(template_dir: str, output_dir: str, driver_jsoncontext: list ) -> None:
|
||||
def generate_driver_wrapper_file(template_dir: str, \
|
||||
output_dir: str, driver_jsoncontext: list) -> None:
|
||||
"""
|
||||
Generate the file psa_crypto_driver_wrapper.c.
|
||||
"""
|
||||
|
@ -59,27 +61,29 @@ def validate_json(driverjson_data: list, driverschema: list) -> bool:
|
|||
Validate the Driver JSON against schema
|
||||
"""
|
||||
try:
|
||||
validate(instance = driverjson_data, schema = driverschema)
|
||||
validate(instance=driverjson_data, schema=driverschema)
|
||||
except jsonschema.exceptions.ValidationError as err:
|
||||
print(err)
|
||||
err = "The driver JSON data is InValid"
|
||||
print("The driver JSON data is InValid")
|
||||
return False
|
||||
|
||||
message = "The driver JSON data is Valid"
|
||||
return True
|
||||
|
||||
def merge_driverjsonfiles(mbedtls_root: str, json_directory: str, jsondriverlistName: str) -> Tuple[bool,list]:
|
||||
def merge_driverjsonfiles(mbedtls_root: str, json_directory: str, \
|
||||
jsondriver_list: str) -> Tuple[bool, list]:
|
||||
"""
|
||||
Merge driver JSON files into a single ordered JSON after validation.
|
||||
"""
|
||||
result = list()
|
||||
driverlist = list()
|
||||
with open(os.path.join(mbedtls_root, 'scripts/data_files/driver_jsons/driver_transparent_schema.json'), 'r') as file:
|
||||
with open(os.path.join(mbedtls_root, \
|
||||
'scripts/data_files/driver_jsons/driver_transparent_schema.json'), 'r') as file:
|
||||
transparent_driver_schema = json.load(file)
|
||||
with open(os.path.join(mbedtls_root, 'scripts/data_files/driver_jsons/driver_opaque_schema.json'), 'r') as file:
|
||||
with open(os.path.join(mbedtls_root, \
|
||||
'scripts/data_files/driver_jsons/driver_opaque_schema.json'), 'r') as file:
|
||||
opaque_driver_schema = json.load(file)
|
||||
|
||||
with open(os.path.join(json_directory, jsondriverlistName), 'r') as driverlistfile:
|
||||
with open(os.path.join(json_directory, jsondriver_list), 'r') as driverlistfile:
|
||||
driverlist = json.load(driverlistfile)
|
||||
for file_name in driverlist:
|
||||
with open(os.path.join(json_directory, file_name), 'r') as infile:
|
||||
|
@ -91,7 +95,7 @@ def merge_driverjsonfiles(mbedtls_root: str, json_directory: str, jsondriverlist
|
|||
else:
|
||||
ret = False
|
||||
print("Unknown Driver type")
|
||||
if ret == False:
|
||||
if ret is False:
|
||||
return ret, []
|
||||
result.append(json_data)
|
||||
return True, result
|
||||
|
@ -103,8 +107,10 @@ def main() -> int:
|
|||
"""
|
||||
def_arg_mbedtls_root = build_tree.guess_mbedtls_root()
|
||||
def_arg_output_dir = os.path.join(def_arg_mbedtls_root, 'library')
|
||||
def_arg_template_dir = os.path.join(def_arg_mbedtls_root, 'scripts/data_files/driver_templates/')
|
||||
def_arg_json_dir = os.path.join(def_arg_mbedtls_root, 'scripts/data_files/driver_jsons/')
|
||||
def_arg_template_dir = os.path.join(def_arg_mbedtls_root, \
|
||||
'scripts/data_files/driver_templates/')
|
||||
def_arg_json_dir = os.path.join(def_arg_mbedtls_root, \
|
||||
'scripts/data_files/driver_jsons/')
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--mbedtls-root', nargs='?', default=def_arg_mbedtls_root,
|
||||
|
@ -117,14 +123,14 @@ def main() -> int:
|
|||
default=def_arg_output_dir, help='output file\'s location')
|
||||
args = parser.parse_args()
|
||||
|
||||
mbedtls_root = os.path.abspath(args.mbedtls_root)
|
||||
output_directory = args.output_directory
|
||||
mbedtls_root = os.path.abspath(args.mbedtls_root)
|
||||
output_directory = args.output_directory
|
||||
template_directory = args.template_dir
|
||||
json_directory = args.json_dir
|
||||
json_directory = args.json_dir
|
||||
|
||||
# load list of driver jsons from driverlist.json
|
||||
ret, merged_driverjson = merge_driverjsonfiles(mbedtls_root, json_directory, 'driverlist.json')
|
||||
if ret == False:
|
||||
if ret is False:
|
||||
return 1
|
||||
generate_driver_wrapper_file(template_directory, output_directory, merged_driverjson)
|
||||
|
||||
|
|
Loading…
Reference in a new issue