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,444 @@
|
|
|
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 getopt
|
|
15
|
+
import sys
|
|
16
|
+
import os
|
|
17
|
+
import stat
|
|
18
|
+
from copy import deepcopy
|
|
19
|
+
import mds_util as utils
|
|
20
|
+
from utils import Utils
|
|
21
|
+
from bmcgo.utils.tools import Tools
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
tool = Tools()
|
|
25
|
+
log = tool.log
|
|
26
|
+
PERSIST_TYPES = {
|
|
27
|
+
"PermanentPer", "PoweroffPer", "ResetPer", "TemporaryPer", "PoweroffPerRetain",
|
|
28
|
+
"ResetPerRetain", "TemporaryPerRetain", "Memory"
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
BACKUP_PERSIST_TYPES = {
|
|
32
|
+
"PoweroffPer", "PoweroffPerRetain"
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
NO_BACKUP_PERSIST_TYPES = {
|
|
36
|
+
"PermanentPer",
|
|
37
|
+
"ResetPer",
|
|
38
|
+
"TemporaryPer",
|
|
39
|
+
"ResetPerRetain",
|
|
40
|
+
"TemporaryPerRetain"
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
EXTEND_FIELD = "extend_field"
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def check_duplicate_public_name(names, all_names, prop, prop_data, class_name):
|
|
47
|
+
if "alias" in prop_data:
|
|
48
|
+
if prop_data["alias"] in names:
|
|
49
|
+
raise RuntimeError(f"model.json中类{class_name}具有重复的资源树属性别名: {prop_data['alias']}")
|
|
50
|
+
names[prop_data["alias"]] = True
|
|
51
|
+
all_names[prop] = True
|
|
52
|
+
all_names[prop_data["alias"]] = True
|
|
53
|
+
return
|
|
54
|
+
|
|
55
|
+
if prop in names:
|
|
56
|
+
raise RuntimeError(f"model.json中类{class_name}具有重复的资源树属性名称: {prop}")
|
|
57
|
+
names[prop] = True
|
|
58
|
+
all_names[prop] = True
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def check_duplicate_private_name(all_names, prop, class_name):
|
|
62
|
+
if prop in all_names:
|
|
63
|
+
raise RuntimeError(f"model.json中类{class_name}具有重复的私有属性名称: {prop}")
|
|
64
|
+
all_names[prop] = True
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def check_if_local(class_data):
|
|
68
|
+
return "tableLocation" in class_data and class_data["tableLocation"] == "Local"
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def ignore_persistence_if_local(class_data, prop_data):
|
|
72
|
+
if check_if_local(class_data):
|
|
73
|
+
if 'usage' in prop_data:
|
|
74
|
+
del prop_data['usage']
|
|
75
|
+
return prop_data
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def make_private_properties(class_info, properties, index, names, imports):
|
|
79
|
+
class_name = class_info["class_name"]
|
|
80
|
+
class_data = class_info["class_data"]
|
|
81
|
+
if "properties" not in class_data:
|
|
82
|
+
return properties, index
|
|
83
|
+
for prop, prop_data in class_data["properties"].items():
|
|
84
|
+
if prop == "priority":
|
|
85
|
+
continue
|
|
86
|
+
if "alias" in prop_data:
|
|
87
|
+
raise RuntimeError(f"model.json中类{class_name}的私有属性{prop}具有别名")
|
|
88
|
+
check_duplicate_private_name(names["all_names"], prop, class_name)
|
|
89
|
+
|
|
90
|
+
prop_data = ignore_persistence_if_local(class_data, prop_data) # 判断是否忽略usage字段
|
|
91
|
+
t_property = utils.get_property(prop, prop_data, index)
|
|
92
|
+
if "type" in t_property and t_property["type"] not in utils.ALLOW_BASIC_TYPES.values():
|
|
93
|
+
t_property["type"] = t_property["type"].replace("defs_", "")
|
|
94
|
+
if t_property["type"].startswith("def_types."):
|
|
95
|
+
imports.add("model_types/def_types.proto")
|
|
96
|
+
else:
|
|
97
|
+
imports.add(f"json_types/{t_property['type'].split('.')[0]}.proto")
|
|
98
|
+
|
|
99
|
+
properties.append(t_property)
|
|
100
|
+
index = index + 1
|
|
101
|
+
return properties, index
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def make_public_properties(class_info, properties, index, names, imports):
|
|
105
|
+
class_name = class_info["class_name"]
|
|
106
|
+
class_data = class_info["class_data"]
|
|
107
|
+
if "interfaces" not in class_data:
|
|
108
|
+
return properties, index
|
|
109
|
+
is_local = check_if_local(class_data)
|
|
110
|
+
for interface, props in class_data["interfaces"].items():
|
|
111
|
+
if (is_local or Utils.get_lua_codegen_version() >= 14) and interface == "bmc.kepler.Object.Properties":
|
|
112
|
+
continue
|
|
113
|
+
if "properties" not in props:
|
|
114
|
+
continue
|
|
115
|
+
for prop, prop_data in props["properties"].items():
|
|
116
|
+
if prop == "priority":
|
|
117
|
+
continue
|
|
118
|
+
check_duplicate_public_name(names["pub_names"], names["all_names"], prop, prop_data, class_name)
|
|
119
|
+
|
|
120
|
+
t_property = utils.get_property(prop, prop_data, index)
|
|
121
|
+
if "type" in t_property and t_property["type"] not in utils.ALLOW_BASIC_TYPES.values():
|
|
122
|
+
unique_intf_name = Utils.get_unique_intf_name(interface)
|
|
123
|
+
t_property["type"] = t_property["type"].replace(
|
|
124
|
+
"defs.", unique_intf_name + ".")
|
|
125
|
+
imports.add(f"json_types/{unique_intf_name}.proto")
|
|
126
|
+
properties.append(t_property)
|
|
127
|
+
|
|
128
|
+
index = index + 1
|
|
129
|
+
return properties, index
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def class_contains_global_persist_type(class_data: dict):
|
|
133
|
+
return class_data.get("tableType", "") in PERSIST_TYPES
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def prop_contains_persist_type(prop_config: dict):
|
|
137
|
+
return bool(set(prop_config.get("usage", [])) & PERSIST_TYPES)
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def get_props_with_persist_type(class_data: dict):
|
|
141
|
+
props = []
|
|
142
|
+
for prop_name, prop_config in class_data.get('properties', {}).items():
|
|
143
|
+
if prop_contains_persist_type(prop_config):
|
|
144
|
+
props.append(prop_name)
|
|
145
|
+
|
|
146
|
+
for intf_data in class_data.get('interfaces', {}).values():
|
|
147
|
+
for prop_name, prop_config in intf_data.get('properties', {}).items():
|
|
148
|
+
if prop_contains_persist_type(prop_config):
|
|
149
|
+
props.append(prop_name)
|
|
150
|
+
return props
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def prop_contains_csr(prop_configs):
|
|
154
|
+
for prop_config in prop_configs.values():
|
|
155
|
+
for t_usage in prop_config.get("usage", []):
|
|
156
|
+
if t_usage == "CSR":
|
|
157
|
+
return True
|
|
158
|
+
|
|
159
|
+
return False
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def contains_csr(class_data):
|
|
163
|
+
if prop_contains_csr(class_data.get("properties", {})):
|
|
164
|
+
return True
|
|
165
|
+
|
|
166
|
+
for intf_data in class_data.get("interfaces", {}).values():
|
|
167
|
+
if prop_contains_csr(intf_data.get("properties", {})):
|
|
168
|
+
return True
|
|
169
|
+
|
|
170
|
+
return False
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def has_primary_key(class_data):
|
|
174
|
+
for prop_config in class_data.get('properties', {}).values():
|
|
175
|
+
if prop_config.get("primaryKey", False):
|
|
176
|
+
return True
|
|
177
|
+
|
|
178
|
+
for intf_data in class_data.get('interfaces', {}).values():
|
|
179
|
+
for prop_config in intf_data.get('properties', {}).values():
|
|
180
|
+
if prop_config.get("primaryKey", False):
|
|
181
|
+
return True
|
|
182
|
+
|
|
183
|
+
return False
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def is_positive_integer(value):
|
|
187
|
+
return isinstance(value, int) and value > 0
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
def gen_class_option(class_name, class_data):
|
|
191
|
+
class_options = {"table_name": class_data["tableName"]}
|
|
192
|
+
if "tableType" in class_data and class_data["tableType"]:
|
|
193
|
+
class_options["table_type"] = class_data["tableType"]
|
|
194
|
+
if "tableMaxRows" in class_data and Utils.get_lua_codegen_version() >= 11:
|
|
195
|
+
if not is_positive_integer(class_data["tableMaxRows"]):
|
|
196
|
+
raise RuntimeError(f"model.json中类{class_name}配置了'tableMaxRows字段', 但是类型不是正整数")
|
|
197
|
+
class_options["table_max_rows"] = class_data["tableMaxRows"]
|
|
198
|
+
return class_options
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def need_gen_db(class_data, props_with_persist_type):
|
|
202
|
+
if check_if_local(class_data):
|
|
203
|
+
return True
|
|
204
|
+
|
|
205
|
+
if class_data.get("tableType", "") in PERSIST_TYPES:
|
|
206
|
+
return True
|
|
207
|
+
|
|
208
|
+
return bool(props_with_persist_type)
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def fill_table_type(backup_table_types, no_backup_table_types, table_type):
|
|
212
|
+
if table_type in BACKUP_PERSIST_TYPES:
|
|
213
|
+
backup_table_types.add(table_type)
|
|
214
|
+
elif table_type in NO_BACKUP_PERSIST_TYPES:
|
|
215
|
+
no_backup_table_types.add(table_type)
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def fill_properties_table_type(global_type, properties, conflict_props, backup_table_types, no_backup_table_types):
|
|
219
|
+
for prop_name, prop_config in properties.items():
|
|
220
|
+
u = deepcopy(prop_config.get("usage", []))
|
|
221
|
+
if not prop_contains_persist_type(prop_config):
|
|
222
|
+
if global_type:
|
|
223
|
+
u.append(global_type)
|
|
224
|
+
|
|
225
|
+
if not bool(set(u) & BACKUP_PERSIST_TYPES):
|
|
226
|
+
if prop_config.get("notAllowNull", False) and not prop_config.get("primaryKey", False) \
|
|
227
|
+
and "default" not in prop_config:
|
|
228
|
+
conflict_props.append(prop_config.get("alias", prop_name))
|
|
229
|
+
|
|
230
|
+
for table_type in u:
|
|
231
|
+
fill_table_type(backup_table_types, no_backup_table_types, table_type)
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
def check_table_type_consistency(class_name, class_data):
|
|
235
|
+
backup_table_types = set()
|
|
236
|
+
no_backup_table_types = set()
|
|
237
|
+
conflict_props = []
|
|
238
|
+
|
|
239
|
+
global_type = class_data.get("tableType", None)
|
|
240
|
+
|
|
241
|
+
fill_properties_table_type(global_type, class_data.get('properties', {}), conflict_props, backup_table_types,
|
|
242
|
+
no_backup_table_types)
|
|
243
|
+
|
|
244
|
+
for intf_data in class_data.get('interfaces', {}).values():
|
|
245
|
+
fill_properties_table_type(global_type, intf_data.get('properties', {}), conflict_props, backup_table_types,
|
|
246
|
+
no_backup_table_types)
|
|
247
|
+
|
|
248
|
+
if not contains_csr(class_data) and backup_table_types and conflict_props:
|
|
249
|
+
raise RuntimeError(f"请为类{class_name}的属性{conflict_props}配置默认值或允许属性为null,否则可能出现恢复数据到内存数据库失败的问题")
|
|
250
|
+
|
|
251
|
+
if backup_table_types and no_backup_table_types:
|
|
252
|
+
log.warning(f"类{class_name}配置了多种持久化类型,支持备份机制的{backup_table_types}与不支持备份机制的{no_backup_table_types}混用," +
|
|
253
|
+
"在主数据库文件丢失、从备份数据库恢复数据时,可能出现数据不一致的问题")
|
|
254
|
+
|
|
255
|
+
if "PermanentPer" in no_backup_table_types and (len(no_backup_table_types) > 1 or len(backup_table_types) > 0):
|
|
256
|
+
log.warning(f"类{class_name}同时配置了PermanentPer和其他持久化类型,掉电场景下可能出现数据不一致的问题")
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
def make_datas(load_dict, package, imports, is_local):
|
|
260
|
+
datas = []
|
|
261
|
+
|
|
262
|
+
for class_name, class_data in load_dict.items():
|
|
263
|
+
props_with_persist_type = get_props_with_persist_type(class_data)
|
|
264
|
+
data_need_persist = class_contains_global_persist_type(class_data) or bool(props_with_persist_type)
|
|
265
|
+
if "tableName" not in class_data:
|
|
266
|
+
if data_need_persist:
|
|
267
|
+
raise RuntimeError(f"model.json中类{class_name}配置了持久化但是没有配置'tableName'")
|
|
268
|
+
continue
|
|
269
|
+
|
|
270
|
+
if Utils.get_lua_codegen_version() >= 14 and not need_gen_db(class_data, props_with_persist_type):
|
|
271
|
+
continue
|
|
272
|
+
|
|
273
|
+
table_name = class_data["tableName"]
|
|
274
|
+
if table_name.startswith("_"):
|
|
275
|
+
raise RuntimeError(f"model.json中类{class_name}配置的'tableName' {table_name}不能以保留字符'_'开头")
|
|
276
|
+
|
|
277
|
+
if check_if_local(class_data) != is_local: # 与本地持久化标志不一致则跳过
|
|
278
|
+
continue
|
|
279
|
+
|
|
280
|
+
if Utils.get_lua_codegen_version() < 11:
|
|
281
|
+
if data_need_persist and not is_local and not has_primary_key(class_data):
|
|
282
|
+
raise RuntimeError(f"model.json中类{class_name}配置了远程持久化但是没有配置'primaryKey'")
|
|
283
|
+
else:
|
|
284
|
+
if data_need_persist and not has_primary_key(class_data):
|
|
285
|
+
raise RuntimeError(f"model.json中类{class_name}配置了持久化但是没有配置'primaryKey'")
|
|
286
|
+
|
|
287
|
+
if is_local and props_with_persist_type:
|
|
288
|
+
log.warning("model.json中类%s配置了本地持久化,持久化类型以'tableType'字段值为准,其属性%s在usage中配置的持久化类型是无效的",
|
|
289
|
+
class_name, ', '.join(props_with_persist_type))
|
|
290
|
+
elif Utils.get_lua_codegen_version() >= 14:
|
|
291
|
+
check_table_type_consistency(class_name, class_data)
|
|
292
|
+
|
|
293
|
+
names = {"pub_names": {}, "all_names": {}}
|
|
294
|
+
class_options = {}
|
|
295
|
+
index = 1
|
|
296
|
+
properties = []
|
|
297
|
+
|
|
298
|
+
class_options = gen_class_option(class_name, class_data)
|
|
299
|
+
class_info = {
|
|
300
|
+
"class_name": class_name,
|
|
301
|
+
"class_data": class_data
|
|
302
|
+
}
|
|
303
|
+
properties, index = make_public_properties(class_info, properties, index, names, imports)
|
|
304
|
+
properties, index = make_private_properties(class_info, properties, index, names, imports)
|
|
305
|
+
|
|
306
|
+
if index > 1:
|
|
307
|
+
datas.append(
|
|
308
|
+
{
|
|
309
|
+
"package": package,
|
|
310
|
+
"name": class_name,
|
|
311
|
+
"options": class_options,
|
|
312
|
+
"type": "Message",
|
|
313
|
+
"properties": properties,
|
|
314
|
+
"nested_type": [],
|
|
315
|
+
}
|
|
316
|
+
)
|
|
317
|
+
return datas
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
def get_property(prop_name, properties):
|
|
321
|
+
for item in properties:
|
|
322
|
+
if item['name'] == prop_name:
|
|
323
|
+
return item
|
|
324
|
+
|
|
325
|
+
return None
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
def rectify_local_db(historical_local_db_file, out_dict):
|
|
329
|
+
if not os.path.exists(historical_local_db_file):
|
|
330
|
+
return
|
|
331
|
+
|
|
332
|
+
load_f = os.fdopen(os.open(historical_local_db_file, os.O_RDONLY, stat.S_IRUSR), "r")
|
|
333
|
+
load_dict = json.load(load_f)
|
|
334
|
+
for table_info in out_dict["data"]:
|
|
335
|
+
class_name = table_info["name"]
|
|
336
|
+
properties = table_info["properties"]
|
|
337
|
+
historical_table_info = load_dict.get(class_name, [])
|
|
338
|
+
if not historical_table_info:
|
|
339
|
+
continue
|
|
340
|
+
|
|
341
|
+
historical_props = set()
|
|
342
|
+
for item in historical_table_info:
|
|
343
|
+
historical_props.add(item['name'])
|
|
344
|
+
props = set()
|
|
345
|
+
for item in properties:
|
|
346
|
+
props.add(item['name'])
|
|
347
|
+
|
|
348
|
+
deleted_props = historical_props - props
|
|
349
|
+
if deleted_props:
|
|
350
|
+
raise RuntimeError(f"使用deprecated关键字废弃{class_name}类中不再使用的属性{deleted_props},而不是直接删除属性")
|
|
351
|
+
|
|
352
|
+
new_props = []
|
|
353
|
+
for item in historical_table_info:
|
|
354
|
+
prop = get_property(item['name'], properties)
|
|
355
|
+
prop["options"][EXTEND_FIELD] = item[EXTEND_FIELD]
|
|
356
|
+
new_props.append(prop)
|
|
357
|
+
prop["id"] = len(new_props)
|
|
358
|
+
|
|
359
|
+
added_props = sorted(list(props - historical_props))
|
|
360
|
+
for prop_name in added_props:
|
|
361
|
+
prop = get_property(prop_name, properties)
|
|
362
|
+
prop["options"][EXTEND_FIELD] = True
|
|
363
|
+
new_props.append(prop)
|
|
364
|
+
prop["id"] = len(new_props)
|
|
365
|
+
|
|
366
|
+
table_info["properties"] = new_props
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
def save_json_file(is_local, load_dict, historical_local_db_file, of_name, disable_gen=False):
|
|
370
|
+
package = of_name.split("/")[-2]
|
|
371
|
+
extra_imports = set()
|
|
372
|
+
datas = make_datas(load_dict, package, extra_imports, is_local)
|
|
373
|
+
extra_imports = sorted(extra_imports)
|
|
374
|
+
|
|
375
|
+
imports = [
|
|
376
|
+
"google/protobuf/descriptor.proto",
|
|
377
|
+
"ipmi_types.proto",
|
|
378
|
+
"types.proto"
|
|
379
|
+
]
|
|
380
|
+
imports.extend(extra_imports)
|
|
381
|
+
dependency = ["types.proto"]
|
|
382
|
+
dependency.extend(extra_imports)
|
|
383
|
+
|
|
384
|
+
out_dict = {
|
|
385
|
+
"imports": imports,
|
|
386
|
+
"dependency": dependency,
|
|
387
|
+
"data": datas,
|
|
388
|
+
"service": [],
|
|
389
|
+
"filename": "database.proto",
|
|
390
|
+
"package": package.capitalize() + "DB",
|
|
391
|
+
"options": {},
|
|
392
|
+
"disable_gen": disable_gen
|
|
393
|
+
}
|
|
394
|
+
if is_local:
|
|
395
|
+
rectify_local_db(historical_local_db_file, out_dict)
|
|
396
|
+
segs = of_name.split("/")
|
|
397
|
+
segs[-1] = "local_" + segs[-1] # -1 表示以/为间隔符拆分的最后一段
|
|
398
|
+
of_name = '/'.join(segs)
|
|
399
|
+
utils.save_proto_json(of_name, out_dict)
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
def generate(if_name, historical_local_db_file, of_name):
|
|
403
|
+
if not os.path.exists(if_name):
|
|
404
|
+
return
|
|
405
|
+
load_f = os.fdopen(os.open(if_name, os.O_RDONLY, stat.S_IRUSR), "r")
|
|
406
|
+
load_dict = json.load(load_f)
|
|
407
|
+
load_f.close()
|
|
408
|
+
disable_mem_db_gen = Utils.get_lua_codegen_version() >= 7 and not Utils.check_model_need_mem_db(load_dict)
|
|
409
|
+
save_json_file(False, load_dict, historical_local_db_file, of_name, disable_gen=disable_mem_db_gen) # 保存普通持久化的表
|
|
410
|
+
save_json_file(True, load_dict, historical_local_db_file, of_name) # 保存本地持久化的表
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
def usage():
|
|
414
|
+
logging.info("gen_db_json.py -i <inputfile> -o <file>")
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
def main(argv):
|
|
418
|
+
m_input = ""
|
|
419
|
+
output = ""
|
|
420
|
+
try:
|
|
421
|
+
opts, _ = getopt.getopt(argv, "hi:m:o:d:", ["help", "input=", "history=", "out="])
|
|
422
|
+
except getopt.GetoptError:
|
|
423
|
+
help()
|
|
424
|
+
return
|
|
425
|
+
for opt, arg in opts:
|
|
426
|
+
if opt in ("-h", "--help"):
|
|
427
|
+
usage()
|
|
428
|
+
return
|
|
429
|
+
elif opt in ("-i", "--input"):
|
|
430
|
+
m_input = arg
|
|
431
|
+
elif opt in ("-m", "--history"):
|
|
432
|
+
m_hisctory = arg
|
|
433
|
+
elif opt in ("-o", "--out"):
|
|
434
|
+
output = arg
|
|
435
|
+
else:
|
|
436
|
+
raise RuntimeError("不支持的选项: {}".format(opt))
|
|
437
|
+
if not m_input or not output:
|
|
438
|
+
usage()
|
|
439
|
+
return
|
|
440
|
+
generate(m_input, m_hisctory, output)
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
if __name__ == "__main__":
|
|
444
|
+
main(sys.argv[1:])
|
|
@@ -0,0 +1,89 @@
|
|
|
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
|
+
from graphviz import Digraph
|
|
14
|
+
from graphviz import Graph
|
|
15
|
+
|
|
16
|
+
new_dot = Digraph("G", filename="test.gv", engine="fdp")
|
|
17
|
+
new_dot.attr("graph", ranksep="equally")
|
|
18
|
+
|
|
19
|
+
A = {
|
|
20
|
+
"model": {
|
|
21
|
+
"A": {"path": "path/A", "interfaces": {"test.A": {}}},
|
|
22
|
+
"D": {"path": "path/D", "interfaces": {"test.D": {}, "test.E": {}}},
|
|
23
|
+
},
|
|
24
|
+
"service": {
|
|
25
|
+
"name": "service_a",
|
|
26
|
+
"required": [{"interface": "test.B", "path": "path/B"}],
|
|
27
|
+
},
|
|
28
|
+
}
|
|
29
|
+
B = {
|
|
30
|
+
"model": {"B": {"path": "path/B", "interfaces": {"test.B": {}}}},
|
|
31
|
+
"service": {
|
|
32
|
+
"name": "service_b",
|
|
33
|
+
"required": [
|
|
34
|
+
{"interface": "test.C", "path": "path/C"},
|
|
35
|
+
{"interface": "test.E", "path": "*"},
|
|
36
|
+
],
|
|
37
|
+
},
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
C = {
|
|
41
|
+
"model": {"C": {"path": "path/C", "interfaces": {"test.C": {}}}},
|
|
42
|
+
"service": {
|
|
43
|
+
"name": "service_c",
|
|
44
|
+
"required": [{"interface": "test.D", "path": "path/D"}],
|
|
45
|
+
},
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def gen_cls(app, graph, subg):
|
|
50
|
+
for cls, cls_data in app["model"].items():
|
|
51
|
+
subg.node(cls, shape="oval")
|
|
52
|
+
for intf in cls_data["interfaces"]:
|
|
53
|
+
with graph.subgraph(name="cluster_mdb") as mdb:
|
|
54
|
+
mdb.node(intf, shape="diamond", pos="bottom")
|
|
55
|
+
graph.edge(
|
|
56
|
+
cls,
|
|
57
|
+
intf,
|
|
58
|
+
arrowhead="onormal",
|
|
59
|
+
style="dashed",
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def add_mds(app, graph):
|
|
64
|
+
app_name = app["service"]["name"]
|
|
65
|
+
subg_name = "cluster" + app_name
|
|
66
|
+
with graph.subgraph(name=subg_name) as subg:
|
|
67
|
+
subg.attr(label=app_name)
|
|
68
|
+
gen_cls(app, graph, subg)
|
|
69
|
+
|
|
70
|
+
for require in app["service"]["required"]:
|
|
71
|
+
if require["path"] != "*":
|
|
72
|
+
graph.edge(subg_name, require["path"].split("/")[-1], ltail=subg_name)
|
|
73
|
+
else:
|
|
74
|
+
with graph.subgraph(name="cluster_mdb") as mdb:
|
|
75
|
+
mdb.node(require["interface"], shape="diamond", pos="bottom")
|
|
76
|
+
graph.edge(
|
|
77
|
+
subg_name,
|
|
78
|
+
require["interface"],
|
|
79
|
+
ltail=subg_name,
|
|
80
|
+
arrowhead="vee",
|
|
81
|
+
style="dashed",
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
add_mds(A, new_dot)
|
|
86
|
+
add_mds(B, new_dot)
|
|
87
|
+
add_mds(C, new_dot)
|
|
88
|
+
|
|
89
|
+
new_dot.view()
|