From 20082b1a11cb30c1ab5c80f1976b5277ffd2e8f7 Mon Sep 17 00:00:00 2001 From: cuican Date: Mon, 11 Dec 2023 14:53:46 +0800 Subject: [PATCH] =?UTF-8?q?=E8=84=9A=E6=9C=AC=E8=A7=84=E8=8C=83=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cuican --- tools/syscap_collector.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/tools/syscap_collector.py b/tools/syscap_collector.py index 35c958e..c60c140 100644 --- a/tools/syscap_collector.py +++ b/tools/syscap_collector.py @@ -82,13 +82,12 @@ def read_json_file(bundle_json_path: str) -> tuple: bundle_syscap_list = list() error_list = dict() try: - f = open(bundle_json_path, 'r', encoding='utf-8') - bundle_data = json.load(f) - component_data = bundle_data.get("component") - component_syscaps_list = component_data.get("syscap") - if component_syscaps_list: - bundle_syscap_list = bundle_syscap_list_handler(bundle_syscap_list, component_syscaps_list) - f.close() + with open(bundle_json_path, 'r', encoding='utf-8') as f: + bundle_data = json.load(f) + component_data = bundle_data.get("component") + component_syscaps_list = component_data.get("syscap") + if component_syscaps_list: + bundle_syscap_list = bundle_syscap_list_handler(bundle_syscap_list, component_syscaps_list) except FileNotFoundError as e: error_list[bundle_json_path] = str(e) except Exception as e: @@ -98,9 +97,8 @@ def read_json_file(bundle_json_path: str) -> tuple: def get_all_components_path(components_file_path: str): try: - f = open(components_file_path, 'r', encoding='utf-8') - path_dict = json.load(f) - f.close() + with open(components_file_path, 'r', encoding='utf-8') as f: + path_dict = json.load(f) return path_dict except FileNotFoundError: logging.error(r"PATH ERROR") -- Gitee