openubmc-bingo 0.5.240__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of openubmc-bingo might be problematic. Click here for more details.
- bmcgo/__init__.py +12 -0
- bmcgo/bmcgo.py +22 -0
- bmcgo/bmcgo_config.py +176 -0
- bmcgo/cli/__init__.py +10 -0
- bmcgo/cli/cli.py +584 -0
- bmcgo/codegen/__init__.py +14 -0
- bmcgo/codegen/c/__init__.py +9 -0
- bmcgo/codegen/c/annotation.py +52 -0
- bmcgo/codegen/c/argument.py +42 -0
- bmcgo/codegen/c/codegen.py +153 -0
- bmcgo/codegen/c/comment.py +22 -0
- bmcgo/codegen/c/ctype_defination.py +353 -0
- bmcgo/codegen/c/helper.py +87 -0
- bmcgo/codegen/c/interface.py +63 -0
- bmcgo/codegen/c/method.py +82 -0
- bmcgo/codegen/c/property.py +180 -0
- bmcgo/codegen/c/renderer.py +21 -0
- bmcgo/codegen/c/signal.py +64 -0
- bmcgo/codegen/c/template/client.c.mako +145 -0
- bmcgo/codegen/c/template/client.h.mako +36 -0
- bmcgo/codegen/c/template/interface.c.mako +0 -0
- bmcgo/codegen/c/template/interface.introspect.xml.mako +99 -0
- bmcgo/codegen/c/template/micro_component.c.mako +32 -0
- bmcgo/codegen/c/template/public.c.mako +228 -0
- bmcgo/codegen/c/template/public.h.mako +128 -0
- bmcgo/codegen/c/template/server.c.mako +104 -0
- bmcgo/codegen/c/template/server.h.mako +36 -0
- bmcgo/codegen/lua/.lua-format +7 -0
- bmcgo/codegen/lua/Makefile +101 -0
- bmcgo/codegen/lua/__init__.py +9 -0
- bmcgo/codegen/lua/codegen.py +171 -0
- bmcgo/codegen/lua/proto/Makefile +87 -0
- bmcgo/codegen/lua/proto/ipmi_types.proto +17 -0
- bmcgo/codegen/lua/proto/types.proto +52 -0
- bmcgo/codegen/lua/script/check_intfs.py +161 -0
- bmcgo/codegen/lua/script/dto/__init__.py +11 -0
- bmcgo/codegen/lua/script/dto/exception.py +53 -0
- bmcgo/codegen/lua/script/dto/kepler_abstract.py +47 -0
- bmcgo/codegen/lua/script/dto/options.py +33 -0
- bmcgo/codegen/lua/script/dto/print_simple.py +19 -0
- bmcgo/codegen/lua/script/dto/redfish_api.py +241 -0
- bmcgo/codegen/lua/script/dto/url_route.py +195 -0
- bmcgo/codegen/lua/script/gen_db_json.py +444 -0
- bmcgo/codegen/lua/script/gen_depends.py +89 -0
- bmcgo/codegen/lua/script/gen_entry.py +263 -0
- bmcgo/codegen/lua/script/gen_feature_json.py +156 -0
- bmcgo/codegen/lua/script/gen_historical_local_db_json.py +88 -0
- bmcgo/codegen/lua/script/gen_intf_json.py +261 -0
- bmcgo/codegen/lua/script/gen_intf_rpc_json.py +575 -0
- bmcgo/codegen/lua/script/gen_ipmi_json.py +485 -0
- bmcgo/codegen/lua/script/gen_mdb_json.py +117 -0
- bmcgo/codegen/lua/script/gen_rpc_msg_json.py +487 -0
- bmcgo/codegen/lua/script/gen_schema.py +302 -0
- bmcgo/codegen/lua/script/ipmi_types_pb2.py +135 -0
- bmcgo/codegen/lua/script/loader/__init__.py +11 -0
- bmcgo/codegen/lua/script/loader/file_utils.py +33 -0
- bmcgo/codegen/lua/script/loader/kepler_abstract_collect.py +79 -0
- bmcgo/codegen/lua/script/loader/kepler_abstract_loader.py +47 -0
- bmcgo/codegen/lua/script/loader/redfish_loader.py +127 -0
- bmcgo/codegen/lua/script/lua_format.py +62 -0
- bmcgo/codegen/lua/script/mds_util.py +385 -0
- bmcgo/codegen/lua/script/merge_model.py +330 -0
- bmcgo/codegen/lua/script/merge_proto_algo.py +85 -0
- bmcgo/codegen/lua/script/proto_loader.py +47 -0
- bmcgo/codegen/lua/script/proto_plugin.py +140 -0
- bmcgo/codegen/lua/script/redfish_source_tree.py +118 -0
- bmcgo/codegen/lua/script/render_utils/__init__.py +38 -0
- bmcgo/codegen/lua/script/render_utils/base.py +25 -0
- bmcgo/codegen/lua/script/render_utils/client_lua.py +98 -0
- bmcgo/codegen/lua/script/render_utils/controller_lua.py +71 -0
- bmcgo/codegen/lua/script/render_utils/db_lua.py +224 -0
- bmcgo/codegen/lua/script/render_utils/error_lua.py +185 -0
- bmcgo/codegen/lua/script/render_utils/factory.py +52 -0
- bmcgo/codegen/lua/script/render_utils/ipmi_lua.py +159 -0
- bmcgo/codegen/lua/script/render_utils/ipmi_message_lua.py +24 -0
- bmcgo/codegen/lua/script/render_utils/mdb_lua.py +177 -0
- bmcgo/codegen/lua/script/render_utils/mdb_register.py +215 -0
- bmcgo/codegen/lua/script/render_utils/message_lua.py +26 -0
- bmcgo/codegen/lua/script/render_utils/messages_lua.py +156 -0
- bmcgo/codegen/lua/script/render_utils/model_lua.py +485 -0
- bmcgo/codegen/lua/script/render_utils/old_model_lua.py +429 -0
- bmcgo/codegen/lua/script/render_utils/plugin_lua.py +38 -0
- bmcgo/codegen/lua/script/render_utils/redfish_proto.py +86 -0
- bmcgo/codegen/lua/script/render_utils/request_lua.py +76 -0
- bmcgo/codegen/lua/script/render_utils/service_lua.py +130 -0
- bmcgo/codegen/lua/script/render_utils/utils_message_lua.py +125 -0
- bmcgo/codegen/lua/script/render_utils/validate_lua.py +221 -0
- bmcgo/codegen/lua/script/sep_ipmi_message_cmds.py +217 -0
- bmcgo/codegen/lua/script/template.py +166 -0
- bmcgo/codegen/lua/script/types_pb2.py +516 -0
- bmcgo/codegen/lua/script/utils.py +663 -0
- bmcgo/codegen/lua/script/validate.py +80 -0
- bmcgo/codegen/lua/script/yaml_to_json.py +73 -0
- bmcgo/codegen/lua/templates/Makefile +114 -0
- bmcgo/codegen/lua/templates/apps/Makefile +261 -0
- bmcgo/codegen/lua/templates/apps/Makefile.mdb.mk +64 -0
- bmcgo/codegen/lua/templates/apps/app.lua.mako +19 -0
- bmcgo/codegen/lua/templates/apps/class.lua.mako +35 -0
- bmcgo/codegen/lua/templates/apps/client.lua.mako +429 -0
- bmcgo/codegen/lua/templates/apps/controller.lua.mako +276 -0
- bmcgo/codegen/lua/templates/apps/datas.lua.mako +8 -0
- bmcgo/codegen/lua/templates/apps/db.lua.mako +89 -0
- bmcgo/codegen/lua/templates/apps/entry.lua.mako +128 -0
- bmcgo/codegen/lua/templates/apps/feature.lua.mako +37 -0
- bmcgo/codegen/lua/templates/apps/generate_route.mako +25 -0
- bmcgo/codegen/lua/templates/apps/impl_feature.lua.mako +72 -0
- bmcgo/codegen/lua/templates/apps/ipmi.lua.mako +97 -0
- bmcgo/codegen/lua/templates/apps/ipmi_cmd.lua.mako +18 -0
- bmcgo/codegen/lua/templates/apps/ipmi_message.lua.mako +36 -0
- bmcgo/codegen/lua/templates/apps/local_db.lua.mako +263 -0
- bmcgo/codegen/lua/templates/apps/main.lua.mako +25 -0
- bmcgo/codegen/lua/templates/apps/mc.lua.mako +77 -0
- bmcgo/codegen/lua/templates/apps/mdb.lua.mako +45 -0
- bmcgo/codegen/lua/templates/apps/mdb_interface.lua.mako +73 -0
- bmcgo/codegen/lua/templates/apps/message.lua.mako +38 -0
- bmcgo/codegen/lua/templates/apps/model.lua.mako +239 -0
- bmcgo/codegen/lua/templates/apps/orm_classes.lua.mako +16 -0
- bmcgo/codegen/lua/templates/apps/plugin.lua.mako +8 -0
- bmcgo/codegen/lua/templates/apps/redfish.proto.mako +47 -0
- bmcgo/codegen/lua/templates/apps/service.lua.mako +440 -0
- bmcgo/codegen/lua/templates/apps/signal_listen.lua.mako +19 -0
- bmcgo/codegen/lua/templates/apps/utils/default_intf.lua.mako +41 -0
- bmcgo/codegen/lua/templates/apps/utils/enum.mako +10 -0
- bmcgo/codegen/lua/templates/apps/utils/imports.mako +13 -0
- bmcgo/codegen/lua/templates/apps/utils/mdb_intf.lua.mako +25 -0
- bmcgo/codegen/lua/templates/apps/utils/mdb_obj.lua.mako +23 -0
- bmcgo/codegen/lua/templates/apps/utils/message.mako +160 -0
- bmcgo/codegen/lua/templates/apps/utils/request.lua.mako +59 -0
- bmcgo/codegen/lua/templates/apps/utils/validate.mako +83 -0
- bmcgo/codegen/lua/templates/errors.lua.mako +36 -0
- bmcgo/codegen/lua/templates/messages.lua.mako +32 -0
- bmcgo/codegen/lua/templates/new_app/.clang-format.mako +170 -0
- bmcgo/codegen/lua/templates/new_app/.gitignore.mako +26 -0
- bmcgo/codegen/lua/templates/new_app/CHANGELOG.md.mako +0 -0
- bmcgo/codegen/lua/templates/new_app/CMakeLists.txt.mako +29 -0
- bmcgo/codegen/lua/templates/new_app/Makefile.mako +25 -0
- bmcgo/codegen/lua/templates/new_app/README.md.mako +0 -0
- bmcgo/codegen/lua/templates/new_app/conanfile.py.mako +7 -0
- bmcgo/codegen/lua/templates/new_app/config.cfg.mako +6 -0
- bmcgo/codegen/lua/templates/new_app/mds/model.json.mako +3 -0
- bmcgo/codegen/lua/templates/new_app/mds/service.json.mako +21 -0
- bmcgo/codegen/lua/templates/new_app/permissions.ini.mako +16 -0
- bmcgo/codegen/lua/templates/new_app/src/lualib/${project_name}_app.lua.mako +16 -0
- bmcgo/codegen/lua/templates/new_app/src/service/main.lua.mako +25 -0
- bmcgo/codegen/lua/templates/new_app/test/integration/test_${project_name}.conf.mako +9 -0
- bmcgo/codegen/lua/templates/new_app/test/integration/test_${project_name}.lua.mako +47 -0
- bmcgo/codegen/lua/templates/new_app/test/unit/test.lua.mako +23 -0
- bmcgo/codegen/lua/templates/new_app/user_conf/rootfs/etc/systemd/system/${project_name}.service.mako +18 -0
- bmcgo/codegen/lua/templates/new_app/user_conf/rootfs/etc/systemd/system/multi-user.target.wants/${project_name}.service.link +1 -0
- bmcgo/component/__init__.py +10 -0
- bmcgo/component/analysis/analysis.py +183 -0
- bmcgo/component/analysis/build_deps.py +165 -0
- bmcgo/component/analysis/data_deps.py +333 -0
- bmcgo/component/analysis/dep-rules.json +912 -0
- bmcgo/component/analysis/dep_node.py +110 -0
- bmcgo/component/analysis/intf_deps.py +163 -0
- bmcgo/component/analysis/intf_validation.py +254 -0
- bmcgo/component/analysis/rule.py +211 -0
- bmcgo/component/analysis/smc_dfx_whitelist.json +11 -0
- bmcgo/component/analysis/sr_validation.py +391 -0
- bmcgo/component/build.py +222 -0
- bmcgo/component/component_dt_version_parse.py +348 -0
- bmcgo/component/component_helper.py +114 -0
- bmcgo/component/coverage/__init__.py +11 -0
- bmcgo/component/coverage/c_incremental_cov_report.template +53 -0
- bmcgo/component/coverage/incremental_cov.py +464 -0
- bmcgo/component/deploy.py +110 -0
- bmcgo/component/gen.py +169 -0
- bmcgo/component/package_info.py +236 -0
- bmcgo/component/template/conanbase.py.mako +278 -0
- bmcgo/component/template/conanfile.deploy.py.mako +40 -0
- bmcgo/component/test.py +947 -0
- bmcgo/errors.py +119 -0
- bmcgo/frame.py +217 -0
- bmcgo/functional/__init__.py +10 -0
- bmcgo/functional/analysis.py +96 -0
- bmcgo/functional/bmc_studio_action.py +98 -0
- bmcgo/functional/check.py +185 -0
- bmcgo/functional/conan_index_build.py +251 -0
- bmcgo/functional/config.py +332 -0
- bmcgo/functional/csr_build.py +724 -0
- bmcgo/functional/deploy.py +263 -0
- bmcgo/functional/diff.py +235 -0
- bmcgo/functional/fetch.py +235 -0
- bmcgo/functional/full_component.py +391 -0
- bmcgo/functional/maintain.py +381 -0
- bmcgo/functional/new.py +166 -0
- bmcgo/functional/schema_valid.py +111 -0
- bmcgo/functional/simple_sign.py +104 -0
- bmcgo/functional/upgrade.py +78 -0
- bmcgo/ipmigen/__init__.py +13 -0
- bmcgo/ipmigen/ctype_defination.py +82 -0
- bmcgo/ipmigen/ipmigen.py +309 -0
- bmcgo/ipmigen/template/cmd.c.mako +366 -0
- bmcgo/ipmigen/template/ipmi.c.mako +25 -0
- bmcgo/ipmigen/template/ipmi.h.mako +51 -0
- bmcgo/logger.py +176 -0
- bmcgo/misc.py +117 -0
- bmcgo/target/app.yml +17 -0
- bmcgo/target/install_sdk.yml +15 -0
- bmcgo/target/personal.yml +53 -0
- bmcgo/target/publish.yml +45 -0
- bmcgo/tasks/__init__.py +11 -0
- bmcgo/tasks/download_buildtools_hm.py +124 -0
- bmcgo/tasks/misc.py +15 -0
- bmcgo/tasks/task.py +354 -0
- bmcgo/tasks/task_build_conan.py +714 -0
- bmcgo/tasks/task_build_rootfs_img.py +595 -0
- bmcgo/tasks/task_buildgppbin.py +88 -0
- bmcgo/tasks/task_buildhpm_ext4.py +82 -0
- bmcgo/tasks/task_create_interface_config.py +122 -0
- bmcgo/tasks/task_download_buildtools.py +99 -0
- bmcgo/tasks/task_download_dependency.py +72 -0
- bmcgo/tasks/task_hpm_envir_prepare.py +112 -0
- bmcgo/tasks/task_packet_to_supporte.py +87 -0
- bmcgo/tasks/task_prepare.py +105 -0
- bmcgo/tasks/task_sign_and_pack_hpm.py +42 -0
- bmcgo/utils/__init__.py +10 -0
- bmcgo/utils/buffer.py +128 -0
- bmcgo/utils/combine_json_schemas.py +170 -0
- bmcgo/utils/component_post.py +54 -0
- bmcgo/utils/component_version_check.py +86 -0
- bmcgo/utils/config.py +1067 -0
- bmcgo/utils/fetch_component_code.py +232 -0
- bmcgo/utils/install_manager.py +61 -0
- bmcgo/utils/installations/__init__.py +10 -0
- bmcgo/utils/installations/base_installer.py +70 -0
- bmcgo/utils/installations/install_consts.py +30 -0
- bmcgo/utils/installations/install_plans/bingo.yml +11 -0
- bmcgo/utils/installations/install_workflow.py +50 -0
- bmcgo/utils/installations/installers/apt_installer.py +177 -0
- bmcgo/utils/installations/installers/pip_installer.py +46 -0
- bmcgo/utils/installations/version_util.py +100 -0
- bmcgo/utils/mapping_config_patch.py +443 -0
- bmcgo/utils/perf_analysis.py +114 -0
- bmcgo/utils/tools.py +704 -0
- bmcgo/worker.py +417 -0
- openubmc_bingo-0.5.240.dist-info/METADATA +30 -0
- openubmc_bingo-0.5.240.dist-info/RECORD +242 -0
- openubmc_bingo-0.5.240.dist-info/WHEEL +5 -0
- openubmc_bingo-0.5.240.dist-info/entry_points.txt +2 -0
- openubmc_bingo-0.5.240.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
DATAMODE_DIR = $(shell pwd)
|
|
2
|
+
SCRIPT_DIR = $(DATAMODE_DIR)/script
|
|
3
|
+
|
|
4
|
+
GEN_BIN = $(SCRIPT_DIR)/gen.py
|
|
5
|
+
GEN_DATAS_BIN = $(SCRIPT_DIR)/gen_datas.py
|
|
6
|
+
RESTAPI_DIRS = routes
|
|
7
|
+
|
|
8
|
+
BUILD_DIR = ${DATAMODE_DIR}/temp
|
|
9
|
+
PROTO_OUT_DIR = ${BUILD_DIR}/proto
|
|
10
|
+
GENERATE_OUT_DIR = ${BUILD_DIR}/gen
|
|
11
|
+
PROTO_DIR = ${DATAMODE_DIR}/proto
|
|
12
|
+
JSON_DIR = ${PROJECT_DIR}/json
|
|
13
|
+
MDS_DIR = ${PROJECT_DIR}/mds
|
|
14
|
+
CONF_DIR = ${PROJECT_DIR}/conf
|
|
15
|
+
TEMP_DIR = ${DATAMODE_DIR}/../../temp
|
|
16
|
+
GEN_BAK_DIR = ${DATAMODE_DIR}/../../gen_bak
|
|
17
|
+
MDB_INTF_DIR = ${TEMP_DIR}/opt/bmc/apps/mdb_interface/
|
|
18
|
+
|
|
19
|
+
.PHONY: protos gen all dft_protos debug_protos
|
|
20
|
+
default: all
|
|
21
|
+
|
|
22
|
+
protos:
|
|
23
|
+
python3 ${SCRIPT_DIR}/check_intfs.py -d ${MDB_INTF_DIR} -n ${PROJECT_NAME} -m ${MDS_DIR} -o ${SCRIPT_DIR}/../temp/check_intfs.json
|
|
24
|
+
@mkdir -p ${PROTO_OUT_DIR}
|
|
25
|
+
@cd proto && make -j12 \
|
|
26
|
+
PROTO_OUT_DIR=${PROTO_OUT_DIR} \
|
|
27
|
+
SCRIPT_DIR=${SCRIPT_DIR} \
|
|
28
|
+
PROTO_DIR=${PROTO_DIR} \
|
|
29
|
+
JSON_DIR=${JSON_DIR}\
|
|
30
|
+
PROJECT_NAME=${PROJECT_NAME}\
|
|
31
|
+
VERSION=${VERSION} \
|
|
32
|
+
|
|
33
|
+
DFT_SERVICE_JSON_EXISTS := $(wildcard ${MDS_DIR}/service.json)
|
|
34
|
+
DFT_MODEL_JSON_EXISTS := $(wildcard ${MDS_DIR}/dft/model.json)
|
|
35
|
+
ifneq ($(and $(DFT_SERVICE_JSON_EXISTS),$(DFT_MODEL_JSON_EXISTS)),)
|
|
36
|
+
dft_protos:
|
|
37
|
+
@mkdir -p ${PROTO_OUT_DIR}/dft
|
|
38
|
+
@cd proto && make -j12 \
|
|
39
|
+
PROTO_OUT_DIR=${PROTO_OUT_DIR}/dft \
|
|
40
|
+
SCRIPT_DIR=${SCRIPT_DIR} \
|
|
41
|
+
PROTO_DIR=${PROTO_DIR} \
|
|
42
|
+
JSON_DIR=${JSON_DIR}\
|
|
43
|
+
PROJECT_NAME=${PROJECT_NAME}\
|
|
44
|
+
VERSION=${VERSION} \
|
|
45
|
+
|
|
46
|
+
else
|
|
47
|
+
dft_protos:
|
|
48
|
+
endif
|
|
49
|
+
|
|
50
|
+
DEBUG_SERVICE_JSON_EXISTS := $(wildcard ${MDS_DIR}/service.json)
|
|
51
|
+
DEBUG_MODEL_JSON_EXISTS := $(wildcard ${MDS_DIR}/debug/model.json)
|
|
52
|
+
ifneq ($(and $(DEBUG_SERVICE_JSON_EXISTS),$(DEBUG_MODEL_JSON_EXISTS)),)
|
|
53
|
+
debug_protos:
|
|
54
|
+
@mkdir -p ${PROTO_OUT_DIR}/debug
|
|
55
|
+
@cd proto && make -j12 \
|
|
56
|
+
PROTO_OUT_DIR=${PROTO_OUT_DIR}/debug \
|
|
57
|
+
SCRIPT_DIR=${SCRIPT_DIR} \
|
|
58
|
+
PROTO_DIR=${PROTO_DIR} \
|
|
59
|
+
JSON_DIR=${JSON_DIR}\
|
|
60
|
+
PROJECT_NAME=${PROJECT_NAME}\
|
|
61
|
+
VERSION=${VERSION} \
|
|
62
|
+
|
|
63
|
+
else
|
|
64
|
+
debug_protos:
|
|
65
|
+
endif
|
|
66
|
+
|
|
67
|
+
gen: protos dft_protos debug_protos
|
|
68
|
+
@cd templates && make -j12 \
|
|
69
|
+
PROTO_OUT_DIR=${PROTO_OUT_DIR} \
|
|
70
|
+
GENERATE_OUT_DIR=${GENERATE_OUT_DIR} \
|
|
71
|
+
SCRIPT_DIR=${SCRIPT_DIR} \
|
|
72
|
+
PROTO_DIR=${PROTO_DIR} \
|
|
73
|
+
PROJECT_NAME=${PROJECT_NAME} \
|
|
74
|
+
VERSION=${VERSION} \
|
|
75
|
+
RESTAPI_DIRS="${RESTAPI_DIRS}" \
|
|
76
|
+
MDS_DIR=${MDS_DIR}\
|
|
77
|
+
CONF_DIR=${CONF_DIR}\
|
|
78
|
+
TEMP_DIR=${TEMP_DIR}\
|
|
79
|
+
GEN_BAK_DIR=${GEN_BAK_DIR}
|
|
80
|
+
|
|
81
|
+
mdb: protos
|
|
82
|
+
@cd templates && make -j12 \
|
|
83
|
+
PROTO_OUT_DIR=${PROTO_OUT_DIR} \
|
|
84
|
+
GENERATE_OUT_DIR=${GENERATE_OUT_DIR} \
|
|
85
|
+
SCRIPT_DIR=${SCRIPT_DIR} \
|
|
86
|
+
PROTO_DIR=${PROTO_DIR} \
|
|
87
|
+
PROJECT_NAME=${PROJECT_NAME} \
|
|
88
|
+
VERSION=${VERSION} \
|
|
89
|
+
mdb
|
|
90
|
+
|
|
91
|
+
messages: protos
|
|
92
|
+
@cd templates && make -j12 \
|
|
93
|
+
PROTO_OUT_DIR=${PROTO_OUT_DIR} \
|
|
94
|
+
GENERATE_OUT_DIR=${GENERATE_OUT_DIR} \
|
|
95
|
+
SCRIPT_DIR=${SCRIPT_DIR} \
|
|
96
|
+
PROTO_DIR=${PROTO_DIR} \
|
|
97
|
+
PROJECT_NAME=${PROJECT_NAME} \
|
|
98
|
+
VERSION=${VERSION} \
|
|
99
|
+
BUILD_DIR=${BUILD_DIR} \
|
|
100
|
+
messages
|
|
101
|
+
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
2
|
+
# openUBMC is licensed under Mulan PSL v2.
|
|
3
|
+
# You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
4
|
+
# You may obtain a copy of Mulan PSL v2 at:
|
|
5
|
+
# http://license.coscl.org.cn/MulanPSL2
|
|
6
|
+
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
|
7
|
+
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
|
8
|
+
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
|
9
|
+
# See the Mulan PSL v2 for more details.
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
#!/usr/bin/python3
|
|
2
|
+
# coding: utf-8
|
|
3
|
+
# Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
4
|
+
# openUBMC is licensed under Mulan PSL v2.
|
|
5
|
+
# You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
6
|
+
# You may obtain a copy of Mulan PSL v2 at:
|
|
7
|
+
# http://license.coscl.org.cn/MulanPSL2
|
|
8
|
+
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
|
9
|
+
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
|
10
|
+
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
|
11
|
+
# See the Mulan PSL v2 for more details.
|
|
12
|
+
import configparser
|
|
13
|
+
import json
|
|
14
|
+
import os
|
|
15
|
+
import re
|
|
16
|
+
import subprocess
|
|
17
|
+
import shutil
|
|
18
|
+
from bmcgo.codegen.c.helper import Helper
|
|
19
|
+
from bmcgo import misc
|
|
20
|
+
from bmcgo.utils.tools import Tools
|
|
21
|
+
cwd = os.path.split(os.path.realpath(__file__))[0]
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class CodeGen(object):
|
|
25
|
+
def __init__(self, project_dir, version, remote):
|
|
26
|
+
self.gen_tool_dir = os.path.join(project_dir, 'temp/lua_codegen')
|
|
27
|
+
self.project_dir = project_dir
|
|
28
|
+
self.project_name = self.get_project_name()
|
|
29
|
+
self.version = version
|
|
30
|
+
self.remote = remote
|
|
31
|
+
|
|
32
|
+
def read_service_json(self):
|
|
33
|
+
service_path = os.path.join(self.project_dir, "mds", "service.json")
|
|
34
|
+
if not os.path.isfile(service_path):
|
|
35
|
+
raise RuntimeError("mds/service.json文件不存在")
|
|
36
|
+
with open(service_path, "r") as service_fp:
|
|
37
|
+
content = json.load(service_fp)
|
|
38
|
+
return content
|
|
39
|
+
|
|
40
|
+
def get_project_name(self):
|
|
41
|
+
project_name = self.read_service_json().get("name")
|
|
42
|
+
if not project_name:
|
|
43
|
+
raise RuntimeError("需要在mds/service.json中配置name")
|
|
44
|
+
return project_name
|
|
45
|
+
|
|
46
|
+
def get_lua_format(self):
|
|
47
|
+
lua_format = shutil.which("lua-format")
|
|
48
|
+
if lua_format:
|
|
49
|
+
return lua_format
|
|
50
|
+
|
|
51
|
+
def get_mdb_interface_package(self):
|
|
52
|
+
channel = f"@{Tools().conan_user}/{misc.StageEnum.STAGE_RC.value}"
|
|
53
|
+
package = f"mdb_interface/[>=0.0.1]{channel}"
|
|
54
|
+
dependencies = self.read_service_json().get(misc.CONAN_DEPDENCIES_KEY)
|
|
55
|
+
if not dependencies:
|
|
56
|
+
return package
|
|
57
|
+
dep_list = dependencies.get("test", [])
|
|
58
|
+
dep_list.extend(dependencies.get("build", []))
|
|
59
|
+
for dep in dep_list:
|
|
60
|
+
conan_package = dep.get("conan", "")
|
|
61
|
+
if not conan_package.startswith("mdb_interface"):
|
|
62
|
+
continue
|
|
63
|
+
if "@" in conan_package:
|
|
64
|
+
package = conan_package
|
|
65
|
+
else:
|
|
66
|
+
package = conan_package + channel
|
|
67
|
+
return package
|
|
68
|
+
|
|
69
|
+
def get_mdb_interface_url(self, temp_dir, target_dir):
|
|
70
|
+
ini_parser = configparser.ConfigParser()
|
|
71
|
+
ok = ini_parser.read(misc.GLOBAL_CFG_FILE)
|
|
72
|
+
if not ok or not ini_parser.has_option("codegen", "mdb_interface_url"):
|
|
73
|
+
return False
|
|
74
|
+
mdb_interface_url = ini_parser["codegen"]["mdb_interface_url"]
|
|
75
|
+
|
|
76
|
+
git_cmd = Helper.get_git_path()
|
|
77
|
+
cmd = [git_cmd, "clone", mdb_interface_url, os.path.join(temp_dir, "mdb_interface"), "--depth=1"]
|
|
78
|
+
subprocess.run(cmd, stdout=subprocess.DEVNULL)
|
|
79
|
+
shutil.copytree(os.path.join(temp_dir, "mdb_interface/json"), target_dir)
|
|
80
|
+
return True
|
|
81
|
+
|
|
82
|
+
def setup_mdb_interface(self):
|
|
83
|
+
target_dir = os.path.join(self.project_dir, 'temp/opt/bmc/apps/mdb_interface')
|
|
84
|
+
shutil.rmtree(target_dir, ignore_errors=True)
|
|
85
|
+
temp_dir = os.path.join(self.project_dir, 'temp/.mdb_interface_temp')
|
|
86
|
+
shutil.rmtree(temp_dir, ignore_errors=True)
|
|
87
|
+
os.makedirs(temp_dir, exist_ok=True)
|
|
88
|
+
if self.get_mdb_interface_url(temp_dir, target_dir):
|
|
89
|
+
shutil.rmtree(temp_dir, ignore_errors=True)
|
|
90
|
+
return
|
|
91
|
+
package = self.get_mdb_interface_package()
|
|
92
|
+
cmd = ["conan", "install", package, f"-if={temp_dir}", "--build=missing", "-g", "deploy"]
|
|
93
|
+
cmd += ["-pr=profile.dt.ini", "-s", "build_type=Dt"]
|
|
94
|
+
if self.remote:
|
|
95
|
+
cmd += ["-r", self.remote]
|
|
96
|
+
subprocess.call(cmd)
|
|
97
|
+
shutil.copytree(os.path.join(temp_dir, "mdb_interface/opt/bmc/apps/mdb_interface"), target_dir)
|
|
98
|
+
shutil.rmtree(temp_dir, ignore_errors=True)
|
|
99
|
+
|
|
100
|
+
def is_valid_date(self, date_str):
|
|
101
|
+
pattern = r'^-- Create: \d{4}-\d{1,2}-\d{1,2}$'
|
|
102
|
+
return bool(re.match(pattern, date_str))
|
|
103
|
+
|
|
104
|
+
def process_file_header(self, filepath, bak_filepath):
|
|
105
|
+
with open(filepath, 'r') as file1, open(bak_filepath, 'r') as file2:
|
|
106
|
+
# 逐行读取文件内容
|
|
107
|
+
file1_lines = file1.readlines()
|
|
108
|
+
file2_lines = file2.readlines()
|
|
109
|
+
file1_lines_num = len(file1_lines)
|
|
110
|
+
if file1_lines_num != len(file2_lines):
|
|
111
|
+
return
|
|
112
|
+
|
|
113
|
+
# 比较文件内容
|
|
114
|
+
for i in range(file1_lines_num):
|
|
115
|
+
if file1_lines[i] == file2_lines[i]:
|
|
116
|
+
continue
|
|
117
|
+
if 'Copyright' in file2_lines[i]:
|
|
118
|
+
continue
|
|
119
|
+
if not self.is_valid_date(file1_lines[i]) or not self.is_valid_date(file2_lines[i]):
|
|
120
|
+
return
|
|
121
|
+
shutil.move(bak_filepath, filepath)
|
|
122
|
+
|
|
123
|
+
def process_file_headers(self, gen_dir, gen_bak_dir):
|
|
124
|
+
for subdir, _, files in os.walk(gen_dir):
|
|
125
|
+
for file in files:
|
|
126
|
+
filepath = os.path.join(subdir, file)
|
|
127
|
+
bak_filepath = os.path.join(gen_bak_dir, os.path.relpath(filepath, gen_dir))
|
|
128
|
+
if os.path.exists(bak_filepath):
|
|
129
|
+
self.process_file_header(filepath, bak_filepath)
|
|
130
|
+
|
|
131
|
+
# 可能包含手写代码的文件需要保留
|
|
132
|
+
whitelist = ['entry.lua', 'signal_listen.lua', 'factory.lua']
|
|
133
|
+
for item in whitelist:
|
|
134
|
+
old_filepath = os.path.join(gen_bak_dir, self.project_name, item)
|
|
135
|
+
new_filepath = os.path.join(gen_dir, self.project_name, item)
|
|
136
|
+
if os.path.exists(old_filepath):
|
|
137
|
+
shutil.copy(old_filepath, new_filepath)
|
|
138
|
+
|
|
139
|
+
def generate_code_run(self, args):
|
|
140
|
+
shutil.rmtree(self.gen_tool_dir, ignore_errors=True)
|
|
141
|
+
shutil.copytree(cwd, self.gen_tool_dir)
|
|
142
|
+
self.setup_mdb_interface()
|
|
143
|
+
lua_format = self.get_lua_format()
|
|
144
|
+
cmd = [
|
|
145
|
+
"/usr/bin/make", "-j12", f"PROJECT_NAME={self.project_name}", f"TPL_DIR={self.gen_tool_dir}",
|
|
146
|
+
f"VERSION={self.version}", "gen"
|
|
147
|
+
]
|
|
148
|
+
subprocess.run(cmd, env=dict(os.environ, LUA_FORMAT=lua_format, LUA_CODEGEN_VERSION=str(self.version),
|
|
149
|
+
PROJECT_NAME=self.project_name), check=True)
|
|
150
|
+
if args.with_template:
|
|
151
|
+
script_path = os.path.join(cwd, 'script', 'gen_entry.py')
|
|
152
|
+
mako_dir = os.path.join(cwd, 'templates', 'apps')
|
|
153
|
+
model_path = os.path.join(self.gen_tool_dir, self.project_name, '_model.json')
|
|
154
|
+
ipmi_path = os.path.join(self.project_dir, 'mds', 'ipmi.json')
|
|
155
|
+
subprocess.run(["/usr/bin/python3", script_path, "-i", ipmi_path, "-m", model_path, "-o", self.project_dir,
|
|
156
|
+
"-n", self.project_name, "-f", lua_format, "-t", mako_dir, "-v", self.version], check=True)
|
|
157
|
+
|
|
158
|
+
def gen(self, args):
|
|
159
|
+
check_cmd_file = os.path.join(self.project_dir, 'temp/lua_codegen/temp/check_cmd.json')
|
|
160
|
+
if os.path.exists(check_cmd_file):
|
|
161
|
+
os.remove(check_cmd_file)
|
|
162
|
+
|
|
163
|
+
gen_dir = os.path.join(self.project_dir, 'gen')
|
|
164
|
+
gen_bak_dir = os.path.join(self.project_dir, 'gen_bak')
|
|
165
|
+
if os.path.exists(gen_dir) and not os.path.exists(gen_bak_dir):
|
|
166
|
+
shutil.move(gen_dir, gen_bak_dir)
|
|
167
|
+
self.generate_code_run(args)
|
|
168
|
+
|
|
169
|
+
if os.path.exists(gen_bak_dir):
|
|
170
|
+
self.process_file_headers(gen_dir, gen_bak_dir)
|
|
171
|
+
shutil.rmtree(gen_bak_dir)
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
PWD = $(shell pwd)
|
|
2
|
+
SCRIPT_DIR = $(PWD)/../script
|
|
3
|
+
PROTO_OUT_DIR = $(PWD)/../temp/proto
|
|
4
|
+
|
|
5
|
+
PROTO_PLUGIN_BIN = ${SCRIPT_DIR}/proto_plugin.py
|
|
6
|
+
YAML_TO_JSON_BIN = ${SCRIPT_DIR}/yaml_to_json.py
|
|
7
|
+
|
|
8
|
+
.PHONY: all protos yamls types json_path json_intf
|
|
9
|
+
default: all
|
|
10
|
+
|
|
11
|
+
# 遍历读取当前目录的所有 proto 文件
|
|
12
|
+
define get_proto_files
|
|
13
|
+
$(wildcard $(1)*.proto) $(foreach e, $(wildcard $(1)*), $(call get_proto_files, $(e)/))
|
|
14
|
+
endef
|
|
15
|
+
PROTO_FILES = $(subst $(PROTO_DIR),,$(call get_proto_files, ${PROTO_DIR}))
|
|
16
|
+
|
|
17
|
+
# 遍历读取当前目录的所有 .yaml 文件
|
|
18
|
+
define get_yaml_files
|
|
19
|
+
$(wildcard $(1)*.yaml) $(foreach e, $(wildcard $(1)*), $(call get_yaml_files, $(e)/))
|
|
20
|
+
endef
|
|
21
|
+
YAML_FILES_TMP = $(subst $(PROTO_DIR),,$(call get_yaml_files, ${PROTO_DIR}))
|
|
22
|
+
YAML_FILES = $(YAML_FILES_TMP:.yaml=)
|
|
23
|
+
|
|
24
|
+
# 编译 types.proto 文件
|
|
25
|
+
${SCRIPT_DIR}/types_pb2.py: types.proto
|
|
26
|
+
protoc --python_out=${SCRIPT_DIR} -I$(PWD) types.proto
|
|
27
|
+
|
|
28
|
+
# 编译 ipmi_types.proto 文件
|
|
29
|
+
${SCRIPT_DIR}/ipmi_types_pb2.py: ipmi_types.proto
|
|
30
|
+
protoc --python_out=${SCRIPT_DIR} -I$(PWD) ipmi_types.proto
|
|
31
|
+
|
|
32
|
+
types: ${SCRIPT_DIR}/types_pb2.py ${SCRIPT_DIR}/ipmi_types_pb2.py
|
|
33
|
+
|
|
34
|
+
define MAKE_PROTO
|
|
35
|
+
$$(PROTO_OUT_DIR)/$(1).json: $(PROTO_DIR)$(1) $${PROTO_PLUGIN_BIN} $${SCRIPT_DIR}/types_pb2.py $${SCRIPT_DIR}/ipmi_types_pb2.py
|
|
36
|
+
@mkdir -p $$(dir $$@)
|
|
37
|
+
protoc --plugin=protoc-gen-custom=$$(PROTO_PLUGIN_BIN) --custom_out=$$(PROTO_OUT_DIR) -I$(PWD) -I$(PROTO_DIR) $(PROTO_DIR)$(1)
|
|
38
|
+
endef
|
|
39
|
+
|
|
40
|
+
$(foreach v, $(PROTO_FILES), $(eval $(call MAKE_PROTO,$(v))))
|
|
41
|
+
|
|
42
|
+
# 编译所有 .proto 文件
|
|
43
|
+
protos: $(foreach v, $(PROTO_FILES), $(PROTO_OUT_DIR)/$(v).json)
|
|
44
|
+
|
|
45
|
+
# 编译所有path .json 文件
|
|
46
|
+
define get_json_files
|
|
47
|
+
$(wildcard $(1)*.json) $(foreach e, $(wildcard $(1)*), $(call get_json_files, $(e)/))
|
|
48
|
+
endef
|
|
49
|
+
JSON_FILES_TMP = $(subst $(JSON_DIR),,$(call get_json_files, ${JSON_DIR}/path))
|
|
50
|
+
JSON_FILES = $(JSON_FILES_TMP:.json=)
|
|
51
|
+
|
|
52
|
+
JSON_BIN = ${SCRIPT_DIR}/gen_mdb_json.py
|
|
53
|
+
define MAKE_JSON
|
|
54
|
+
$$(PROTO_OUT_DIR)/$(1).json: $(JSON_DIR)$(1).json $${JSON_BIN}
|
|
55
|
+
@mkdir -p $$(dir $$@)
|
|
56
|
+
python3 ${JSON_BIN} -i $(JSON_DIR)$(1).json -o $$@
|
|
57
|
+
endef
|
|
58
|
+
$(foreach v, $(JSON_FILES), $(eval $(call MAKE_JSON,$(v))))
|
|
59
|
+
json_path: $(foreach v, $(JSON_FILES), $(PROTO_OUT_DIR)/$(v).json)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
# 编译所有intf .json 文件
|
|
63
|
+
|
|
64
|
+
JSON_INTF_FILES_TMP = $(subst $(JSON_DIR),,$(call get_json_files, ${JSON_DIR}/intf))
|
|
65
|
+
JSON_INTF_FILES = $(JSON_INTF_FILES_TMP:.json=)
|
|
66
|
+
|
|
67
|
+
JSON_INTF_BIN = ${SCRIPT_DIR}/gen_intf_json.py
|
|
68
|
+
define MAKE_INTF_JSON
|
|
69
|
+
$$(PROTO_OUT_DIR)/$(1).json: $(JSON_DIR)$(1).json $${JSON_BIN}
|
|
70
|
+
@mkdir -p $$(dir $$@)
|
|
71
|
+
python3 ${JSON_INTF_BIN} -i $(JSON_DIR)$(1).json -o $$@ -d ${JSON_DIR}
|
|
72
|
+
endef
|
|
73
|
+
$(foreach v, $(JSON_INTF_FILES), $(eval $(call MAKE_INTF_JSON,$(v))))
|
|
74
|
+
json_intf: $(foreach v, $(JSON_INTF_FILES), $(PROTO_OUT_DIR)/$(v).json)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
# 编译所有 .yaml 文件
|
|
78
|
+
define MAKE_YAML
|
|
79
|
+
$$(PROTO_OUT_DIR)/$(1).json: $(PROTO_DIR)$(1).yaml $${YAML_TO_JSON_BIN}
|
|
80
|
+
@mkdir -p $$(dir $$@)
|
|
81
|
+
python3 ${YAML_TO_JSON_BIN} -i $(PROTO_DIR)$(1).yaml -b ./ -o $$@
|
|
82
|
+
endef
|
|
83
|
+
$(foreach v, $(YAML_FILES), $(eval $(call MAKE_YAML,$(v))))
|
|
84
|
+
yamls: $(foreach v, $(YAML_FILES), $(PROTO_OUT_DIR)/$(v).json)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
all: protos yamls json_path json_intf
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
syntax = "proto3";
|
|
2
|
+
import "google/protobuf/descriptor.proto";
|
|
3
|
+
|
|
4
|
+
extend google.protobuf.FileOptions {
|
|
5
|
+
string default_channel = 71001;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
extend google.protobuf.MessageOptions {
|
|
9
|
+
string channel = 81001;
|
|
10
|
+
int32 net_fn = 81002;
|
|
11
|
+
int32 cmd = 81003;
|
|
12
|
+
string prio = 81004;
|
|
13
|
+
string privilege = 81005;
|
|
14
|
+
string decode = 81006;
|
|
15
|
+
string encode = 81007;
|
|
16
|
+
string filters = 81008;
|
|
17
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
syntax = "proto3";
|
|
2
|
+
import "google/protobuf/descriptor.proto";
|
|
3
|
+
|
|
4
|
+
message int8 {}
|
|
5
|
+
message int16 {}
|
|
6
|
+
message uint8 {}
|
|
7
|
+
message uint16 {}
|
|
8
|
+
|
|
9
|
+
extend google.protobuf.FieldOptions {
|
|
10
|
+
bool unique = 90001;
|
|
11
|
+
bool primary_key = 90002;
|
|
12
|
+
string default = 90003;
|
|
13
|
+
string datas = 90004;
|
|
14
|
+
bool allow_null = 90005;
|
|
15
|
+
string validate = 90006;
|
|
16
|
+
int32 max_len = 90007;
|
|
17
|
+
string header_name = 90008;
|
|
18
|
+
string rename = 90009;
|
|
19
|
+
int32 group = 90010;
|
|
20
|
+
string schema = 90011;
|
|
21
|
+
string persistence_ex = 90012;
|
|
22
|
+
|
|
23
|
+
bool const = 90100;
|
|
24
|
+
bool emit_change = 90101;
|
|
25
|
+
bool emit_no_value = 90102;
|
|
26
|
+
bool explicit = 90103;
|
|
27
|
+
bool readonly = 90104;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
extend google.protobuf.MessageOptions {
|
|
31
|
+
bool singleton = 80001;
|
|
32
|
+
string primary_keys = 80002;
|
|
33
|
+
string table_name = 80003;
|
|
34
|
+
string url = 80004;
|
|
35
|
+
string require_auth = 80005;
|
|
36
|
+
string path = 80006;
|
|
37
|
+
string interface = 80007;
|
|
38
|
+
bool flatten = 80008;
|
|
39
|
+
bool auth = 80009;
|
|
40
|
+
bool query = 80010;
|
|
41
|
+
string persistence = 80011;
|
|
42
|
+
string user_privilege = 80012;
|
|
43
|
+
string system_lockdown = 80013;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
extend google.protobuf.ServiceOptions {
|
|
47
|
+
string service_interface = 70001;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
extend google.protobuf.MethodOptions {
|
|
51
|
+
bool initiator = 60001;
|
|
52
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# coding=utf-8
|
|
3
|
+
# Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
4
|
+
# openUBMC is licensed under Mulan PSL v2.
|
|
5
|
+
# You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
6
|
+
# You may obtain a copy of Mulan PSL v2 at:
|
|
7
|
+
# http://license.coscl.org.cn/MulanPSL2
|
|
8
|
+
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
|
9
|
+
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
|
10
|
+
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
|
11
|
+
# See the Mulan PSL v2 for more details.
|
|
12
|
+
|
|
13
|
+
import json
|
|
14
|
+
import logging
|
|
15
|
+
import getopt
|
|
16
|
+
import sys
|
|
17
|
+
import os
|
|
18
|
+
import stat
|
|
19
|
+
import time
|
|
20
|
+
from collections import defaultdict
|
|
21
|
+
from pathlib import Path
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class IntfPool:
|
|
25
|
+
def __init__(self, project_name, mdb_path, mds_dir):
|
|
26
|
+
self.pool = defaultdict(set)
|
|
27
|
+
self.dev_pool = defaultdict(set)
|
|
28
|
+
self.output = dict()
|
|
29
|
+
self.duplicates = []
|
|
30
|
+
for root, _, files in os.walk(mds_dir):
|
|
31
|
+
for file in files:
|
|
32
|
+
if file == "service.json":
|
|
33
|
+
self.add_from_service(os.path.join(root, file))
|
|
34
|
+
if file == "model.json":
|
|
35
|
+
self.add_from_model(os.path.join(root, file))
|
|
36
|
+
|
|
37
|
+
if project_name == 'hwproxy':
|
|
38
|
+
for root, _, files in os.walk(os.path.join(mdb_path, "intf/mdb/bmc/dev")):
|
|
39
|
+
for file in files:
|
|
40
|
+
self.add_from_device_tree(os.path.join(root, file))
|
|
41
|
+
self.resolve_duplicates()
|
|
42
|
+
self.log_duplicates()
|
|
43
|
+
|
|
44
|
+
@staticmethod
|
|
45
|
+
def open_mds(mds_file):
|
|
46
|
+
with os.fdopen(os.open(mds_file, os.O_RDONLY, stat.S_IRUSR), 'r') as mds_fp:
|
|
47
|
+
ret = json.load(mds_fp)
|
|
48
|
+
return ret
|
|
49
|
+
|
|
50
|
+
def extend_alias(self, alias, interface):
|
|
51
|
+
prefix_len = len(interface) - len(alias) - 1
|
|
52
|
+
prefix = interface[:prefix_len]
|
|
53
|
+
if prefix == "bmc":
|
|
54
|
+
return alias
|
|
55
|
+
dot_index = prefix.rfind('.')
|
|
56
|
+
ret = interface[(dot_index + 1):]
|
|
57
|
+
new_alias = ret.replace('.', '')
|
|
58
|
+
self.duplicates.append((interface, alias, new_alias))
|
|
59
|
+
return ret
|
|
60
|
+
|
|
61
|
+
def log_duplicates(self):
|
|
62
|
+
for interface, alias, new_alias in self.duplicates:
|
|
63
|
+
logging.warning("接口 '%s' 末尾部分 '%s' 重复,已扩展为 '%s'", interface, alias, new_alias)
|
|
64
|
+
logging.warning("手写代码中如有调用名字以 '%s' 拼接的自动生成函数,请同步修改", alias)
|
|
65
|
+
time.sleep(3 / len(self.duplicates))
|
|
66
|
+
|
|
67
|
+
def add_from_service(self, service_json):
|
|
68
|
+
if not os.path.exists(service_json):
|
|
69
|
+
return
|
|
70
|
+
|
|
71
|
+
service_dict = self.open_mds(service_json)
|
|
72
|
+
for item in service_dict.get("required", []):
|
|
73
|
+
interface = item.get("interface")
|
|
74
|
+
if interface:
|
|
75
|
+
self.pool[interface.split('.')[-1]].add(interface)
|
|
76
|
+
|
|
77
|
+
def add_from_model(self, model_json):
|
|
78
|
+
if not os.path.exists(model_json):
|
|
79
|
+
return
|
|
80
|
+
|
|
81
|
+
model_dict = self.open_mds(model_json)
|
|
82
|
+
for class_data in model_dict.values():
|
|
83
|
+
for interface in class_data.get("interfaces", {}):
|
|
84
|
+
self.pool[interface.split('.')[-1]].add(interface)
|
|
85
|
+
|
|
86
|
+
def add_from_device_tree(self, intf_json):
|
|
87
|
+
if not os.path.exists(intf_json):
|
|
88
|
+
return
|
|
89
|
+
|
|
90
|
+
intf_dict = self.open_mds(intf_json)
|
|
91
|
+
for interface in intf_dict.keys():
|
|
92
|
+
self.dev_pool[interface.split('.')[-1]].add(interface)
|
|
93
|
+
|
|
94
|
+
def resolve_duplicates(self):
|
|
95
|
+
while self.pool:
|
|
96
|
+
temp_pool = self.pool
|
|
97
|
+
self.pool = defaultdict(set)
|
|
98
|
+
for alias, interfaces in temp_pool.items():
|
|
99
|
+
if len(interfaces) == 1:
|
|
100
|
+
self.add_to_output(alias, interfaces)
|
|
101
|
+
continue
|
|
102
|
+
for interface in interfaces:
|
|
103
|
+
self.pool[self.extend_alias(alias, interface)].add(interface)
|
|
104
|
+
|
|
105
|
+
while self.dev_pool:
|
|
106
|
+
temp_pool = self.dev_pool
|
|
107
|
+
self.dev_pool = defaultdict(set)
|
|
108
|
+
for alias, interfaces in temp_pool.items():
|
|
109
|
+
if len(interfaces) == 1:
|
|
110
|
+
self.add_to_output(alias, interfaces)
|
|
111
|
+
continue
|
|
112
|
+
for interface in interfaces:
|
|
113
|
+
self.dev_pool[self.extend_alias(alias, interface)].add(interface)
|
|
114
|
+
|
|
115
|
+
def add_to_output(self, alias, interfaces):
|
|
116
|
+
for interface in interfaces:
|
|
117
|
+
self.output[interface] = alias.replace('.', '')
|
|
118
|
+
|
|
119
|
+
def save_output(self, output_file):
|
|
120
|
+
out_path = Path(output_file).resolve()
|
|
121
|
+
out_dir = out_path.parent
|
|
122
|
+
if not os.path.exists(out_dir):
|
|
123
|
+
os.mkdir(out_dir)
|
|
124
|
+
with os.fdopen(os.open(out_path, os.O_WRONLY | os.O_CREAT | os.O_TRUNC,
|
|
125
|
+
stat.S_IWUSR | stat.S_IRUSR), 'w') as out_fp:
|
|
126
|
+
json.dump(self.output, out_fp)
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def usage():
|
|
130
|
+
logging.info("check_intfs.py -m <mds_dir> -o <output_file>")
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def main(argv):
|
|
134
|
+
logging.getLogger().setLevel(logging.INFO)
|
|
135
|
+
options = dict()
|
|
136
|
+
try:
|
|
137
|
+
opts, _ = getopt.getopt(argv, "hd:n:s:m:o:", ["help", "service=", "model=",
|
|
138
|
+
"out"])
|
|
139
|
+
except getopt.GetoptError as getopt_error:
|
|
140
|
+
logging.error(getopt_error)
|
|
141
|
+
return
|
|
142
|
+
for opt, arg in opts:
|
|
143
|
+
if opt in ("-h", "--help"):
|
|
144
|
+
usage()
|
|
145
|
+
return
|
|
146
|
+
elif opt in ("-d", "--dir"):
|
|
147
|
+
mdb_path = arg
|
|
148
|
+
elif opt in ("-n", "--project_name"):
|
|
149
|
+
project_name = arg
|
|
150
|
+
elif opt in ("-m", "--mds"):
|
|
151
|
+
options["mds_dir"] = arg
|
|
152
|
+
elif opt in ("-o", "--out"):
|
|
153
|
+
options["output_file"] = arg
|
|
154
|
+
else:
|
|
155
|
+
raise RuntimeError("不支持的选项: {}".format(opt))
|
|
156
|
+
|
|
157
|
+
IntfPool(project_name, mdb_path, options.get("mds_dir")).save_output(options.get("output_file"))
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
if __name__ == "__main__":
|
|
161
|
+
main(sys.argv[1:])
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# coding=utf-8
|
|
3
|
+
# Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
4
|
+
# openUBMC is licensed under Mulan PSL v2.
|
|
5
|
+
# You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
6
|
+
# You may obtain a copy of Mulan PSL v2 at:
|
|
7
|
+
# http://license.coscl.org.cn/MulanPSL2
|
|
8
|
+
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
|
9
|
+
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
|
10
|
+
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
|
11
|
+
# See the Mulan PSL v2 for more details.
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# coding=utf-8
|
|
3
|
+
# Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
4
|
+
# openUBMC is licensed under Mulan PSL v2.
|
|
5
|
+
# You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
6
|
+
# You may obtain a copy of Mulan PSL v2 at:
|
|
7
|
+
# http://license.coscl.org.cn/MulanPSL2
|
|
8
|
+
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
|
9
|
+
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
|
10
|
+
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
|
11
|
+
# See the Mulan PSL v2 for more details.
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class MessageParseException(Exception):
|
|
15
|
+
pass
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class UrlParseException(Exception):
|
|
19
|
+
pass
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class JsonTypeException(Exception):
|
|
23
|
+
@staticmethod
|
|
24
|
+
def check_dict(data):
|
|
25
|
+
if not isinstance(data, dict):
|
|
26
|
+
raise JsonTypeException(f"需要一个 dict 类型, 但是 '{data}' 类型为 '{type(data)}'")
|
|
27
|
+
|
|
28
|
+
@staticmethod
|
|
29
|
+
def check_list(data):
|
|
30
|
+
if not isinstance(data, list):
|
|
31
|
+
raise JsonTypeException(f"需要一个 list 类型, 但是 '{data}' 类型为 '{type(data)}'")
|
|
32
|
+
|
|
33
|
+
@staticmethod
|
|
34
|
+
def check_string(data: dict, attr_name):
|
|
35
|
+
JsonTypeException.check_dict(data)
|
|
36
|
+
if not isinstance(data.get(attr_name), (str, bytes)):
|
|
37
|
+
raise JsonTypeException(f"需要一个 string 类型, 但是 '{attr_name}' 类型为 '{type(data.get(attr_name))}'")
|
|
38
|
+
|
|
39
|
+
@staticmethod
|
|
40
|
+
def check_integer(data: dict, attr_name):
|
|
41
|
+
JsonTypeException.check_dict(data)
|
|
42
|
+
if not isinstance(data.get(attr_name), (int, bool)):
|
|
43
|
+
raise JsonTypeException(f"需要一个 integer 类型, 但是 '{attr_name}' 类型为 '{type(data.get(attr_name))}'")
|
|
44
|
+
|
|
45
|
+
@staticmethod
|
|
46
|
+
def check_float(data: dict, attr_name):
|
|
47
|
+
JsonTypeException.check_dict(data)
|
|
48
|
+
if not isinstance(data.get(attr_name), (int, bool, float)):
|
|
49
|
+
raise JsonTypeException(f"需要一个 float 类型, 但是 '{attr_name}' 类型为 '{type(data.get(attr_name))}'")
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class UrlNotMatchException(Exception):
|
|
53
|
+
pass
|