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,302 @@
|
|
|
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 re
|
|
20
|
+
from collections import defaultdict
|
|
21
|
+
from utils import Utils
|
|
22
|
+
from bmcgo.utils.tools import Tools
|
|
23
|
+
|
|
24
|
+
tool = Tools()
|
|
25
|
+
log = tool.log
|
|
26
|
+
MDS_REF = "$ref"
|
|
27
|
+
MDS_DEFS = "defs"
|
|
28
|
+
MDS_REF_INTERFACE = "refInterface"
|
|
29
|
+
MDS_PATH = "path"
|
|
30
|
+
MDS_PARENT = "parent"
|
|
31
|
+
MDS_STRUCT = "structs"
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def no_need_filter(k):
|
|
35
|
+
filter_list = ["usage", "notAllowNull", "readOnly", "default", "primaryKey", "critical"]
|
|
36
|
+
return k not in filter_list
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def is_excluded_intf(intf):
|
|
40
|
+
return intf == "bmc.kepler.Object.Properties"
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def is_usage_csr(property_data):
|
|
44
|
+
return "usage" in property_data and "CSR" in property_data["usage"]
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def update_type(property_data):
|
|
48
|
+
new_property_data = {}
|
|
49
|
+
if not isinstance(property_data, dict):
|
|
50
|
+
return new_property_data
|
|
51
|
+
if "description" in property_data and Utils.get_lua_codegen_version() >= 13:
|
|
52
|
+
property_data.pop("description", "")
|
|
53
|
+
if "baseType" in property_data:
|
|
54
|
+
base_type = property_data.pop("baseType", "")
|
|
55
|
+
if base_type == "Array":
|
|
56
|
+
new_property_data = property_data.copy()
|
|
57
|
+
new_property_data["type"] = "array"
|
|
58
|
+
try:
|
|
59
|
+
new_property_data["items"][MDS_REF] = new_property_data["items"][MDS_REF].replace(MDS_DEFS, MDS_STRUCT)
|
|
60
|
+
except Exception as e:
|
|
61
|
+
log.error(f"任务状态错误: {e}")
|
|
62
|
+
raise Exception(f"未找到{MDS_REF}") from e
|
|
63
|
+
return new_property_data
|
|
64
|
+
|
|
65
|
+
if MDS_REF_INTERFACE in property_data:
|
|
66
|
+
new_property_data[MDS_REF_INTERFACE] = property_data.pop(MDS_REF_INTERFACE, "")
|
|
67
|
+
types = []
|
|
68
|
+
types.append({MDS_REF: "base.json#/" + base_type})
|
|
69
|
+
if property_data:
|
|
70
|
+
types.append(property_data.copy())
|
|
71
|
+
new_property_data["allOf"] = types.copy()
|
|
72
|
+
if MDS_REF in property_data:
|
|
73
|
+
new_property_data[MDS_REF] = property_data[MDS_REF].replace(MDS_DEFS, MDS_STRUCT)
|
|
74
|
+
|
|
75
|
+
return new_property_data
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def read_properties(properties, out_properties, is_intf_props):
|
|
79
|
+
# properties only mark usage as C should deploy to csr schema
|
|
80
|
+
props = list(p for p, v in properties.items() if is_intf_props or is_usage_csr(v))
|
|
81
|
+
for index, prop in enumerate(props):
|
|
82
|
+
# filter properties which no need for csr
|
|
83
|
+
prop_alias = prop
|
|
84
|
+
if not is_usage_csr(properties[prop]):
|
|
85
|
+
continue
|
|
86
|
+
# if prop have alias, use alias name replace prop name
|
|
87
|
+
if "alias" in properties[prop] and Utils.get_lua_codegen_version() >= 13:
|
|
88
|
+
prop_alias = properties[prop].pop("alias", "")
|
|
89
|
+
properties[prop]["title"] = prop
|
|
90
|
+
out_properties[prop_alias] = {
|
|
91
|
+
k: v
|
|
92
|
+
for k, v in properties[prop].items()
|
|
93
|
+
if no_need_filter(k)
|
|
94
|
+
}
|
|
95
|
+
if prop_alias != prop and Utils.get_lua_codegen_version() >= 13:
|
|
96
|
+
out_properties[prop_alias] = update_type(out_properties[prop_alias])
|
|
97
|
+
props[index] = prop_alias
|
|
98
|
+
else:
|
|
99
|
+
out_properties[prop] = update_type(out_properties[prop])
|
|
100
|
+
return props
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def read_defs(structs, data):
|
|
104
|
+
for struct_name, struct_data in data[MDS_DEFS].items():
|
|
105
|
+
properties = {k: v for k, v in struct_data.items()}
|
|
106
|
+
for prop, prop_data in properties.items():
|
|
107
|
+
properties[prop] = update_type(prop_data).copy()
|
|
108
|
+
structs[struct_name] = {"type": "object", "properties": properties}
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def get_duplicated_props(class_name, class_props):
|
|
112
|
+
props_by_name = defaultdict(list)
|
|
113
|
+
for props, intf_name in class_props:
|
|
114
|
+
for prop_name, prop_data in props.items():
|
|
115
|
+
if intf_name is None or not is_usage_csr(prop_data):
|
|
116
|
+
continue
|
|
117
|
+
props_by_name[prop_name].append(intf_name)
|
|
118
|
+
duplicated_props = list()
|
|
119
|
+
for prop_name, intf_names in props_by_name.items():
|
|
120
|
+
if len(intf_names) > 1:
|
|
121
|
+
duplicated_props.append(prop_name)
|
|
122
|
+
log.error("类%s下不同接口%s配置了同名属性%s并且都配置了CSR,不生成到schema.json中",
|
|
123
|
+
class_name, ', '.join(intf_names), prop_name)
|
|
124
|
+
return duplicated_props
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def remove_duplicate_props(class_name, class_data):
|
|
128
|
+
class_props = [(class_data.get("properties", {}), None)] # 元组第2个元素表示资源树接口,None为私有属性
|
|
129
|
+
for intf_name, intf_data in class_data.get("interfaces", {}).items():
|
|
130
|
+
if is_excluded_intf(intf_name):
|
|
131
|
+
continue
|
|
132
|
+
class_props.append((intf_data.get("properties", {}), intf_name))
|
|
133
|
+
|
|
134
|
+
duplicated_props = get_duplicated_props(class_name, class_props)
|
|
135
|
+
for props, _ in class_props:
|
|
136
|
+
for prop_name in duplicated_props:
|
|
137
|
+
if prop_name in props:
|
|
138
|
+
del props[prop_name]
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def read_interfaces(interfaces, out_properties, structs):
|
|
142
|
+
intfs = {}
|
|
143
|
+
for intf_name, intf in interfaces.items():
|
|
144
|
+
# no properties also need interface name , because may be reference Object by other property for Devkit check
|
|
145
|
+
intfs[intf_name] = {}
|
|
146
|
+
if "properties" in intf:
|
|
147
|
+
props = read_properties(intf["properties"], out_properties, not is_excluded_intf(intf_name))
|
|
148
|
+
intfs[intf_name] = props
|
|
149
|
+
if MDS_DEFS in intf:
|
|
150
|
+
read_defs(structs, intf)
|
|
151
|
+
return intfs
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def save_csr_schema(of_name, csr_schema):
|
|
155
|
+
if os.path.exists(of_name):
|
|
156
|
+
with os.fdopen(os.open(of_name, os.O_RDONLY, stat.S_IRUSR), "r") as load_f:
|
|
157
|
+
if json.load(load_f) == csr_schema:
|
|
158
|
+
logging.info("schema 文件内容没有变更")
|
|
159
|
+
return
|
|
160
|
+
|
|
161
|
+
with os.fdopen(
|
|
162
|
+
os.open(
|
|
163
|
+
of_name, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, stat.S_IWUSR | stat.S_IRUSR
|
|
164
|
+
),
|
|
165
|
+
"w",
|
|
166
|
+
) as load_f:
|
|
167
|
+
json.dump(csr_schema, load_f, indent=4)
|
|
168
|
+
logging.info("schema 已经发生改变")
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
csr_schema_template = {
|
|
172
|
+
MDS_DEFS: {},
|
|
173
|
+
"id": "bmc",
|
|
174
|
+
"type": "object",
|
|
175
|
+
"patternProperties": {},
|
|
176
|
+
"$schema": "https://json-schema.org/draft/2019-09/schema#",
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
def replace_colon(path):
|
|
181
|
+
path = os.path.realpath(path) if (path[0:1] == "/") else path
|
|
182
|
+
paths = path.split("/")
|
|
183
|
+
maps = {}
|
|
184
|
+
for var in paths:
|
|
185
|
+
if var.startswith(":"):
|
|
186
|
+
maps[var] = var.replace(":", "${") + "}"
|
|
187
|
+
for old, new in maps.items():
|
|
188
|
+
path = path.replace(old, new)
|
|
189
|
+
return path
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def create_schema_class(interfaces, properties, class_data):
|
|
193
|
+
class_def = {"properties": properties, "type": "object", "interfaces": interfaces}
|
|
194
|
+
if MDS_PATH in class_data:
|
|
195
|
+
class_def[MDS_PATH] = replace_colon(class_data[MDS_PATH])
|
|
196
|
+
if MDS_PARENT in class_data:
|
|
197
|
+
class_def[MDS_PARENT] = class_data[MDS_PARENT]
|
|
198
|
+
class_def["additionalProperties"] = False
|
|
199
|
+
return class_def
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def count_dir_level(path):
|
|
203
|
+
level = 0
|
|
204
|
+
while True:
|
|
205
|
+
path = os.path.dirname(path)
|
|
206
|
+
if path == '/':
|
|
207
|
+
break
|
|
208
|
+
level += 1
|
|
209
|
+
return level
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
def filling_material(load_dict, csr_schema):
|
|
213
|
+
for class_name, class_data in load_dict.items():
|
|
214
|
+
if Utils.get_lua_codegen_version() < 13:
|
|
215
|
+
remove_duplicate_props(class_name, class_data)
|
|
216
|
+
properties = {}
|
|
217
|
+
interfaces = {}
|
|
218
|
+
if "interfaces" in class_data:
|
|
219
|
+
interfaces = read_interfaces(
|
|
220
|
+
class_data["interfaces"], properties, csr_schema[MDS_STRUCT]
|
|
221
|
+
)
|
|
222
|
+
if "properties" in class_data:
|
|
223
|
+
_ = read_properties(class_data["properties"], properties, False)
|
|
224
|
+
if MDS_DEFS in class_data:
|
|
225
|
+
read_defs(csr_schema[MDS_STRUCT], class_data)
|
|
226
|
+
# no properties means no properties mark usage C ,no need generic csr schema class
|
|
227
|
+
if properties:
|
|
228
|
+
csr_schema[MDS_DEFS][class_name] = create_schema_class(
|
|
229
|
+
interfaces, properties, class_data
|
|
230
|
+
)
|
|
231
|
+
csr_schema["patternProperties"]["^" + class_name + "_"] = {
|
|
232
|
+
MDS_REF: "#/defs/" + class_name
|
|
233
|
+
}
|
|
234
|
+
if MDS_DEFS in load_dict:
|
|
235
|
+
read_defs(csr_schema[MDS_STRUCT], load_dict)
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
def generate(if_name, of_name, project_name):
|
|
239
|
+
if not os.path.exists(if_name):
|
|
240
|
+
return
|
|
241
|
+
|
|
242
|
+
# APP的目录层级是3,组件层级是4
|
|
243
|
+
pattern = re.compile(f'.*(/[^/]+/temp/{project_name}/.*)')
|
|
244
|
+
match = re.search(pattern, if_name)
|
|
245
|
+
path_level = 0
|
|
246
|
+
if match:
|
|
247
|
+
temp_model_path = match.group(1)
|
|
248
|
+
path_level = count_dir_level(temp_model_path)
|
|
249
|
+
dir_path = os.path.dirname(if_name)
|
|
250
|
+
|
|
251
|
+
if not (dir_path.endswith('test_gen_schema') or path_level == 3):
|
|
252
|
+
return
|
|
253
|
+
|
|
254
|
+
csr_schema = csr_schema_template.copy()
|
|
255
|
+
csr_schema[MDS_STRUCT] = {}
|
|
256
|
+
for root, _, files in os.walk(dir_path):
|
|
257
|
+
for file in files:
|
|
258
|
+
if file.endswith('_model.json'):
|
|
259
|
+
file_path = os.path.join(root, file)
|
|
260
|
+
load_f = os.fdopen(os.open(file_path, os.O_RDONLY, stat.S_IRUSR), "r")
|
|
261
|
+
if_name = os.path.realpath(if_name)
|
|
262
|
+
load_dict = json.load(load_f)
|
|
263
|
+
|
|
264
|
+
filling_material(load_dict, csr_schema)
|
|
265
|
+
load_f.close()
|
|
266
|
+
|
|
267
|
+
save_csr_schema(of_name, csr_schema)
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
def usage():
|
|
272
|
+
logging.info("gen_schema.py -i <inputfile> -o <outfile> -n <project_name>")
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
def main(argv):
|
|
276
|
+
m_input = ""
|
|
277
|
+
output = ""
|
|
278
|
+
try:
|
|
279
|
+
opts, _ = getopt.getopt(argv, "hi:o:n:", ["help", "input=", "out=", "project_name="])
|
|
280
|
+
except getopt.GetoptError:
|
|
281
|
+
help()
|
|
282
|
+
return
|
|
283
|
+
for opt, arg in opts:
|
|
284
|
+
if opt in ("-h", "--help"):
|
|
285
|
+
usage()
|
|
286
|
+
return
|
|
287
|
+
elif opt in ("-i", "--input"):
|
|
288
|
+
m_input = arg
|
|
289
|
+
elif opt in ("-o", "--out"):
|
|
290
|
+
output = arg
|
|
291
|
+
elif opt in ("-n", "--project_name"):
|
|
292
|
+
project_name = arg
|
|
293
|
+
else:
|
|
294
|
+
raise RuntimeError("不支持的选项: {}".format(opt))
|
|
295
|
+
if not m_input or not output:
|
|
296
|
+
usage()
|
|
297
|
+
return
|
|
298
|
+
generate(m_input, output, project_name)
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
if __name__ == "__main__":
|
|
302
|
+
main(sys.argv[1:])
|
|
@@ -0,0 +1,135 @@
|
|
|
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 sys
|
|
14
|
+
from google.protobuf import descriptor as _descriptor
|
|
15
|
+
from google.protobuf import message as _message
|
|
16
|
+
from google.protobuf import reflection as _reflection
|
|
17
|
+
from google.protobuf import symbol_database as _symbol_database
|
|
18
|
+
# @@protoc_insertion_point(imports)
|
|
19
|
+
from google.protobuf import descriptor_pb2 as google_dot_protobuf_dot_descriptor__pb2
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
_b = sys.version_info[0] < 3 and (lambda x: x) or (lambda x: x.encode("latin1"))
|
|
23
|
+
_sym_db = _symbol_database.Default()
|
|
24
|
+
|
|
25
|
+
DESCRIPTOR = _descriptor.FileDescriptor(
|
|
26
|
+
name='ipmi_types.proto',
|
|
27
|
+
package='',
|
|
28
|
+
syntax='proto3',
|
|
29
|
+
serialized_options=None,
|
|
30
|
+
serialized_pb=_b('\n\x10ipmi_types.proto\x1a google/protobuf/descriptor.proto:7\n\x0f\x64\x65\x66\x61ult_channel\
|
|
31
|
+
\x12\x1c.google.protobuf.FileOptions\x18\xd9\xaa\x04 \x01(\t:2\n\x07\x63hannel\x12\x1f.google.protobuf.MessageOptions\
|
|
32
|
+
\x18\xe9\xf8\x04 \x01(\t:1\n\x06net_fn\x12\x1f.google.protobuf.MessageOptions\x18\xea\xf8\x04 \x01(\x05:.\n\x03\x63md\
|
|
33
|
+
\x12\x1f.google.protobuf.MessageOptions\x18\xeb\xf8\x04 \x01(\x05:/\n\x04prio\x12\x1f.google.protobuf.MessageOptions\
|
|
34
|
+
\x18\xec\xf8\x04 \x01(\t:4\n\tprivilege\x12\x1f.google.protobuf.MessageOptions\x18\xed\xf8\x04 \x01(\t:1\
|
|
35
|
+
\n\x06\x64\x65\x63ode\x12\x1f.google.protobuf.MessageOptions\x18\xee\xf8\x04 \x01(\t:1\n\x06\x65ncode\x12\x1f.google.\
|
|
36
|
+
protobuf.MessageOptions\x18\xef\xf8\x04 \x01(\t:2\n\x07\x66ilters\x12\x1f.google.protobuf.MessageOptions\
|
|
37
|
+
\x18\xf0\xf8\x04 \x01(\tb\x06proto3'),
|
|
38
|
+
dependencies=[google_dot_protobuf_dot_descriptor__pb2.DESCRIPTOR, ])
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
DEFAULT_CHANNEL_FIELD_NUMBER = 71001
|
|
42
|
+
default_channel = _descriptor.FieldDescriptor(
|
|
43
|
+
name='default_channel', full_name='default_channel', index=0,
|
|
44
|
+
number=71001, type=9, cpp_type=9, label=1,
|
|
45
|
+
has_default_value=False, default_value=_b("").decode('utf-8'),
|
|
46
|
+
message_type=None, enum_type=None, containing_type=None,
|
|
47
|
+
is_extension=True, extension_scope=None,
|
|
48
|
+
serialized_options=None, file=DESCRIPTOR)
|
|
49
|
+
CHANNEL_FIELD_NUMBER = 81001
|
|
50
|
+
channel = _descriptor.FieldDescriptor(
|
|
51
|
+
name='channel', full_name='channel', index=1,
|
|
52
|
+
number=81001, type=9, cpp_type=9, label=1,
|
|
53
|
+
has_default_value=False, default_value=_b("").decode('utf-8'),
|
|
54
|
+
message_type=None, enum_type=None, containing_type=None,
|
|
55
|
+
is_extension=True, extension_scope=None,
|
|
56
|
+
serialized_options=None, file=DESCRIPTOR)
|
|
57
|
+
NET_FN_FIELD_NUMBER = 81002
|
|
58
|
+
net_fn = _descriptor.FieldDescriptor(
|
|
59
|
+
name='net_fn', full_name='net_fn', index=2,
|
|
60
|
+
number=81002, type=5, cpp_type=1, label=1,
|
|
61
|
+
has_default_value=False, default_value=0,
|
|
62
|
+
message_type=None, enum_type=None, containing_type=None,
|
|
63
|
+
is_extension=True, extension_scope=None,
|
|
64
|
+
serialized_options=None, file=DESCRIPTOR)
|
|
65
|
+
CMD_FIELD_NUMBER = 81003
|
|
66
|
+
cmd = _descriptor.FieldDescriptor(
|
|
67
|
+
name='cmd', full_name='cmd', index=3,
|
|
68
|
+
number=81003, type=5, cpp_type=1, label=1,
|
|
69
|
+
has_default_value=False, default_value=0,
|
|
70
|
+
message_type=None, enum_type=None, containing_type=None,
|
|
71
|
+
is_extension=True, extension_scope=None,
|
|
72
|
+
serialized_options=None, file=DESCRIPTOR)
|
|
73
|
+
PRIO_FIELD_NUMBER = 81004
|
|
74
|
+
prio = _descriptor.FieldDescriptor(
|
|
75
|
+
name='prio', full_name='prio', index=4,
|
|
76
|
+
number=81004, type=9, cpp_type=9, label=1,
|
|
77
|
+
has_default_value=False, default_value=_b("").decode('utf-8'),
|
|
78
|
+
message_type=None, enum_type=None, containing_type=None,
|
|
79
|
+
is_extension=True, extension_scope=None,
|
|
80
|
+
serialized_options=None, file=DESCRIPTOR)
|
|
81
|
+
PRIVILEGE_FIELD_NUMBER = 81005
|
|
82
|
+
privilege = _descriptor.FieldDescriptor(
|
|
83
|
+
name='privilege', full_name='privilege', index=5,
|
|
84
|
+
number=81005, type=9, cpp_type=9, label=1,
|
|
85
|
+
has_default_value=False, default_value=_b("").decode('utf-8'),
|
|
86
|
+
message_type=None, enum_type=None, containing_type=None,
|
|
87
|
+
is_extension=True, extension_scope=None,
|
|
88
|
+
serialized_options=None, file=DESCRIPTOR)
|
|
89
|
+
DECODE_FIELD_NUMBER = 81006
|
|
90
|
+
decode = _descriptor.FieldDescriptor(
|
|
91
|
+
name='decode', full_name='decode', index=6,
|
|
92
|
+
number=81006, type=9, cpp_type=9, label=1,
|
|
93
|
+
has_default_value=False, default_value=_b("").decode('utf-8'),
|
|
94
|
+
message_type=None, enum_type=None, containing_type=None,
|
|
95
|
+
is_extension=True, extension_scope=None,
|
|
96
|
+
serialized_options=None, file=DESCRIPTOR)
|
|
97
|
+
ENCODE_FIELD_NUMBER = 81007
|
|
98
|
+
encode = _descriptor.FieldDescriptor(
|
|
99
|
+
name='encode', full_name='encode', index=7,
|
|
100
|
+
number=81007, type=9, cpp_type=9, label=1,
|
|
101
|
+
has_default_value=False, default_value=_b("").decode('utf-8'),
|
|
102
|
+
message_type=None, enum_type=None, containing_type=None,
|
|
103
|
+
is_extension=True, extension_scope=None,
|
|
104
|
+
serialized_options=None, file=DESCRIPTOR)
|
|
105
|
+
FILTERS_FIELD_NUMBER = 81008
|
|
106
|
+
filters = _descriptor.FieldDescriptor(
|
|
107
|
+
name='filters', full_name='filters', index=8,
|
|
108
|
+
number=81008, type=9, cpp_type=9, label=1,
|
|
109
|
+
has_default_value=False, default_value=_b("").decode('utf-8'),
|
|
110
|
+
message_type=None, enum_type=None, containing_type=None,
|
|
111
|
+
is_extension=True, extension_scope=None,
|
|
112
|
+
serialized_options=None, file=DESCRIPTOR)
|
|
113
|
+
|
|
114
|
+
DESCRIPTOR.extensions_by_name['default_channel'] = default_channel
|
|
115
|
+
DESCRIPTOR.extensions_by_name['channel'] = channel
|
|
116
|
+
DESCRIPTOR.extensions_by_name['net_fn'] = net_fn
|
|
117
|
+
DESCRIPTOR.extensions_by_name['cmd'] = cmd
|
|
118
|
+
DESCRIPTOR.extensions_by_name['prio'] = prio
|
|
119
|
+
DESCRIPTOR.extensions_by_name['privilege'] = privilege
|
|
120
|
+
DESCRIPTOR.extensions_by_name['decode'] = decode
|
|
121
|
+
DESCRIPTOR.extensions_by_name['encode'] = encode
|
|
122
|
+
DESCRIPTOR.extensions_by_name['filters'] = filters
|
|
123
|
+
_sym_db.RegisterFileDescriptor(DESCRIPTOR)
|
|
124
|
+
|
|
125
|
+
google_dot_protobuf_dot_descriptor__pb2.FileOptions.RegisterExtension(default_channel)
|
|
126
|
+
google_dot_protobuf_dot_descriptor__pb2.MessageOptions.RegisterExtension(channel)
|
|
127
|
+
google_dot_protobuf_dot_descriptor__pb2.MessageOptions.RegisterExtension(net_fn)
|
|
128
|
+
google_dot_protobuf_dot_descriptor__pb2.MessageOptions.RegisterExtension(cmd)
|
|
129
|
+
google_dot_protobuf_dot_descriptor__pb2.MessageOptions.RegisterExtension(prio)
|
|
130
|
+
google_dot_protobuf_dot_descriptor__pb2.MessageOptions.RegisterExtension(privilege)
|
|
131
|
+
google_dot_protobuf_dot_descriptor__pb2.MessageOptions.RegisterExtension(decode)
|
|
132
|
+
google_dot_protobuf_dot_descriptor__pb2.MessageOptions.RegisterExtension(encode)
|
|
133
|
+
google_dot_protobuf_dot_descriptor__pb2.MessageOptions.RegisterExtension(filters)
|
|
134
|
+
|
|
135
|
+
# @@protoc_insertion_point(module_scope)
|
|
@@ -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,33 @@
|
|
|
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 os
|
|
15
|
+
from typing import List
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def load_json(file_path: str) -> dict:
|
|
19
|
+
file_path = os.path.normpath(file_path)
|
|
20
|
+
if not os.path.exists(file_path):
|
|
21
|
+
return {}
|
|
22
|
+
with open(file_path, "r", encoding="utf-8") as fd:
|
|
23
|
+
return json.loads(fd.read())
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def json_file_list(root_path: str) -> List[str]:
|
|
27
|
+
ret = []
|
|
28
|
+
for root, _, files in os.walk(root_path):
|
|
29
|
+
for file_name in files:
|
|
30
|
+
if not file_name.endswith(".json"):
|
|
31
|
+
continue
|
|
32
|
+
ret.append(os.path.join(root, file_name))
|
|
33
|
+
return ret
|
|
@@ -0,0 +1,79 @@
|
|
|
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 argparse
|
|
15
|
+
import logging
|
|
16
|
+
import os
|
|
17
|
+
import stat
|
|
18
|
+
import sys
|
|
19
|
+
|
|
20
|
+
from dto.exception import JsonTypeException
|
|
21
|
+
from dto.kepler_abstract import KeplerAbstractMgr, KeplerAbstract
|
|
22
|
+
from loader.file_utils import json_file_list, load_json
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def collect_abstract_info(file_path, abstract_mgr: KeplerAbstractMgr):
|
|
26
|
+
data = load_json(file_path)
|
|
27
|
+
if not data:
|
|
28
|
+
return
|
|
29
|
+
JsonTypeException.check_list(data.get("data"))
|
|
30
|
+
for msg in data.get("data"):
|
|
31
|
+
JsonTypeException.check_dict(msg.get("options"))
|
|
32
|
+
path = msg.get("options").get("path")
|
|
33
|
+
interface = msg.get("options").get("interface")
|
|
34
|
+
if not path and interface:
|
|
35
|
+
continue
|
|
36
|
+
abstract_mgr.add(KeplerAbstract(path, interface, file_path, msg.get("package"), msg.get("name")))
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def collect_abstract_infos(root_path: str) -> KeplerAbstractMgr:
|
|
40
|
+
abstract_mgr = KeplerAbstractMgr()
|
|
41
|
+
file_path_list = json_file_list(root_path)
|
|
42
|
+
for file_path in file_path_list:
|
|
43
|
+
if not file_path.endswith(".proto.json"):
|
|
44
|
+
continue
|
|
45
|
+
collect_abstract_info(file_path, abstract_mgr)
|
|
46
|
+
return abstract_mgr
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def parse_option():
|
|
50
|
+
parser = argparse.ArgumentParser()
|
|
51
|
+
parser.add_argument("-i", "--input", dest="root_path",
|
|
52
|
+
help="root path of Kepler *.proto.json", metavar="DIR")
|
|
53
|
+
parser.add_argument("-o", "--out", dest="output_file_path",
|
|
54
|
+
help="Abstract file path", metavar="FILE")
|
|
55
|
+
opt_dict = parser.parse_args()
|
|
56
|
+
if not opt_dict.root_path or not opt_dict.output_file_path:
|
|
57
|
+
parser.print_help()
|
|
58
|
+
return False, opt_dict
|
|
59
|
+
|
|
60
|
+
if os.path.isdir(opt_dict.root_path):
|
|
61
|
+
logging.info("%s 不是一个文件夹", opt_dict.root_path)
|
|
62
|
+
return False, opt_dict
|
|
63
|
+
if os.path.isdir(os.path.dirname(opt_dict.output_file_path)):
|
|
64
|
+
logging.info("%s 不存在", os.path.dirname(opt_dict.output_file_path))
|
|
65
|
+
return False, opt_dict
|
|
66
|
+
return True, opt_dict
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def collect(root_path: str, output_file_path: str):
|
|
70
|
+
abstract_mgr = collect_abstract_infos(root_path)
|
|
71
|
+
with os.fdopen(os.open(output_file_path, os.O_WRONLY | os.O_CREAT, stat.S_IWUSR), 'w') as fd:
|
|
72
|
+
json_obj = [abstract_mgr.url_abstract_map.get(key).to_json() for key in abstract_mgr.url_abstract_map.keys()]
|
|
73
|
+
json.dump(json_obj, fd, indent=3)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
if __name__ == '__main__':
|
|
77
|
+
is_sucess, options = parse_option()
|
|
78
|
+
if is_sucess:
|
|
79
|
+
collect(options.root_path, options.output_file_path)
|
|
@@ -0,0 +1,47 @@
|
|
|
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
|
+
from typing import List
|
|
15
|
+
|
|
16
|
+
from dto.exception import JsonTypeException, UrlNotMatchException
|
|
17
|
+
from dto.kepler_abstract import KeplerAbstractMgr, KeplerAbstract
|
|
18
|
+
from dto.redfish_api import MessageSchemaMgr, MessageSchema
|
|
19
|
+
from loader.redfish_loader import RedfishLoader
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def load(file_path) -> KeplerAbstractMgr:
|
|
23
|
+
abstract_mgr = KeplerAbstractMgr()
|
|
24
|
+
with open(file_path, "r", encoding="utf-8") as fd:
|
|
25
|
+
json_str = json.load(fd)
|
|
26
|
+
JsonTypeException.check_list(json_str)
|
|
27
|
+
for data in json_str:
|
|
28
|
+
JsonTypeException.check_dict(data)
|
|
29
|
+
abstract_mgr.add(KeplerAbstract.from_json(data))
|
|
30
|
+
return abstract_mgr
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def load_related_kepler_schemas(root_path: str,
|
|
34
|
+
routes: List[MessageSchema],
|
|
35
|
+
redfish_schema_mgr: MessageSchemaMgr,
|
|
36
|
+
abstract_mgr: KeplerAbstractMgr) -> MessageSchemaMgr:
|
|
37
|
+
schema_mgr = MessageSchemaMgr()
|
|
38
|
+
parsed_file_set = set()
|
|
39
|
+
for route in routes:
|
|
40
|
+
url_dict = redfish_schema_mgr.related_objects(route)
|
|
41
|
+
for url in url_dict.url_dict.values():
|
|
42
|
+
abstract_info = abstract_mgr.get(url.url_feature)
|
|
43
|
+
if not abstract_info:
|
|
44
|
+
raise UrlNotMatchException(url.url)
|
|
45
|
+
loader = RedfishLoader(root_path, abstract_info.file_path)
|
|
46
|
+
loader.parse(schema_mgr, parsed_file_set)
|
|
47
|
+
return schema_mgr
|