From a606b3b887c176c073a8c1e34efc68abe5354da8 Mon Sep 17 00:00:00 2001 From: cuican Date: Wed, 29 Nov 2023 11:10:56 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E6=96=B0=E5=A2=9Esyscap=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E8=83=BD=E5=8A=9B=E9=9B=86=E6=94=B6=E9=9B=86=E7=94=9F=E6=88=90?= =?UTF-8?q?=E5=B7=A5=E5=85=B7syscap=5Fcollector?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cuican --- tools/syscap_collector.py | 176 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 tools/syscap_collector.py diff --git a/tools/syscap_collector.py b/tools/syscap_collector.py new file mode 100644 index 0000000..7a8c0ad --- /dev/null +++ b/tools/syscap_collector.py @@ -0,0 +1,176 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import logging +import os +import json +import argparse + +logging.basicConfig(level=logging.INFO) + + +def get_args(): + parser = argparse.ArgumentParser(add_help=True) + parser.add_argument( + "-p", + "--project_path", + default=r"./", + type=str, + help="root path of project. default: ./", + ) + parser.add_argument( + "-o", + "--output_path", + default=r"./", + type=str, + help="path of output file. default: ./", + ) + parser.add_argument( + "-e", + "--error_output", + action='store_true', + help="output error_list or not. default not", + ) + args = parser.parse_args() + return args + + +def dict_to_json(output_path: str, syscaps_dict: dict, error_output: bool, error_dict: dict): + logging.info("start generate syscap json...") + filename = os.path.join(output_path, 'component_list_syscap.json') + f = open(filename, 'w', encoding='utf-8') + json.dump(syscaps_dict, f) + logging.info("end...") + f.close() + if error_output: + logging.info("start generate error json......") + filename = os.path.join(output_path, 'error_dict.json') + error_f = open(filename, 'w', encoding='utf-8') + json.dump(error_dict, error_f) + logging.info("end...") + error_f.close() + + +def check_syscap(syscap_str: str): + syscap = syscap_str.split(' = ') + if syscap[-1].lower() == 'false': + return False + else: + return syscap[0] + + +def read_json_file(bundle_json_path: str) -> tuple: + bundle_data = dict() + bundle_syscap_list = list() + error_list = dict() + try: + f = open(bundle_json_path, 'r', encoding='utf-8') + bundle_data = json.load(f) + f.close() + except FileNotFoundError as e: + error_list[bundle_json_path] = str(e) + except Exception as e: + error_list[bundle_json_path] = str(e) + if bundle_data: + component_data = bundle_data.get("component") + component_syscaps_list = component_data.get("syscap") + if component_syscaps_list: + for i in component_syscaps_list: + i = check_syscap(i) + if i: + bundle_syscap_list.append(i) + return bundle_syscap_list, error_list + + +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() + return path_dict + except FileNotFoundError: + logging.error(r"ERROR:PATH ERROR") + return {} + + +def path_component_to_bundle(path: str) -> str: + bundle_json_path = os.path.join(path, 'bundle.json') + return bundle_json_path + + +def handle_bundle_json_file(component_path_list: list) -> tuple: + logging.info("start collect syscap path...") + syscap_list = list() + error_dict = dict() + for path in component_path_list: + bundle_json_path = path_component_to_bundle(path) + bundle_syscap_list, error_list = read_json_file(bundle_json_path) + syscap_list.extend(bundle_syscap_list) + error_dict.update(error_list) + + return {"SysCaps": syscap_list}, error_dict + + +def format_component_path(component_path: str): + sep_list = ['\\', '/'] + sep_list.remove(os.sep) + component_path = component_path.replace(sep_list[0], os.sep) + return component_path + + +def traversal_path(path_dict: dict, project_path: str) -> list: + component_path_list = list() + for _, v in path_dict.items(): + component_path = os.path.join(project_path, v) + component_path = format_component_path(component_path) + component_path_list.append(component_path) + return component_path_list + + +def collect_all_syscap(components_path: str, project_path: str) -> tuple: + """ + 从各部件收集syscap并返回字典 + :param components_path: 必选部件json文件的路径 + :param project_path: 项目根路径 + :return: 所有典型品类syscap字典 + """ + components_path_dict = get_all_components_path(components_path) + if components_path_dict: + logging.info("start collect component path...") + component_path_list = traversal_path(components_path_dict, project_path) + syscap_dict, error_dict = handle_bundle_json_file(component_path_list) + return syscap_dict, error_dict + else: + return 0, 0 + + +def components_path_handler(project_path): + components_path = os.path.join(project_path, "out", "rk3568", "build_configs", "parts_info", + "parts_path_info.json") + return components_path + + +def main(): + args = get_args() + project_path = args.project_path + output_path = args.output_path + error_output = args.error_output + components_path = components_path_handler(project_path) + syscap_dict, error_dict = collect_all_syscap(components_path, project_path) + if syscap_dict: + dict_to_json(output_path, syscap_dict, error_output, error_dict) + + +if __name__ == "__main__": + main() From 8d4dd274ed0e9d3a126bf56d6795026ed942c308 Mon Sep 17 00:00:00 2001 From: cuican Date: Wed, 29 Nov 2023 11:10:56 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E6=96=B0=E5=A2=9Esyscap=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E8=83=BD=E5=8A=9B=E9=9B=86=E6=94=B6=E9=9B=86=E7=94=9F=E6=88=90?= =?UTF-8?q?=E5=B7=A5=E5=85=B7syscap=5Fcollector?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cuican --- tools/syscap_collector.py | 181 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 tools/syscap_collector.py diff --git a/tools/syscap_collector.py b/tools/syscap_collector.py new file mode 100644 index 0000000..3e792ff --- /dev/null +++ b/tools/syscap_collector.py @@ -0,0 +1,181 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import logging +import os +import json +import argparse +import stat + + +def get_args(): + parser = argparse.ArgumentParser(add_help=True) + parser.add_argument( + "-p", + "--project_path", + default=r"./", + type=str, + help="root path of project. default: ./", + ) + parser.add_argument( + "-o", + "--output_path", + default=r"./", + type=str, + help="path of output file. default: ./", + ) + parser.add_argument( + "-e", + "--error_output", + action='store_true', + help="output error_list or not. default not", + ) + args = parser.parse_args() + return args + + +def dict_to_json(output_path: str, syscaps_dict: dict, error_output: bool, error_dict: dict): + flags = os.O_WRONLY | os.O_CREAT | os.O_EXCL + modes = stat.S_IWUSR | stat.S_IRUSR + logging.info("start generate syscap json...") + filename = os.path.join(output_path, 'component_list_syscap.json') + with os.fdopen(os.open(filename, flags, modes), 'w') as f: + json.dump(syscaps_dict, f) + logging.info("end...") + + if error_output: + logging.info("start generate error json......") + filename = os.path.join(output_path, 'error_dict.json') + with os.fdopen(os.open(filename, flags, modes), 'w') as error_f: + json.dump(error_dict, error_f) + logging.info("end...") + + +def check_syscap(syscap_str: str): + syscap = syscap_str.split(' = ') + if syscap[-1].lower() == 'false': + return False + else: + return syscap[0] + + +def bundle_syscap_list_handler(bundle_syscap_list: list, component_syscaps_list: list) -> list: + for i in component_syscaps_list: + i = check_syscap(i) + if i: + bundle_syscap_list.append(i) + return bundle_syscap_list + + +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() + except FileNotFoundError as e: + error_list[bundle_json_path] = str(e) + except Exception as e: + error_list[bundle_json_path] = str(e) + return bundle_syscap_list, error_list + + +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() + return path_dict + except FileNotFoundError: + logging.error(r"PATH ERROR") + return {} + + +def path_component_to_bundle(path: str) -> str: + bundle_json_path = os.path.join(path, 'bundle.json') + return bundle_json_path + + +def handle_bundle_json_file(component_path_list: list) -> tuple: + logging.info("start collect syscap path...") + syscap_list = list() + error_dict = dict() + for path in component_path_list: + bundle_json_path = path_component_to_bundle(path) + bundle_syscap_list, error_list = read_json_file(bundle_json_path) + syscap_list.extend(bundle_syscap_list) + error_dict.update(error_list) + + return {"SysCaps": syscap_list}, error_dict + + +def format_component_path(component_path: str): + sep_list = ['\\', '/'] + sep_list.remove(os.sep) + component_path = component_path.replace(sep_list[0], os.sep) + return component_path + + +def traversal_path(path_dict: dict, project_path: str) -> list: + component_path_list = list() + for _, v in path_dict.items(): + component_path = os.path.join(project_path, v) + component_path = format_component_path(component_path) + component_path_list.append(component_path) + return component_path_list + + +def collect_all_syscap(components_path: str, project_path: str) -> tuple: + """ + 从各部件收集syscap并返回字典 + :param components_path: 必选部件json文件的路径 + :param project_path: 项目根路径 + :return: 所有典型品类syscap字典 + """ + components_path_dict = get_all_components_path(components_path) + if components_path_dict: + logging.info("start collect component path...") + component_path_list = traversal_path(components_path_dict, project_path) + syscap_dict, error_dict = handle_bundle_json_file(component_path_list) + return syscap_dict, error_dict + else: + return 0, 0 + + +def components_path_handler(project_path): + components_path = os.path.join(project_path, "out", "rk3568", "build_configs", "parts_info", + "parts_path_info.json") + return components_path + + +def main(): + logging.basicConfig(level=logging.INFO) + + args = get_args() + project_path = args.project_path + output_path = args.output_path + error_output = args.error_output + components_path = components_path_handler(project_path) + syscap_dict, error_dict = collect_all_syscap(components_path, project_path) + if syscap_dict: + dict_to_json(output_path, syscap_dict, error_output, error_dict) + + +if __name__ == "__main__": + main() From 4a0fdf96b67b7892c5b66fc5cb760023ca46e2d4 Mon Sep 17 00:00:00 2001 From: cuican Date: Wed, 29 Nov 2023 16:41:44 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E6=96=B0=E5=A2=9Esyscap=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E8=83=BD=E5=8A=9B=E9=9B=86=E6=94=B6=E9=9B=86=E7=94=9F=E6=88=90?= =?UTF-8?q?=E5=B7=A5=E5=85=B7syscap=5Fcollector?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cuican --- tools/syscap_collector.py | 181 -------------------------------------- 1 file changed, 181 deletions(-) delete mode 100644 tools/syscap_collector.py diff --git a/tools/syscap_collector.py b/tools/syscap_collector.py deleted file mode 100644 index 3e792ff..0000000 --- a/tools/syscap_collector.py +++ /dev/null @@ -1,181 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -# Copyright (c) 2022 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import logging -import os -import json -import argparse -import stat - - -def get_args(): - parser = argparse.ArgumentParser(add_help=True) - parser.add_argument( - "-p", - "--project_path", - default=r"./", - type=str, - help="root path of project. default: ./", - ) - parser.add_argument( - "-o", - "--output_path", - default=r"./", - type=str, - help="path of output file. default: ./", - ) - parser.add_argument( - "-e", - "--error_output", - action='store_true', - help="output error_list or not. default not", - ) - args = parser.parse_args() - return args - - -def dict_to_json(output_path: str, syscaps_dict: dict, error_output: bool, error_dict: dict): - flags = os.O_WRONLY | os.O_CREAT | os.O_EXCL - modes = stat.S_IWUSR | stat.S_IRUSR - logging.info("start generate syscap json...") - filename = os.path.join(output_path, 'component_list_syscap.json') - with os.fdopen(os.open(filename, flags, modes), 'w') as f: - json.dump(syscaps_dict, f) - logging.info("end...") - - if error_output: - logging.info("start generate error json......") - filename = os.path.join(output_path, 'error_dict.json') - with os.fdopen(os.open(filename, flags, modes), 'w') as error_f: - json.dump(error_dict, error_f) - logging.info("end...") - - -def check_syscap(syscap_str: str): - syscap = syscap_str.split(' = ') - if syscap[-1].lower() == 'false': - return False - else: - return syscap[0] - - -def bundle_syscap_list_handler(bundle_syscap_list: list, component_syscaps_list: list) -> list: - for i in component_syscaps_list: - i = check_syscap(i) - if i: - bundle_syscap_list.append(i) - return bundle_syscap_list - - -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() - except FileNotFoundError as e: - error_list[bundle_json_path] = str(e) - except Exception as e: - error_list[bundle_json_path] = str(e) - return bundle_syscap_list, error_list - - -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() - return path_dict - except FileNotFoundError: - logging.error(r"PATH ERROR") - return {} - - -def path_component_to_bundle(path: str) -> str: - bundle_json_path = os.path.join(path, 'bundle.json') - return bundle_json_path - - -def handle_bundle_json_file(component_path_list: list) -> tuple: - logging.info("start collect syscap path...") - syscap_list = list() - error_dict = dict() - for path in component_path_list: - bundle_json_path = path_component_to_bundle(path) - bundle_syscap_list, error_list = read_json_file(bundle_json_path) - syscap_list.extend(bundle_syscap_list) - error_dict.update(error_list) - - return {"SysCaps": syscap_list}, error_dict - - -def format_component_path(component_path: str): - sep_list = ['\\', '/'] - sep_list.remove(os.sep) - component_path = component_path.replace(sep_list[0], os.sep) - return component_path - - -def traversal_path(path_dict: dict, project_path: str) -> list: - component_path_list = list() - for _, v in path_dict.items(): - component_path = os.path.join(project_path, v) - component_path = format_component_path(component_path) - component_path_list.append(component_path) - return component_path_list - - -def collect_all_syscap(components_path: str, project_path: str) -> tuple: - """ - 从各部件收集syscap并返回字典 - :param components_path: 必选部件json文件的路径 - :param project_path: 项目根路径 - :return: 所有典型品类syscap字典 - """ - components_path_dict = get_all_components_path(components_path) - if components_path_dict: - logging.info("start collect component path...") - component_path_list = traversal_path(components_path_dict, project_path) - syscap_dict, error_dict = handle_bundle_json_file(component_path_list) - return syscap_dict, error_dict - else: - return 0, 0 - - -def components_path_handler(project_path): - components_path = os.path.join(project_path, "out", "rk3568", "build_configs", "parts_info", - "parts_path_info.json") - return components_path - - -def main(): - logging.basicConfig(level=logging.INFO) - - args = get_args() - project_path = args.project_path - output_path = args.output_path - error_output = args.error_output - components_path = components_path_handler(project_path) - syscap_dict, error_dict = collect_all_syscap(components_path, project_path) - if syscap_dict: - dict_to_json(output_path, syscap_dict, error_output, error_dict) - - -if __name__ == "__main__": - main() From cb41b7cd8de98c53e0ce3f2d808b5e88fd83b899 Mon Sep 17 00:00:00 2001 From: cuican Date: Wed, 29 Nov 2023 16:41:44 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E6=96=B0=E5=A2=9Esyscap=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E8=83=BD=E5=8A=9B=E9=9B=86=E6=94=B6=E9=9B=86=E7=94=9F=E6=88=90?= =?UTF-8?q?=E5=B7=A5=E5=85=B7syscap=5Fcollector?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cuican --- tools/syscap_collector.py | 181 -------------------------------------- 1 file changed, 181 deletions(-) delete mode 100644 tools/syscap_collector.py diff --git a/tools/syscap_collector.py b/tools/syscap_collector.py deleted file mode 100644 index 3e792ff..0000000 --- a/tools/syscap_collector.py +++ /dev/null @@ -1,181 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -# Copyright (c) 2022 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import logging -import os -import json -import argparse -import stat - - -def get_args(): - parser = argparse.ArgumentParser(add_help=True) - parser.add_argument( - "-p", - "--project_path", - default=r"./", - type=str, - help="root path of project. default: ./", - ) - parser.add_argument( - "-o", - "--output_path", - default=r"./", - type=str, - help="path of output file. default: ./", - ) - parser.add_argument( - "-e", - "--error_output", - action='store_true', - help="output error_list or not. default not", - ) - args = parser.parse_args() - return args - - -def dict_to_json(output_path: str, syscaps_dict: dict, error_output: bool, error_dict: dict): - flags = os.O_WRONLY | os.O_CREAT | os.O_EXCL - modes = stat.S_IWUSR | stat.S_IRUSR - logging.info("start generate syscap json...") - filename = os.path.join(output_path, 'component_list_syscap.json') - with os.fdopen(os.open(filename, flags, modes), 'w') as f: - json.dump(syscaps_dict, f) - logging.info("end...") - - if error_output: - logging.info("start generate error json......") - filename = os.path.join(output_path, 'error_dict.json') - with os.fdopen(os.open(filename, flags, modes), 'w') as error_f: - json.dump(error_dict, error_f) - logging.info("end...") - - -def check_syscap(syscap_str: str): - syscap = syscap_str.split(' = ') - if syscap[-1].lower() == 'false': - return False - else: - return syscap[0] - - -def bundle_syscap_list_handler(bundle_syscap_list: list, component_syscaps_list: list) -> list: - for i in component_syscaps_list: - i = check_syscap(i) - if i: - bundle_syscap_list.append(i) - return bundle_syscap_list - - -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() - except FileNotFoundError as e: - error_list[bundle_json_path] = str(e) - except Exception as e: - error_list[bundle_json_path] = str(e) - return bundle_syscap_list, error_list - - -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() - return path_dict - except FileNotFoundError: - logging.error(r"PATH ERROR") - return {} - - -def path_component_to_bundle(path: str) -> str: - bundle_json_path = os.path.join(path, 'bundle.json') - return bundle_json_path - - -def handle_bundle_json_file(component_path_list: list) -> tuple: - logging.info("start collect syscap path...") - syscap_list = list() - error_dict = dict() - for path in component_path_list: - bundle_json_path = path_component_to_bundle(path) - bundle_syscap_list, error_list = read_json_file(bundle_json_path) - syscap_list.extend(bundle_syscap_list) - error_dict.update(error_list) - - return {"SysCaps": syscap_list}, error_dict - - -def format_component_path(component_path: str): - sep_list = ['\\', '/'] - sep_list.remove(os.sep) - component_path = component_path.replace(sep_list[0], os.sep) - return component_path - - -def traversal_path(path_dict: dict, project_path: str) -> list: - component_path_list = list() - for _, v in path_dict.items(): - component_path = os.path.join(project_path, v) - component_path = format_component_path(component_path) - component_path_list.append(component_path) - return component_path_list - - -def collect_all_syscap(components_path: str, project_path: str) -> tuple: - """ - 从各部件收集syscap并返回字典 - :param components_path: 必选部件json文件的路径 - :param project_path: 项目根路径 - :return: 所有典型品类syscap字典 - """ - components_path_dict = get_all_components_path(components_path) - if components_path_dict: - logging.info("start collect component path...") - component_path_list = traversal_path(components_path_dict, project_path) - syscap_dict, error_dict = handle_bundle_json_file(component_path_list) - return syscap_dict, error_dict - else: - return 0, 0 - - -def components_path_handler(project_path): - components_path = os.path.join(project_path, "out", "rk3568", "build_configs", "parts_info", - "parts_path_info.json") - return components_path - - -def main(): - logging.basicConfig(level=logging.INFO) - - args = get_args() - project_path = args.project_path - output_path = args.output_path - error_output = args.error_output - components_path = components_path_handler(project_path) - syscap_dict, error_dict = collect_all_syscap(components_path, project_path) - if syscap_dict: - dict_to_json(output_path, syscap_dict, error_output, error_dict) - - -if __name__ == "__main__": - main() From fc990b1973860f15bf8a3a6020de060ae7a18d02 Mon Sep 17 00:00:00 2001 From: cuican Date: Wed, 29 Nov 2023 16:47:23 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E6=96=B0=E5=A2=9Esyscap=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E8=83=BD=E5=8A=9B=E9=9B=86=E6=94=B6=E9=9B=86=E7=94=9F=E6=88=90?= =?UTF-8?q?=E5=B7=A5=E5=85=B7syscap=5Fcollector?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cuican --- tools/syscap_collector.py | 181 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 tools/syscap_collector.py diff --git a/tools/syscap_collector.py b/tools/syscap_collector.py new file mode 100644 index 0000000..3e792ff --- /dev/null +++ b/tools/syscap_collector.py @@ -0,0 +1,181 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import logging +import os +import json +import argparse +import stat + + +def get_args(): + parser = argparse.ArgumentParser(add_help=True) + parser.add_argument( + "-p", + "--project_path", + default=r"./", + type=str, + help="root path of project. default: ./", + ) + parser.add_argument( + "-o", + "--output_path", + default=r"./", + type=str, + help="path of output file. default: ./", + ) + parser.add_argument( + "-e", + "--error_output", + action='store_true', + help="output error_list or not. default not", + ) + args = parser.parse_args() + return args + + +def dict_to_json(output_path: str, syscaps_dict: dict, error_output: bool, error_dict: dict): + flags = os.O_WRONLY | os.O_CREAT | os.O_EXCL + modes = stat.S_IWUSR | stat.S_IRUSR + logging.info("start generate syscap json...") + filename = os.path.join(output_path, 'component_list_syscap.json') + with os.fdopen(os.open(filename, flags, modes), 'w') as f: + json.dump(syscaps_dict, f) + logging.info("end...") + + if error_output: + logging.info("start generate error json......") + filename = os.path.join(output_path, 'error_dict.json') + with os.fdopen(os.open(filename, flags, modes), 'w') as error_f: + json.dump(error_dict, error_f) + logging.info("end...") + + +def check_syscap(syscap_str: str): + syscap = syscap_str.split(' = ') + if syscap[-1].lower() == 'false': + return False + else: + return syscap[0] + + +def bundle_syscap_list_handler(bundle_syscap_list: list, component_syscaps_list: list) -> list: + for i in component_syscaps_list: + i = check_syscap(i) + if i: + bundle_syscap_list.append(i) + return bundle_syscap_list + + +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() + except FileNotFoundError as e: + error_list[bundle_json_path] = str(e) + except Exception as e: + error_list[bundle_json_path] = str(e) + return bundle_syscap_list, error_list + + +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() + return path_dict + except FileNotFoundError: + logging.error(r"PATH ERROR") + return {} + + +def path_component_to_bundle(path: str) -> str: + bundle_json_path = os.path.join(path, 'bundle.json') + return bundle_json_path + + +def handle_bundle_json_file(component_path_list: list) -> tuple: + logging.info("start collect syscap path...") + syscap_list = list() + error_dict = dict() + for path in component_path_list: + bundle_json_path = path_component_to_bundle(path) + bundle_syscap_list, error_list = read_json_file(bundle_json_path) + syscap_list.extend(bundle_syscap_list) + error_dict.update(error_list) + + return {"SysCaps": syscap_list}, error_dict + + +def format_component_path(component_path: str): + sep_list = ['\\', '/'] + sep_list.remove(os.sep) + component_path = component_path.replace(sep_list[0], os.sep) + return component_path + + +def traversal_path(path_dict: dict, project_path: str) -> list: + component_path_list = list() + for _, v in path_dict.items(): + component_path = os.path.join(project_path, v) + component_path = format_component_path(component_path) + component_path_list.append(component_path) + return component_path_list + + +def collect_all_syscap(components_path: str, project_path: str) -> tuple: + """ + 从各部件收集syscap并返回字典 + :param components_path: 必选部件json文件的路径 + :param project_path: 项目根路径 + :return: 所有典型品类syscap字典 + """ + components_path_dict = get_all_components_path(components_path) + if components_path_dict: + logging.info("start collect component path...") + component_path_list = traversal_path(components_path_dict, project_path) + syscap_dict, error_dict = handle_bundle_json_file(component_path_list) + return syscap_dict, error_dict + else: + return 0, 0 + + +def components_path_handler(project_path): + components_path = os.path.join(project_path, "out", "rk3568", "build_configs", "parts_info", + "parts_path_info.json") + return components_path + + +def main(): + logging.basicConfig(level=logging.INFO) + + args = get_args() + project_path = args.project_path + output_path = args.output_path + error_output = args.error_output + components_path = components_path_handler(project_path) + syscap_dict, error_dict = collect_all_syscap(components_path, project_path) + if syscap_dict: + dict_to_json(output_path, syscap_dict, error_output, error_dict) + + +if __name__ == "__main__": + main() From 2eb7cb8ad0e16e326a3f13090fe13e5786ddb4b7 Mon Sep 17 00:00:00 2001 From: cuican Date: Wed, 29 Nov 2023 16:49:03 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E6=96=B0=E5=A2=9Esyscap=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E8=83=BD=E5=8A=9B=E9=9B=86=E6=94=B6=E9=9B=86=E7=94=9F=E6=88=90?= =?UTF-8?q?=E5=B7=A5=E5=85=B7syscap=5Fcollector?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cuican --- tools/syscap_collector.py | 181 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 tools/syscap_collector.py diff --git a/tools/syscap_collector.py b/tools/syscap_collector.py new file mode 100644 index 0000000..3e792ff --- /dev/null +++ b/tools/syscap_collector.py @@ -0,0 +1,181 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import logging +import os +import json +import argparse +import stat + + +def get_args(): + parser = argparse.ArgumentParser(add_help=True) + parser.add_argument( + "-p", + "--project_path", + default=r"./", + type=str, + help="root path of project. default: ./", + ) + parser.add_argument( + "-o", + "--output_path", + default=r"./", + type=str, + help="path of output file. default: ./", + ) + parser.add_argument( + "-e", + "--error_output", + action='store_true', + help="output error_list or not. default not", + ) + args = parser.parse_args() + return args + + +def dict_to_json(output_path: str, syscaps_dict: dict, error_output: bool, error_dict: dict): + flags = os.O_WRONLY | os.O_CREAT | os.O_EXCL + modes = stat.S_IWUSR | stat.S_IRUSR + logging.info("start generate syscap json...") + filename = os.path.join(output_path, 'component_list_syscap.json') + with os.fdopen(os.open(filename, flags, modes), 'w') as f: + json.dump(syscaps_dict, f) + logging.info("end...") + + if error_output: + logging.info("start generate error json......") + filename = os.path.join(output_path, 'error_dict.json') + with os.fdopen(os.open(filename, flags, modes), 'w') as error_f: + json.dump(error_dict, error_f) + logging.info("end...") + + +def check_syscap(syscap_str: str): + syscap = syscap_str.split(' = ') + if syscap[-1].lower() == 'false': + return False + else: + return syscap[0] + + +def bundle_syscap_list_handler(bundle_syscap_list: list, component_syscaps_list: list) -> list: + for i in component_syscaps_list: + i = check_syscap(i) + if i: + bundle_syscap_list.append(i) + return bundle_syscap_list + + +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() + except FileNotFoundError as e: + error_list[bundle_json_path] = str(e) + except Exception as e: + error_list[bundle_json_path] = str(e) + return bundle_syscap_list, error_list + + +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() + return path_dict + except FileNotFoundError: + logging.error(r"PATH ERROR") + return {} + + +def path_component_to_bundle(path: str) -> str: + bundle_json_path = os.path.join(path, 'bundle.json') + return bundle_json_path + + +def handle_bundle_json_file(component_path_list: list) -> tuple: + logging.info("start collect syscap path...") + syscap_list = list() + error_dict = dict() + for path in component_path_list: + bundle_json_path = path_component_to_bundle(path) + bundle_syscap_list, error_list = read_json_file(bundle_json_path) + syscap_list.extend(bundle_syscap_list) + error_dict.update(error_list) + + return {"SysCaps": syscap_list}, error_dict + + +def format_component_path(component_path: str): + sep_list = ['\\', '/'] + sep_list.remove(os.sep) + component_path = component_path.replace(sep_list[0], os.sep) + return component_path + + +def traversal_path(path_dict: dict, project_path: str) -> list: + component_path_list = list() + for _, v in path_dict.items(): + component_path = os.path.join(project_path, v) + component_path = format_component_path(component_path) + component_path_list.append(component_path) + return component_path_list + + +def collect_all_syscap(components_path: str, project_path: str) -> tuple: + """ + 从各部件收集syscap并返回字典 + :param components_path: 必选部件json文件的路径 + :param project_path: 项目根路径 + :return: 所有典型品类syscap字典 + """ + components_path_dict = get_all_components_path(components_path) + if components_path_dict: + logging.info("start collect component path...") + component_path_list = traversal_path(components_path_dict, project_path) + syscap_dict, error_dict = handle_bundle_json_file(component_path_list) + return syscap_dict, error_dict + else: + return 0, 0 + + +def components_path_handler(project_path): + components_path = os.path.join(project_path, "out", "rk3568", "build_configs", "parts_info", + "parts_path_info.json") + return components_path + + +def main(): + logging.basicConfig(level=logging.INFO) + + args = get_args() + project_path = args.project_path + output_path = args.output_path + error_output = args.error_output + components_path = components_path_handler(project_path) + syscap_dict, error_dict = collect_all_syscap(components_path, project_path) + if syscap_dict: + dict_to_json(output_path, syscap_dict, error_output, error_dict) + + +if __name__ == "__main__": + main() From ddb6902d612983481127d22a7d804b134f87de3c Mon Sep 17 00:00:00 2001 From: cuican Date: Wed, 29 Nov 2023 16:49:03 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=89=88=E6=9D=83?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cuican --- tools/syscap_collector.py | 181 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 tools/syscap_collector.py diff --git a/tools/syscap_collector.py b/tools/syscap_collector.py new file mode 100644 index 0000000..35c958e --- /dev/null +++ b/tools/syscap_collector.py @@ -0,0 +1,181 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import logging +import os +import json +import argparse +import stat + + +def get_args(): + parser = argparse.ArgumentParser(add_help=True) + parser.add_argument( + "-p", + "--project_path", + default=r"./", + type=str, + help="root path of project. default: ./", + ) + parser.add_argument( + "-o", + "--output_path", + default=r"./", + type=str, + help="path of output file. default: ./", + ) + parser.add_argument( + "-e", + "--error_output", + action='store_true', + help="output error_list or not. default not", + ) + args = parser.parse_args() + return args + + +def dict_to_json(output_path: str, syscaps_dict: dict, error_output: bool, error_dict: dict): + flags = os.O_WRONLY | os.O_CREAT | os.O_EXCL + modes = stat.S_IWUSR | stat.S_IRUSR + logging.info("start generate syscap json...") + filename = os.path.join(output_path, 'component_list_syscap.json') + with os.fdopen(os.open(filename, flags, modes), 'w') as f: + json.dump(syscaps_dict, f) + logging.info("end...") + + if error_output: + logging.info("start generate error json......") + filename = os.path.join(output_path, 'error_dict.json') + with os.fdopen(os.open(filename, flags, modes), 'w') as error_f: + json.dump(error_dict, error_f) + logging.info("end...") + + +def check_syscap(syscap_str: str): + syscap = syscap_str.split(' = ') + if syscap[-1].lower() == 'false': + return False + else: + return syscap[0] + + +def bundle_syscap_list_handler(bundle_syscap_list: list, component_syscaps_list: list) -> list: + for i in component_syscaps_list: + i = check_syscap(i) + if i: + bundle_syscap_list.append(i) + return bundle_syscap_list + + +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() + except FileNotFoundError as e: + error_list[bundle_json_path] = str(e) + except Exception as e: + error_list[bundle_json_path] = str(e) + return bundle_syscap_list, error_list + + +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() + return path_dict + except FileNotFoundError: + logging.error(r"PATH ERROR") + return {} + + +def path_component_to_bundle(path: str) -> str: + bundle_json_path = os.path.join(path, 'bundle.json') + return bundle_json_path + + +def handle_bundle_json_file(component_path_list: list) -> tuple: + logging.info("start collect syscap path...") + syscap_list = list() + error_dict = dict() + for path in component_path_list: + bundle_json_path = path_component_to_bundle(path) + bundle_syscap_list, error_list = read_json_file(bundle_json_path) + syscap_list.extend(bundle_syscap_list) + error_dict.update(error_list) + + return {"SysCaps": syscap_list}, error_dict + + +def format_component_path(component_path: str): + sep_list = ['\\', '/'] + sep_list.remove(os.sep) + component_path = component_path.replace(sep_list[0], os.sep) + return component_path + + +def traversal_path(path_dict: dict, project_path: str) -> list: + component_path_list = list() + for _, v in path_dict.items(): + component_path = os.path.join(project_path, v) + component_path = format_component_path(component_path) + component_path_list.append(component_path) + return component_path_list + + +def collect_all_syscap(components_path: str, project_path: str) -> tuple: + """ + 从各部件收集syscap并返回字典 + :param components_path: 必选部件json文件的路径 + :param project_path: 项目根路径 + :return: 所有典型品类syscap字典 + """ + components_path_dict = get_all_components_path(components_path) + if components_path_dict: + logging.info("start collect component path...") + component_path_list = traversal_path(components_path_dict, project_path) + syscap_dict, error_dict = handle_bundle_json_file(component_path_list) + return syscap_dict, error_dict + else: + return 0, 0 + + +def components_path_handler(project_path): + components_path = os.path.join(project_path, "out", "rk3568", "build_configs", "parts_info", + "parts_path_info.json") + return components_path + + +def main(): + logging.basicConfig(level=logging.INFO) + + args = get_args() + project_path = args.project_path + output_path = args.output_path + error_output = args.error_output + components_path = components_path_handler(project_path) + syscap_dict, error_dict = collect_all_syscap(components_path, project_path) + if syscap_dict: + dict_to_json(output_path, syscap_dict, error_output, error_dict) + + +if __name__ == "__main__": + main()