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,485 @@
|
|
|
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 re
|
|
14
|
+
|
|
15
|
+
from utils import Utils
|
|
16
|
+
from dto.options import Options
|
|
17
|
+
from render_utils.base import Base
|
|
18
|
+
from render_utils.factory import Factory
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
BASE_TYPE = "baseType"
|
|
22
|
+
ITEMS = "items"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class ModelLuaUtils(Base, Utils):
|
|
26
|
+
|
|
27
|
+
def __init__(self, data: dict, options: Options):
|
|
28
|
+
super().__init__(data, options=options)
|
|
29
|
+
|
|
30
|
+
@staticmethod
|
|
31
|
+
def has_path(msg):
|
|
32
|
+
return 'path' in msg
|
|
33
|
+
|
|
34
|
+
@staticmethod
|
|
35
|
+
def has_properties(msg):
|
|
36
|
+
return 'properties' in msg
|
|
37
|
+
|
|
38
|
+
@staticmethod
|
|
39
|
+
def has_methods(msg):
|
|
40
|
+
return 'methods' in msg
|
|
41
|
+
|
|
42
|
+
@staticmethod
|
|
43
|
+
def has_signals(msg):
|
|
44
|
+
return 'signals' in msg
|
|
45
|
+
|
|
46
|
+
@staticmethod
|
|
47
|
+
def has_table_name(msg):
|
|
48
|
+
return 'tableName' in msg
|
|
49
|
+
|
|
50
|
+
@staticmethod
|
|
51
|
+
def has_parent(msg):
|
|
52
|
+
return 'parent' in msg
|
|
53
|
+
|
|
54
|
+
@staticmethod
|
|
55
|
+
def is_enum_array(prop_config):
|
|
56
|
+
return prop_config[BASE_TYPE] == 'Array' and ITEMS in prop_config and BASE_TYPE in prop_config[ITEMS] \
|
|
57
|
+
and prop_config[ITEMS][BASE_TYPE] == 'Enum'
|
|
58
|
+
|
|
59
|
+
def class_has_block_io(self, msg):
|
|
60
|
+
if self.has_path(msg):
|
|
61
|
+
for (interface, _) in msg['interfaces'].items():
|
|
62
|
+
if interface == 'bmc.kepler.Chip.BlockIO':
|
|
63
|
+
return True
|
|
64
|
+
return False
|
|
65
|
+
|
|
66
|
+
def has_block_io(self, root):
|
|
67
|
+
for (_, msg) in root.items():
|
|
68
|
+
if self.class_has_block_io(msg):
|
|
69
|
+
return True
|
|
70
|
+
return False
|
|
71
|
+
|
|
72
|
+
def convert_dict_to_lua_table(self, msg):
|
|
73
|
+
string = '{\n'
|
|
74
|
+
i = 1
|
|
75
|
+
for (prop, value) in msg.items():
|
|
76
|
+
if prop == "pattern":
|
|
77
|
+
string += f"['{prop}'] = [=[{value}]=],\n"
|
|
78
|
+
elif prop == "validator":
|
|
79
|
+
string += f"['{prop}'] = {value},\n"
|
|
80
|
+
else:
|
|
81
|
+
string += f"['{prop}'] = " + self.convert_to_lua(value) + ",\n"
|
|
82
|
+
i += 1
|
|
83
|
+
return string + '}'
|
|
84
|
+
|
|
85
|
+
def convert_to_lua(self, value):
|
|
86
|
+
if isinstance(value, str):
|
|
87
|
+
return "'" + value + "'"
|
|
88
|
+
elif isinstance(value, bool):
|
|
89
|
+
return 'true' if value else 'false'
|
|
90
|
+
elif isinstance(value, int) or isinstance(value, float):
|
|
91
|
+
return str(value)
|
|
92
|
+
elif isinstance(value, dict):
|
|
93
|
+
return self.convert_dict_to_lua_table(value)
|
|
94
|
+
elif isinstance(value, list):
|
|
95
|
+
string = "{"
|
|
96
|
+
for val in value:
|
|
97
|
+
string += self.convert_to_lua(val) + ","
|
|
98
|
+
string += "}"
|
|
99
|
+
return string
|
|
100
|
+
raise Exception("无效值类型")
|
|
101
|
+
|
|
102
|
+
def get_enum_value(self, ref, enum_type):
|
|
103
|
+
if ref.startswith("types.json"):
|
|
104
|
+
return "types." + ref.replace("types.json#/defs/", "") + "." + enum_type
|
|
105
|
+
elif ref.startswith("mdb://"):
|
|
106
|
+
spices = ref.split(".json#")
|
|
107
|
+
return self.get_intf_type(Utils.get_unique_intf_name(spices[0].replace("/", "."))) + "." + \
|
|
108
|
+
spices[1].replace("/defs/", "") + "." + enum_type
|
|
109
|
+
raise Exception("枚举引用定义错误")
|
|
110
|
+
|
|
111
|
+
def get_prop_default_value(self, class_name, prop, prop_config):
|
|
112
|
+
if 'default' not in prop_config:
|
|
113
|
+
if BASE_TYPE in prop_config and prop_config[BASE_TYPE] == 'Enum':
|
|
114
|
+
return self.get_class_type(class_name) + "." + prop + ".default[1]:value()"
|
|
115
|
+
else:
|
|
116
|
+
return self.get_class_type(class_name) + "." + prop + ".default[1]"
|
|
117
|
+
|
|
118
|
+
default = prop_config['default']
|
|
119
|
+
if 'baseType' not in prop_config:
|
|
120
|
+
return self.convert_to_lua(default)
|
|
121
|
+
|
|
122
|
+
if prop_config[BASE_TYPE] == 'Enum':
|
|
123
|
+
return self.get_enum_value(prop_config["$ref"], default) + ":value()"
|
|
124
|
+
elif self.is_enum_array(prop_config):
|
|
125
|
+
result = "{"
|
|
126
|
+
for enum_type in default:
|
|
127
|
+
result += self.get_enum_value(prop_config[ITEMS]["$ref"], enum_type) + ":value(),"
|
|
128
|
+
return result + "}"
|
|
129
|
+
|
|
130
|
+
return self.convert_to_lua(default)
|
|
131
|
+
|
|
132
|
+
def get_mdb_prop_default_value(self, intf_name, prop, prop_config):
|
|
133
|
+
pkg_name = self.get_intf_type(intf_name) + "."
|
|
134
|
+
if 'default' not in prop_config:
|
|
135
|
+
if BASE_TYPE in prop_config and prop_config[BASE_TYPE] == 'Enum':
|
|
136
|
+
return pkg_name + prop + ".default[1]:value()"
|
|
137
|
+
else:
|
|
138
|
+
return pkg_name + prop + ".default[1]"
|
|
139
|
+
|
|
140
|
+
default = prop_config['default']
|
|
141
|
+
if 'baseType' not in prop_config:
|
|
142
|
+
return self.convert_to_lua(default)
|
|
143
|
+
|
|
144
|
+
if prop_config[BASE_TYPE] == 'Enum':
|
|
145
|
+
return pkg_name + \
|
|
146
|
+
prop_config["$ref"].replace("#/defs/", "") + "." + default + ":value()"
|
|
147
|
+
elif self.is_enum_array(prop_config):
|
|
148
|
+
result = "{"
|
|
149
|
+
for enum_type in default:
|
|
150
|
+
result += pkg_name + prop_config[ITEMS]["$ref"].replace("#/defs/", "") + "." + enum_type + ":value(),"
|
|
151
|
+
return result + "}"
|
|
152
|
+
|
|
153
|
+
return self.convert_to_lua(default)
|
|
154
|
+
|
|
155
|
+
def get_path(self, root, msg):
|
|
156
|
+
if not self.has_path(msg):
|
|
157
|
+
return ''
|
|
158
|
+
if not self.has_parent(msg):
|
|
159
|
+
return msg['path']
|
|
160
|
+
return msg['path'].replace(':parent/', self.get_path(root, root[msg['parent']]) + ':parent/')
|
|
161
|
+
|
|
162
|
+
def convert_dynamic_params(self, msg):
|
|
163
|
+
match_obj = re.search("\$\{(.+?)\}", msg)
|
|
164
|
+
if match_obj is None:
|
|
165
|
+
return msg
|
|
166
|
+
|
|
167
|
+
return self.convert_dynamic_params(re.sub('\$\{(.+?)\}', ':' + match_obj.group(1), msg, 1))
|
|
168
|
+
|
|
169
|
+
def get_primary_key(self, msg):
|
|
170
|
+
if self.has_properties(msg):
|
|
171
|
+
for (prop, prop_config) in msg['properties'].items():
|
|
172
|
+
if "primaryKey" in prop_config:
|
|
173
|
+
return self.convert_to_lua({"field": prop, BASE_TYPE: prop_config.get('baseType')})
|
|
174
|
+
|
|
175
|
+
if 'interfaces' not in msg:
|
|
176
|
+
return {}
|
|
177
|
+
|
|
178
|
+
for (_, intf_msg) in msg['interfaces'].items():
|
|
179
|
+
if not self.has_properties(intf_msg):
|
|
180
|
+
continue
|
|
181
|
+
for (prop, prop_config) in intf_msg['properties'].items():
|
|
182
|
+
if "primaryKey" not in prop_config:
|
|
183
|
+
continue
|
|
184
|
+
result = {"field": prop_config.get("alias", prop), BASE_TYPE: prop_config.get('baseType')}
|
|
185
|
+
return self.convert_to_lua(result)
|
|
186
|
+
|
|
187
|
+
return {}
|
|
188
|
+
|
|
189
|
+
def has_prop_configs(self, msg):
|
|
190
|
+
return self.has_properties(msg)
|
|
191
|
+
|
|
192
|
+
def get_prop_configs(self, class_name, msg):
|
|
193
|
+
for (prop, prop_config) in msg['properties'].items():
|
|
194
|
+
prop_config["validator"] = self.get_class_type(class_name) + "." + prop
|
|
195
|
+
return self.convert_to_lua(msg['properties'])
|
|
196
|
+
|
|
197
|
+
def get_default_props(self, class_name, msg):
|
|
198
|
+
string = '{'
|
|
199
|
+
for (prop, prop_config) in msg['properties'].items():
|
|
200
|
+
string += "['" + str(prop) + "'] = " + \
|
|
201
|
+
str(self.get_prop_default_value(class_name, prop, prop_config)) + ","
|
|
202
|
+
|
|
203
|
+
return string + '}'
|
|
204
|
+
|
|
205
|
+
def has_mdb_prop_configs(self, msg):
|
|
206
|
+
if not self.has_path(msg):
|
|
207
|
+
return False
|
|
208
|
+
|
|
209
|
+
for (_, intf_msg) in msg['interfaces'].items():
|
|
210
|
+
if self.has_properties(intf_msg):
|
|
211
|
+
return True
|
|
212
|
+
|
|
213
|
+
return False
|
|
214
|
+
|
|
215
|
+
def get_mdb_prop_configs(self, msg):
|
|
216
|
+
string = '{'
|
|
217
|
+
for (interface, intf_msg) in msg['interfaces'].items():
|
|
218
|
+
if not self.has_properties(intf_msg):
|
|
219
|
+
continue
|
|
220
|
+
intf_name = self.get_intf_name(interface, intf_msg)
|
|
221
|
+
for (prop, prop_config) in intf_msg['properties'].items():
|
|
222
|
+
prop_config["validator"] = f"{self.get_intf_type(intf_name)}.{prop}"
|
|
223
|
+
string += f"['{interface}'] = {self.convert_to_lua(intf_msg['properties'])},"
|
|
224
|
+
|
|
225
|
+
return string + '}'
|
|
226
|
+
|
|
227
|
+
def convert_methods(self, methods):
|
|
228
|
+
result = {}
|
|
229
|
+
for (method, method_config) in methods.items():
|
|
230
|
+
result[method] = {}
|
|
231
|
+
for (body, params) in method_config.items():
|
|
232
|
+
if body != 'req' and body != 'rsp':
|
|
233
|
+
result[method][body] = params
|
|
234
|
+
continue
|
|
235
|
+
result[method][body] = []
|
|
236
|
+
for (param, param_config) in params.items():
|
|
237
|
+
param_config["param"] = param
|
|
238
|
+
result[method][body].append(param_config)
|
|
239
|
+
return result
|
|
240
|
+
|
|
241
|
+
def convert_signals(self, signals):
|
|
242
|
+
result = {}
|
|
243
|
+
for (signal, signal_config) in signals.items():
|
|
244
|
+
result[signal] = []
|
|
245
|
+
for (param, param_config) in signal_config.items():
|
|
246
|
+
param_config["param"] = param
|
|
247
|
+
result[signal].append(param_config)
|
|
248
|
+
return result
|
|
249
|
+
|
|
250
|
+
def has_mdb_method_configs(self, msg):
|
|
251
|
+
if not self.has_path(msg):
|
|
252
|
+
return False
|
|
253
|
+
|
|
254
|
+
for (_, intf_msg) in msg['interfaces'].items():
|
|
255
|
+
if self.has_methods(intf_msg):
|
|
256
|
+
return True
|
|
257
|
+
|
|
258
|
+
return False
|
|
259
|
+
|
|
260
|
+
def get_mdb_method_configs(self, msg):
|
|
261
|
+
string = '{'
|
|
262
|
+
for (interface, intf_msg) in msg['interfaces'].items():
|
|
263
|
+
if self.has_methods(intf_msg):
|
|
264
|
+
methods = self.convert_methods(intf_msg['methods'])
|
|
265
|
+
string += "['" + str(interface) + "'] = " + self.convert_to_lua(methods) + ","
|
|
266
|
+
return string + '}'
|
|
267
|
+
|
|
268
|
+
def has_mdb_signal_configs(self, msg):
|
|
269
|
+
if not self.has_path(msg):
|
|
270
|
+
return False
|
|
271
|
+
|
|
272
|
+
for (_, intf_msg) in msg['interfaces'].items():
|
|
273
|
+
if self.has_signals(intf_msg):
|
|
274
|
+
return True
|
|
275
|
+
|
|
276
|
+
return False
|
|
277
|
+
|
|
278
|
+
def get_mdb_signal_configs(self, msg):
|
|
279
|
+
string = '{'
|
|
280
|
+
for (interface, intf_msg) in msg['interfaces'].items():
|
|
281
|
+
if self.has_signals(intf_msg):
|
|
282
|
+
signals = self.convert_signals(intf_msg['signals'])
|
|
283
|
+
string += "['" + str(interface) + "'] = " + self.convert_to_lua(signals) + ","
|
|
284
|
+
|
|
285
|
+
return string + '}'
|
|
286
|
+
|
|
287
|
+
def has_alias(self, msg):
|
|
288
|
+
if not self.has_path(msg):
|
|
289
|
+
return False
|
|
290
|
+
|
|
291
|
+
for (_, intf_msg) in msg['interfaces'].items():
|
|
292
|
+
if not self.has_properties(intf_msg):
|
|
293
|
+
continue
|
|
294
|
+
|
|
295
|
+
for (_, prop_config) in intf_msg['properties'].items():
|
|
296
|
+
if 'alias' in prop_config:
|
|
297
|
+
return True
|
|
298
|
+
|
|
299
|
+
return False
|
|
300
|
+
|
|
301
|
+
def get_alias_map(self, msg):
|
|
302
|
+
result = {}
|
|
303
|
+
for (interface, intf_msg) in msg['interfaces'].items():
|
|
304
|
+
if not self.has_properties(intf_msg):
|
|
305
|
+
continue
|
|
306
|
+
|
|
307
|
+
for (prop, prop_config) in intf_msg['properties'].items():
|
|
308
|
+
if 'alias' in prop_config:
|
|
309
|
+
result[prop_config['alias']] = {"original_name": prop, "interface": interface}
|
|
310
|
+
|
|
311
|
+
return self.convert_to_lua(result)
|
|
312
|
+
|
|
313
|
+
def has_mdb_classes(self, msg):
|
|
314
|
+
return self.has_path(msg)
|
|
315
|
+
|
|
316
|
+
def get_mdb_classes(self, root, msg):
|
|
317
|
+
return "mdb.get_class_obj('" + self.deduplicate_path(self.convert_dynamic_params(self.get_path(root, msg))) + \
|
|
318
|
+
"')"
|
|
319
|
+
|
|
320
|
+
def has_new_mdb_objects(self, msg):
|
|
321
|
+
return self.has_path(msg)
|
|
322
|
+
|
|
323
|
+
def has_privilege(self, msg, intf_msg):
|
|
324
|
+
return ('privilege' in msg) or ('privilege' in intf_msg) or (self.has_property_privilege(intf_msg)) or \
|
|
325
|
+
(self.has_method_privilege(intf_msg))
|
|
326
|
+
|
|
327
|
+
def get_new_mdb_objects(self, msg):
|
|
328
|
+
string = 'mdb.new_objects_builder({'
|
|
329
|
+
for (interface, intf_msg) in msg['interfaces'].items():
|
|
330
|
+
string += f"['{interface}'] = {{"
|
|
331
|
+
intf_name = self.get_intf_name(interface, intf_msg)
|
|
332
|
+
if self.has_properties(intf_msg):
|
|
333
|
+
string += "['property_defaults'] = {"
|
|
334
|
+
for (prop, prop_config) in intf_msg['properties'].items():
|
|
335
|
+
string += f"['{prop}'] = " + self.get_mdb_prop_default_value(intf_name, prop, prop_config) + ','
|
|
336
|
+
string += '},'
|
|
337
|
+
|
|
338
|
+
if self.has_privilege(msg, intf_msg):
|
|
339
|
+
string += "['privileges'] = {"
|
|
340
|
+
if 'privilege' in msg:
|
|
341
|
+
string += "['path'] = " + self.get_privilege(msg) + ','
|
|
342
|
+
if 'privilege' in intf_msg:
|
|
343
|
+
string += "['interface'] = " + self.get_privilege(intf_msg) + ','
|
|
344
|
+
if self.has_property_privilege(intf_msg):
|
|
345
|
+
string += "['props'] = " + self.get_property_privileges(intf_msg['properties']) + ','
|
|
346
|
+
if self.has_method_privilege(intf_msg):
|
|
347
|
+
string += "['methods'] = " + self.get_privileges(intf_msg['methods']) + ','
|
|
348
|
+
string += '},'
|
|
349
|
+
|
|
350
|
+
string += f"['interface_types'] = {self.get_intf_type(intf_name)}}},"
|
|
351
|
+
|
|
352
|
+
return string + "})"
|
|
353
|
+
|
|
354
|
+
def get_intf_name(self, interface, intf_msg):
|
|
355
|
+
slices = interface.split(".")
|
|
356
|
+
if "implement" in intf_msg:
|
|
357
|
+
return slices[-2] + slices[-1]
|
|
358
|
+
return Utils.get_unique_intf_name(interface)
|
|
359
|
+
|
|
360
|
+
def get_privilege(self, config):
|
|
361
|
+
if 'privilege' not in config:
|
|
362
|
+
return 'nil'
|
|
363
|
+
privilege = []
|
|
364
|
+
for priv in config['privilege']:
|
|
365
|
+
privilege.append('privilege.' + priv)
|
|
366
|
+
return " | ".join(privilege)
|
|
367
|
+
|
|
368
|
+
def get_privileges(self, configs):
|
|
369
|
+
privileges = {}
|
|
370
|
+
for prop, prop_config in configs.items():
|
|
371
|
+
if 'privilege' in prop_config:
|
|
372
|
+
privileges[prop] = self.get_privilege(prop_config)
|
|
373
|
+
|
|
374
|
+
string = '{\n'
|
|
375
|
+
for (prop, value) in privileges.items():
|
|
376
|
+
string += "['" + prop + "'] = " + value + ",\n"
|
|
377
|
+
return string + '}'
|
|
378
|
+
|
|
379
|
+
def get_property_privilege(self, config):
|
|
380
|
+
result = {}
|
|
381
|
+
if 'privilege' not in config:
|
|
382
|
+
return result
|
|
383
|
+
|
|
384
|
+
for item, privileges in config['privilege'].items():
|
|
385
|
+
privilege = []
|
|
386
|
+
for priv in privileges:
|
|
387
|
+
privilege.append('privilege.' + priv)
|
|
388
|
+
|
|
389
|
+
result[item] = " | ".join(privilege)
|
|
390
|
+
|
|
391
|
+
return result
|
|
392
|
+
|
|
393
|
+
def has_property_privilege(self, intf_msg):
|
|
394
|
+
if 'properties' not in intf_msg:
|
|
395
|
+
return False
|
|
396
|
+
|
|
397
|
+
for _, prop_config in intf_msg['properties'].items():
|
|
398
|
+
if 'privilege' in prop_config:
|
|
399
|
+
return True
|
|
400
|
+
return False
|
|
401
|
+
|
|
402
|
+
def has_method_privilege(self, intf_msg):
|
|
403
|
+
if 'methods' not in intf_msg:
|
|
404
|
+
return False
|
|
405
|
+
|
|
406
|
+
for _, method_config in intf_msg['methods'].items():
|
|
407
|
+
if 'privilege' in method_config:
|
|
408
|
+
return True
|
|
409
|
+
return False
|
|
410
|
+
|
|
411
|
+
def get_property_privileges(self, configs):
|
|
412
|
+
privileges = {}
|
|
413
|
+
for prop, prop_config in configs.items():
|
|
414
|
+
if 'privilege' in prop_config:
|
|
415
|
+
privileges[prop] = self.get_property_privilege(prop_config)
|
|
416
|
+
|
|
417
|
+
result = '{\n'
|
|
418
|
+
for (prop, value) in privileges.items():
|
|
419
|
+
priv = '{\n'
|
|
420
|
+
for item, privilege in value.items():
|
|
421
|
+
priv += "['" + item + "'] = " + privilege + ",\n"
|
|
422
|
+
priv += '}'
|
|
423
|
+
|
|
424
|
+
result += "['" + prop + "'] = " + priv + ",\n"
|
|
425
|
+
return result + '}'
|
|
426
|
+
|
|
427
|
+
def get_class_type(self, class_name):
|
|
428
|
+
return Utils.camel_to_snake(class_name) + '_class_types'
|
|
429
|
+
|
|
430
|
+
def get_class_types(self, project_name, root):
|
|
431
|
+
types = {}
|
|
432
|
+
for (class_name, msg) in root.items():
|
|
433
|
+
if not msg.get('properties', {}) and not msg.get('methods', {}):
|
|
434
|
+
continue
|
|
435
|
+
|
|
436
|
+
if msg.get('properties', {}):
|
|
437
|
+
if any(('default' in prop_config and prop_config.get(BASE_TYPE, {}) == 'Enum' and \
|
|
438
|
+
prop_config["$ref"].startswith("types.json")) for prop_config in msg['properties'].values()):
|
|
439
|
+
type_json_type = 'types'
|
|
440
|
+
types[type_json_type] = f"local {type_json_type} = require 'class.types.types'\n"
|
|
441
|
+
|
|
442
|
+
c_type = self.get_class_type(class_name)
|
|
443
|
+
if project_name != 'dft' and project_name != 'debug':
|
|
444
|
+
types[c_type] = f"local {c_type} = require 'class.types.{class_name}'\n"
|
|
445
|
+
else:
|
|
446
|
+
types[c_type] = f"local {c_type} = require '{project_name}.class.types.{class_name}'\n"
|
|
447
|
+
return types
|
|
448
|
+
|
|
449
|
+
def get_intf_type(self, intf_name):
|
|
450
|
+
return Utils.camel_to_snake(intf_name) + '_intf_types'
|
|
451
|
+
|
|
452
|
+
def get_intf_types(self, project_name, root):
|
|
453
|
+
types = {}
|
|
454
|
+
for (_, msg) in root.items():
|
|
455
|
+
for (interface, intf_msg) in msg.get('interfaces', {}).items():
|
|
456
|
+
intf_name = self.get_intf_name(interface, intf_msg)
|
|
457
|
+
intf_type = self.get_intf_type(intf_name)
|
|
458
|
+
types[intf_type] = f"local {intf_type} = require '{project_name}.json_types.{intf_name}'\n"
|
|
459
|
+
return types
|
|
460
|
+
|
|
461
|
+
def render_types(self, project_name, root):
|
|
462
|
+
types = {}
|
|
463
|
+
types.update(self.get_class_types(project_name, root))
|
|
464
|
+
types.update(self.get_intf_types(project_name, root))
|
|
465
|
+
|
|
466
|
+
string = ''
|
|
467
|
+
for _, value in types.items():
|
|
468
|
+
string += value
|
|
469
|
+
return string
|
|
470
|
+
|
|
471
|
+
def collect_features(self, intf_msg, features):
|
|
472
|
+
for method_config in intf_msg.get('methods', {}).values():
|
|
473
|
+
if "featureTag" in method_config:
|
|
474
|
+
features.add(method_config["featureTag"])
|
|
475
|
+
|
|
476
|
+
def get_features(self, root):
|
|
477
|
+
features = set()
|
|
478
|
+
if "private" in root:
|
|
479
|
+
self.collect_features(root["private"], features)
|
|
480
|
+
for msg in root.values():
|
|
481
|
+
for intf_msg in msg.get('interfaces', {}).values():
|
|
482
|
+
self.collect_features(intf_msg, features)
|
|
483
|
+
return sorted(list(features))
|
|
484
|
+
|
|
485
|
+
Factory().register("model.lua.mako", ModelLuaUtils)
|