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,487 @@
|
|
|
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 mds_util as utils
|
|
20
|
+
from utils import Utils
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
PROPERTY_FLAGS = {
|
|
24
|
+
'emitsChangedSignal': {
|
|
25
|
+
'true': 'EMIT_CHANGE',
|
|
26
|
+
'const': 'CONST',
|
|
27
|
+
'invalidates': 'EMIT_NO_VALUE',
|
|
28
|
+
'false': ''
|
|
29
|
+
},
|
|
30
|
+
'explicit': {
|
|
31
|
+
True: 'EXPLICIT',
|
|
32
|
+
False: ''
|
|
33
|
+
},
|
|
34
|
+
'deprecated': {
|
|
35
|
+
True: 'DEPRECATED',
|
|
36
|
+
False: ''
|
|
37
|
+
},
|
|
38
|
+
'volatile': {
|
|
39
|
+
True: 'VOLATILE',
|
|
40
|
+
False: ''
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
OPTIONS = 'options'
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def is_struct(prop_data):
|
|
47
|
+
if 'baseType' not in prop_data:
|
|
48
|
+
return True
|
|
49
|
+
elif prop_data['baseType'] == "Enum":
|
|
50
|
+
return False
|
|
51
|
+
elif prop_data['baseType'] == "Array" and 'baseType' in prop_data["items"] and \
|
|
52
|
+
prop_data["items"]['baseType'] == "Enum":
|
|
53
|
+
return False
|
|
54
|
+
else:
|
|
55
|
+
return True
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def get_message(msg_name, msg_data, msg_pack, imports):
|
|
59
|
+
has_struct = False
|
|
60
|
+
depends = []
|
|
61
|
+
message = {}
|
|
62
|
+
message_type = utils.get_message_type(msg_data)
|
|
63
|
+
if message_type == 'struct':
|
|
64
|
+
message = utils.get_struct_message(msg_pack, msg_name, msg_data)
|
|
65
|
+
elif message_type == 'enum':
|
|
66
|
+
message = utils.get_enum_message(msg_pack, msg_name, msg_data)
|
|
67
|
+
return message, depends
|
|
68
|
+
else:
|
|
69
|
+
message = utils.get_dict_message(msg_pack, msg_name, msg_data)
|
|
70
|
+
|
|
71
|
+
imports[msg_pack] = imports.get(msg_pack, set())
|
|
72
|
+
for prop in message.get("properties", []):
|
|
73
|
+
if prop["type"] in utils.ALLOW_BASIC_TYPES.values():
|
|
74
|
+
continue
|
|
75
|
+
if prop["type"].startswith("def_types."):
|
|
76
|
+
imports[msg_pack].add("def_types.proto")
|
|
77
|
+
prop["type"] = prop["type"].replace("defs_", "")
|
|
78
|
+
elif ".defs_" in prop["type"]:
|
|
79
|
+
imports[msg_pack].add(f'../json_types/{prop["type"].split(".")[0]}.proto')
|
|
80
|
+
prop["type"] = prop["type"].replace("defs_", "")
|
|
81
|
+
else:
|
|
82
|
+
prop["type"] = prop["type"].replace("defs.", msg_pack + ".")
|
|
83
|
+
depends.append(prop["type"])
|
|
84
|
+
if message_type == 'dict':
|
|
85
|
+
prop["is_struct"] = True
|
|
86
|
+
has_struct = is_struct(msg_data[prop['original_name']])
|
|
87
|
+
if "options" in message:
|
|
88
|
+
message["options"]["has_struct"] = has_struct
|
|
89
|
+
|
|
90
|
+
return message, depends
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def save_model_msg(intfs, out_dir, extra_imports):
|
|
94
|
+
for pkg_name, pkg_data in intfs.items():
|
|
95
|
+
if "defs" == pkg_name:
|
|
96
|
+
continue
|
|
97
|
+
file_name = pkg_name[1:] + ".proto"
|
|
98
|
+
imports = [
|
|
99
|
+
"google/protobuf/descriptor.proto",
|
|
100
|
+
"ipmi_types.proto",
|
|
101
|
+
"types.proto"
|
|
102
|
+
]
|
|
103
|
+
dependency = ["types.proto"]
|
|
104
|
+
if pkg_name in extra_imports:
|
|
105
|
+
imports.extend(extra_imports[pkg_name])
|
|
106
|
+
dependency.extend(extra_imports[pkg_name])
|
|
107
|
+
datas = {
|
|
108
|
+
"imports": imports,
|
|
109
|
+
"dependency": dependency,
|
|
110
|
+
"data": pkg_data["messages"],
|
|
111
|
+
"package": pkg_name,
|
|
112
|
+
"options": {},
|
|
113
|
+
"filename": file_name,
|
|
114
|
+
"require_path": "class.types." + pkg_name[1:]
|
|
115
|
+
}
|
|
116
|
+
utils.save_proto_json(out_dir + "/" + pkg_name[1:] + ".proto.json", datas)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def save_types_msg(intfs, out_dir, extra_imports):
|
|
120
|
+
for pkg_name, pkg_data in intfs.items():
|
|
121
|
+
if "defs" == pkg_name:
|
|
122
|
+
continue
|
|
123
|
+
file_name = pkg_name + ".proto"
|
|
124
|
+
imports = [
|
|
125
|
+
"google/protobuf/descriptor.proto",
|
|
126
|
+
"ipmi_types.proto",
|
|
127
|
+
"types.proto"
|
|
128
|
+
]
|
|
129
|
+
dependency = ["types.proto"]
|
|
130
|
+
if pkg_name in extra_imports:
|
|
131
|
+
imports.extend(extra_imports[pkg_name])
|
|
132
|
+
dependency.extend(extra_imports[pkg_name])
|
|
133
|
+
datas = {
|
|
134
|
+
"imports": imports,
|
|
135
|
+
"dependency": dependency,
|
|
136
|
+
"data": pkg_data["messages"],
|
|
137
|
+
"package": pkg_name,
|
|
138
|
+
"options": {},
|
|
139
|
+
"filename": file_name,
|
|
140
|
+
"require_path": "class.types.types"
|
|
141
|
+
}
|
|
142
|
+
utils.save_proto_json(out_dir + "/" + pkg_name + ".proto.json", datas)
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def save_msg(intfs, out_dir, project_name):
|
|
146
|
+
for pkg_name, pkg_data in intfs.items():
|
|
147
|
+
if "defs" == pkg_name:
|
|
148
|
+
continue
|
|
149
|
+
file_name = pkg_name + ".proto"
|
|
150
|
+
imports = ["types.proto"]
|
|
151
|
+
require_dir = "device_types" if ("intf" in pkg_data and
|
|
152
|
+
pkg_data["intf"].startswith('bmc.dev.')) else "json_types"
|
|
153
|
+
new_out_dir = os.path.join(out_dir, '../device_types') if ("intf" in pkg_data
|
|
154
|
+
and pkg_data["intf"].startswith('bmc.dev.')) else out_dir
|
|
155
|
+
if not os.path.exists(new_out_dir):
|
|
156
|
+
os.mkdir(new_out_dir)
|
|
157
|
+
|
|
158
|
+
datas = {
|
|
159
|
+
"imports": [
|
|
160
|
+
"google/protobuf/descriptor.proto",
|
|
161
|
+
"ipmi_types.proto",
|
|
162
|
+
"types.proto"
|
|
163
|
+
],
|
|
164
|
+
"dependency": imports,
|
|
165
|
+
"data": pkg_data["messages"],
|
|
166
|
+
"package": pkg_name,
|
|
167
|
+
"options": {},
|
|
168
|
+
"filename": file_name,
|
|
169
|
+
"require_path": f"{project_name}.{require_dir}.{pkg_name}",
|
|
170
|
+
"intf": pkg_data["data"] if "data" in pkg_data else {},
|
|
171
|
+
}
|
|
172
|
+
utils.save_proto_json(f"{new_out_dir}/{file_name}.json", datas)
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def check_duplicate_msg(messages, method_name):
|
|
176
|
+
for method in messages:
|
|
177
|
+
if method["name"] == method_name:
|
|
178
|
+
return True
|
|
179
|
+
return False
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def get_req(method_data):
|
|
183
|
+
if "req" in method_data:
|
|
184
|
+
return method_data["req"]
|
|
185
|
+
if "arg_in" in method_data:
|
|
186
|
+
return method_data["arg_in"]
|
|
187
|
+
return {}
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
def get_rsp(method_data):
|
|
191
|
+
if "rsp" in method_data:
|
|
192
|
+
return method_data["rsp"]
|
|
193
|
+
if "arg_out" in method_data:
|
|
194
|
+
return method_data["arg_out"]
|
|
195
|
+
return {}
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def get_depend_message_pos(depend, old_messages):
|
|
199
|
+
index = 1
|
|
200
|
+
for var in old_messages:
|
|
201
|
+
if (var["package"] + "." + var["name"]) == depend:
|
|
202
|
+
return index
|
|
203
|
+
index = index + 1
|
|
204
|
+
|
|
205
|
+
return -1
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
# 由于当前模板的限制,依赖必须是顺序的,因此要计算插入的位置
|
|
209
|
+
def update_package(package, msg_name, struct_data, msg_package, imports):
|
|
210
|
+
new_message, depends = get_message(
|
|
211
|
+
msg_name, struct_data, msg_package, imports)
|
|
212
|
+
last_pos = 0
|
|
213
|
+
for depend in depends:
|
|
214
|
+
pos = get_depend_message_pos(depend, package["messages"])
|
|
215
|
+
if pos != -1:
|
|
216
|
+
last_pos = max(last_pos, pos)
|
|
217
|
+
|
|
218
|
+
package["messages"].insert(last_pos, new_message)
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
# 为结构体生成message
|
|
222
|
+
def gen_defs(defs, msg_package, packages, imports=None):
|
|
223
|
+
if imports is None:
|
|
224
|
+
imports = {}
|
|
225
|
+
|
|
226
|
+
if msg_package not in packages:
|
|
227
|
+
packages[msg_package] = {"messages": []}
|
|
228
|
+
|
|
229
|
+
package = packages[msg_package]
|
|
230
|
+
for struct_name, struct_data in defs.items():
|
|
231
|
+
msg_name = struct_name
|
|
232
|
+
if not check_duplicate_msg(package["messages"], msg_name):
|
|
233
|
+
update_package(package, msg_name, struct_data, msg_package, imports)
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
def validate_property_options(intf, property_name: str, key, value):
|
|
237
|
+
values_map = PROPERTY_FLAGS.get(key)
|
|
238
|
+
if values_map is None:
|
|
239
|
+
return False, f'mdb_interface中接口{intf}属性{property_name}配置了无效的options字段{key}。'\
|
|
240
|
+
f'可选字段为{", ".join(PROPERTY_FLAGS.keys())}。'
|
|
241
|
+
flag = values_map.get(value)
|
|
242
|
+
if flag is not None:
|
|
243
|
+
return True, flag
|
|
244
|
+
expected_type = "布尔类型"
|
|
245
|
+
expected_values = map(lambda v: str(v).lower(), values_map.keys())
|
|
246
|
+
if key == "emitsChangedSignal":
|
|
247
|
+
expected_type = "字符串类型"
|
|
248
|
+
expected_values = map(lambda v: f'"{v}"', expected_values)
|
|
249
|
+
error_msg = f'mdb_interface中接口{intf}属性{property_name}配置了无效的options值"{key}": {json.dumps(value)}。'\
|
|
250
|
+
f'\"{key}\"字段取值类型必须是{expected_type},取值范围是{", ".join(expected_values)}。'
|
|
251
|
+
return False, error_msg
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
def convert_property_options(intf, property_name: str, options_data: dict):
|
|
255
|
+
flags = []
|
|
256
|
+
for k, v in options_data.items():
|
|
257
|
+
ok, result = validate_property_options(intf, property_name, k, v)
|
|
258
|
+
if not ok:
|
|
259
|
+
raise RuntimeError(result)
|
|
260
|
+
if result:
|
|
261
|
+
flags.append(result)
|
|
262
|
+
# emitsChangedSignal默认为true
|
|
263
|
+
if "emitsChangedSignal" not in options_data:
|
|
264
|
+
flags.append(PROPERTY_FLAGS.get("emitsChangedSignal").get("true"))
|
|
265
|
+
return flags
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
def generate_message(intf_data, intf, packages, imports):
|
|
269
|
+
msg_package = Utils.get_unique_intf_name(intf)
|
|
270
|
+
|
|
271
|
+
if msg_package not in packages:
|
|
272
|
+
packages[msg_package] = {"messages": [], "depends": [], "data": {}, "intf": intf}
|
|
273
|
+
package = packages[msg_package]
|
|
274
|
+
package["data"] = {"name": intf, "data": intf_data}
|
|
275
|
+
|
|
276
|
+
if "methods" in intf_data:
|
|
277
|
+
for method_name, method_data in intf_data["methods"].items():
|
|
278
|
+
req_name = method_name + "Req"
|
|
279
|
+
rsp_name = method_name + "Rsp"
|
|
280
|
+
if not check_duplicate_msg(package["messages"], req_name):
|
|
281
|
+
update_package(package, req_name, get_req(
|
|
282
|
+
method_data), msg_package, imports)
|
|
283
|
+
|
|
284
|
+
if not check_duplicate_msg(package["messages"], rsp_name):
|
|
285
|
+
update_package(package, rsp_name, get_rsp(
|
|
286
|
+
method_data), msg_package, imports)
|
|
287
|
+
|
|
288
|
+
if "signals" in intf_data:
|
|
289
|
+
for signal_name, signal_data in intf_data["signals"].items():
|
|
290
|
+
signature_name = signal_name + "Signature"
|
|
291
|
+
if not check_duplicate_msg(package["messages"], signature_name):
|
|
292
|
+
update_package(package, signature_name,
|
|
293
|
+
signal_data, msg_package, imports)
|
|
294
|
+
|
|
295
|
+
if "properties" in intf_data:
|
|
296
|
+
for property_name, property_data in intf_data["properties"].items():
|
|
297
|
+
if not check_duplicate_msg(package["messages"], property_name):
|
|
298
|
+
update_package(package, property_name,
|
|
299
|
+
{property_name: property_data}, msg_package, imports)
|
|
300
|
+
if OPTIONS in property_data:
|
|
301
|
+
property_data[OPTIONS] = convert_property_options(intf, property_name, property_data[OPTIONS])
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
def prepare_virutal(intf_data):
|
|
305
|
+
if "virtual" in intf_data:
|
|
306
|
+
intf_data["properties"]["priority"] = {
|
|
307
|
+
"baseType": "U8",
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
def prepare_intf_data(intf_data, intf):
|
|
312
|
+
if "defs" in intf_data:
|
|
313
|
+
intf_data[intf]["defs"] = intf_data["defs"]
|
|
314
|
+
prepare_virutal(intf_data)
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
def generate_default_message(default_intf_name, mdb_path, messages):
|
|
318
|
+
intf_json = utils.get_intf(default_intf_name, mdb_path)
|
|
319
|
+
imports = {}
|
|
320
|
+
if "implement" in intf_json[default_intf_name]:
|
|
321
|
+
intf_json = utils.generate_default(intf_json, mdb_path)
|
|
322
|
+
generate_message(intf_json[default_intf_name],
|
|
323
|
+
default_intf_name, messages, imports)
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
def gen_dev_intf(intf, output, project_name):
|
|
327
|
+
messages = {}
|
|
328
|
+
intf_name = ''
|
|
329
|
+
for key in intf.keys():
|
|
330
|
+
if key != 'defs':
|
|
331
|
+
intf_name = key
|
|
332
|
+
gen_client_msg_intf(intf, intf_name, messages)
|
|
333
|
+
save_msg(messages, output, project_name)
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
def gen_dev_intfs(mdb_path, output, project_name):
|
|
337
|
+
file_list = Utils.get_files(os.path.join(mdb_path, "intf/mdb/bmc/dev"))
|
|
338
|
+
for file in file_list:
|
|
339
|
+
with os.fdopen(os.open(file, os.O_RDONLY, stat.S_IRUSR), "r") as intf_file:
|
|
340
|
+
gen_dev_intf(json.load(intf_file), output, project_name)
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
def get_service_messages(mdb_path, classes, messages, imports):
|
|
344
|
+
for _, class_data in classes.items():
|
|
345
|
+
if "interfaces" not in class_data:
|
|
346
|
+
continue
|
|
347
|
+
for intf_name, intf_data in class_data["interfaces"].items():
|
|
348
|
+
if "defs" in intf_data:
|
|
349
|
+
gen_defs(
|
|
350
|
+
intf_data["defs"], Utils.get_unique_intf_name(
|
|
351
|
+
intf_name), messages
|
|
352
|
+
)
|
|
353
|
+
prepare_virutal(intf_data)
|
|
354
|
+
generate_message(intf_data, intf_name, messages, imports)
|
|
355
|
+
|
|
356
|
+
if "default" in intf_data:
|
|
357
|
+
generate_default_message(
|
|
358
|
+
intf_data["default"], mdb_path, messages)
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
def gen_service_msg(model_merged_file, of_name, mdb_path, project_name):
|
|
362
|
+
load_f = utils.open_file(model_merged_file)
|
|
363
|
+
load_dict = json.load(load_f)
|
|
364
|
+
|
|
365
|
+
messages = {}
|
|
366
|
+
imports = {}
|
|
367
|
+
get_service_messages(mdb_path, load_dict, messages, imports)
|
|
368
|
+
save_msg(messages, of_name, project_name)
|
|
369
|
+
load_f.close()
|
|
370
|
+
|
|
371
|
+
if project_name == 'hwproxy':
|
|
372
|
+
gen_dev_intfs(mdb_path, of_name, project_name)
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
def gen_model_msg(model_merged_file, of_name):
|
|
376
|
+
load_f = utils.open_file(model_merged_file)
|
|
377
|
+
load_dict = json.load(load_f)
|
|
378
|
+
messages = {}
|
|
379
|
+
imports = {}
|
|
380
|
+
for class_name, class_data in load_dict.items():
|
|
381
|
+
class_name = "M" + class_name
|
|
382
|
+
if "defs" in class_data:
|
|
383
|
+
gen_defs(class_data["defs"], class_name, messages)
|
|
384
|
+
generate_message(class_data, class_name, messages, imports)
|
|
385
|
+
|
|
386
|
+
save_model_msg(messages, of_name, imports)
|
|
387
|
+
load_f.close()
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
def gen_client_msg_intf(intf_json, intf, messages):
|
|
391
|
+
imports = {}
|
|
392
|
+
for intf_name, intf_data in intf_json.items():
|
|
393
|
+
if intf_name == "defs":
|
|
394
|
+
gen_defs(intf_data, Utils.get_unique_intf_name(intf), messages)
|
|
395
|
+
else:
|
|
396
|
+
prepare_intf_data(intf_json, intf_name)
|
|
397
|
+
prepare_virutal(intf_data)
|
|
398
|
+
generate_message(intf_data, intf_name, messages, imports)
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
def gen_client_msg(service_file, output, mdb_path, project_name):
|
|
402
|
+
load_f = utils.open_file(service_file)
|
|
403
|
+
service_json = json.load(load_f)
|
|
404
|
+
|
|
405
|
+
if "required" not in service_json:
|
|
406
|
+
load_f.close()
|
|
407
|
+
return
|
|
408
|
+
|
|
409
|
+
messages = {}
|
|
410
|
+
for required in service_json["required"]:
|
|
411
|
+
intf = required["interface"]
|
|
412
|
+
intf_json = utils.get_intf(intf, mdb_path)
|
|
413
|
+
if "implement" in intf_json[intf]:
|
|
414
|
+
intf_json = utils.generate_default(intf_json, mdb_path)
|
|
415
|
+
gen_client_msg_intf(intf_json, intf, messages)
|
|
416
|
+
|
|
417
|
+
save_msg(messages, output, project_name)
|
|
418
|
+
load_f.close()
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
def gen_types_msg(types_file, of_name):
|
|
422
|
+
load_f = utils.open_file(types_file)
|
|
423
|
+
load_dict = json.load(load_f)
|
|
424
|
+
messages = {}
|
|
425
|
+
imports = {}
|
|
426
|
+
if "defs" in load_dict:
|
|
427
|
+
gen_defs(load_dict["defs"], "def_types", messages, imports)
|
|
428
|
+
generate_message(load_dict, "def_types", messages, imports)
|
|
429
|
+
|
|
430
|
+
save_types_msg(messages, of_name, imports)
|
|
431
|
+
load_f.close()
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
def usage():
|
|
435
|
+
logging.info(
|
|
436
|
+
"gen_rpc_msg_json.py -i <inputfile> -d<mdb_path> -o<outputfile> -x <client_msg> -m<service_msg>"
|
|
437
|
+
)
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
def main(argv):
|
|
441
|
+
m_input = ""
|
|
442
|
+
output = ""
|
|
443
|
+
mdb_path = ""
|
|
444
|
+
project_name = ""
|
|
445
|
+
try:
|
|
446
|
+
opts, _ = getopt.getopt(
|
|
447
|
+
argv,
|
|
448
|
+
"hi:o:d:n:mcxpt",
|
|
449
|
+
["help", "input=", "out=", "message", "project_name=",
|
|
450
|
+
"client", "client_msg", "model_message", "types_message"],
|
|
451
|
+
)
|
|
452
|
+
except getopt.GetoptError:
|
|
453
|
+
help()
|
|
454
|
+
return
|
|
455
|
+
for opt, arg in opts:
|
|
456
|
+
if opt in ("-h", "--help"):
|
|
457
|
+
usage()
|
|
458
|
+
return
|
|
459
|
+
elif opt in ("-i", "--input"):
|
|
460
|
+
m_input = arg
|
|
461
|
+
elif opt in ("-o", "--out"):
|
|
462
|
+
output = arg
|
|
463
|
+
elif opt in ("-d", "--dir"):
|
|
464
|
+
mdb_path = arg
|
|
465
|
+
elif opt in ("-n", "--project_name"):
|
|
466
|
+
project_name = arg
|
|
467
|
+
elif opt in ("-m", "--message"):
|
|
468
|
+
gen_service_msg(m_input, output, mdb_path, project_name)
|
|
469
|
+
return
|
|
470
|
+
elif opt in ("-p", "--model_message"):
|
|
471
|
+
gen_model_msg(m_input, output)
|
|
472
|
+
return
|
|
473
|
+
elif opt in ("-x", "--client_message"):
|
|
474
|
+
gen_client_msg(m_input, output, mdb_path, project_name)
|
|
475
|
+
return
|
|
476
|
+
elif opt in ("-t", "--types_message"):
|
|
477
|
+
gen_types_msg(m_input, output)
|
|
478
|
+
return
|
|
479
|
+
else:
|
|
480
|
+
raise RuntimeError("不支持的选项: {}".format(opt))
|
|
481
|
+
if not m_input or not output:
|
|
482
|
+
usage()
|
|
483
|
+
return
|
|
484
|
+
|
|
485
|
+
|
|
486
|
+
if __name__ == "__main__":
|
|
487
|
+
main(sys.argv[1:])
|