From 579b4218b2f909062622df1136dfd275974735f1 Mon Sep 17 00:00:00 2001 From: aodongbiao Date: Fri, 23 Sep 2022 11:38:29 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: aodongbiao Change-Id: I70656958f0189843e04bc20465c07b4025003259 --- tools/syscap_check.py | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/tools/syscap_check.py b/tools/syscap_check.py index 99c550d..a4932aa 100644 --- a/tools/syscap_check.py +++ b/tools/syscap_check.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # Copyright (c) 2022 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,9 +18,6 @@ import json import re import argparse from prettytable import PrettyTable, ALL -import sys - -debug = True if sys.gettrace() else False def get_args(): @@ -83,14 +80,10 @@ def read_value_from_json(filepath: str, return f = open(filepath, 'r') data = json.load(f) - if debug: - print(filepath) for key in key_hierarchy: try: data = data[key] except KeyError: - if debug: - print('warning: can\'t find the key:"{}" in file "{}"'.format(key, filepath)) return finally: f.close() @@ -114,7 +107,7 @@ def collect_syscap_from_codec(filepath: str, pattern: str = r'{"(.*)"') -> tuple array_syscap_set.update(re.findall(ptrn, content)) array_syscap_dict[filepath] = list() for v in array_syscap_set: - array_syscap_dict[filepath].append(v) + array_syscap_dict.get(filepath).append(v) return array_syscap_set, array_syscap_dict @@ -311,16 +304,6 @@ def main(): bundle_key_heirarchy=bundle_syscap_heirarchy, bundles=bundles) -def test(): - h_path = "./bundle.json" - key_heirarchy = ("component", "syscap") - result_dict = dict() - read_value_from_json(h_path, key_heirarchy, result_dict, bundle_syscap_post_handler) - print(result_dict) - print(len(result_dict)) - - if __name__ == "__main__": main() - # test() -- Gitee From ffde94fbfe65932efa784e2a5954b1f3b79b23e3 Mon Sep 17 00:00:00 2001 From: aodongbiao Date: Mon, 26 Sep 2022 14:40:58 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: aodongbiao Change-Id: I8e10789dca94bef1390f13a4f6f53ba63e9b29cf --- tools/syscap_check.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tools/syscap_check.py b/tools/syscap_check.py index a4932aa..e2b97fa 100644 --- a/tools/syscap_check.py +++ b/tools/syscap_check.py @@ -78,15 +78,15 @@ def read_value_from_json(filepath: str, if not os.path.isfile(filepath): print('error: "{}" is not a file.') return - f = open(filepath, 'r') - data = json.load(f) - for key in key_hierarchy: - try: - data = data[key] - except KeyError: - return - finally: - f.close() + with open(filepath, 'r', encoding='utf-8') as f: + data = json.load(f) + for key in key_hierarchy: + try: + data = data[key] + except KeyError: + return + finally: + pass data = [post_handler(x) for x in data if len(x) != 0 and not x.isspace()] if len(data) != 0: result_dict[filepath] = data -- Gitee