openubmc-bingo 0.5.243__py3-none-any.whl → 0.5.254__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 +1 -1
- bmcgo/bmcgo_config.py +81 -1
- bmcgo/codegen/lua/Makefile +13 -0
- bmcgo/codegen/lua/codegen.py +6 -3
- bmcgo/codegen/lua/script/dto/options.py +1 -0
- bmcgo/codegen/lua/script/{render_utils/factory.py → factory.py} +1 -1
- bmcgo/codegen/lua/script/gen_entry.py +6 -3
- bmcgo/codegen/lua/script/gen_intf_rpc_json.py +12 -0
- bmcgo/codegen/lua/script/gen_schema.py +2 -0
- bmcgo/codegen/lua/script/merge_model.py +10 -3
- bmcgo/codegen/lua/script/render_utils/__init__.py +5 -4
- bmcgo/codegen/lua/script/render_utils/client_lua.py +2 -2
- bmcgo/codegen/lua/script/render_utils/controller_lua.py +2 -2
- bmcgo/codegen/lua/script/render_utils/db_lua.py +2 -2
- bmcgo/codegen/lua/script/render_utils/error_lua.py +2 -2
- bmcgo/codegen/lua/script/render_utils/ipmi_lua.py +2 -2
- bmcgo/codegen/lua/script/render_utils/ipmi_message_lua.py +2 -2
- bmcgo/codegen/lua/script/render_utils/mdb_lua.py +2 -2
- bmcgo/codegen/lua/script/render_utils/message_lua.py +2 -2
- bmcgo/codegen/lua/script/render_utils/messages_lua.py +2 -2
- bmcgo/codegen/lua/script/render_utils/model_lua.py +2 -2
- bmcgo/codegen/lua/script/render_utils/old_model_lua.py +2 -2
- bmcgo/codegen/lua/script/render_utils/plugin_lua.py +2 -2
- bmcgo/codegen/lua/script/render_utils/redfish_proto.py +2 -2
- bmcgo/codegen/lua/script/render_utils/request_lua.py +2 -2
- bmcgo/codegen/lua/script/render_utils/service_lua.py +3 -2
- bmcgo/codegen/lua/script/template.py +5 -1
- bmcgo/codegen/lua/script/utils.py +9 -2
- bmcgo/codegen/lua/templates/Makefile +8 -0
- bmcgo/codegen/lua/templates/apps/Makefile +27 -1
- bmcgo/codegen/lua/templates/apps/controller.lua.mako +20 -4
- bmcgo/codegen/lua/v1/script/gen_schema.py +328 -0
- bmcgo/codegen/lua/v1/script/render_utils/model_lua.py +458 -0
- bmcgo/codegen/lua/v1/templates/apps/model.lua.mako +62 -0
- bmcgo/codegen/lua/v1/templates/apps/service.lua.mako +193 -0
- bmcgo/component/build.py +26 -43
- bmcgo/component/component_helper.py +54 -0
- bmcgo/component/coverage/incremental_cov.py +25 -33
- bmcgo/frame.py +9 -6
- bmcgo/functional/conan_index_build.py +16 -41
- bmcgo/functional/config.py +7 -0
- bmcgo/functional/csr_build.py +313 -88
- bmcgo/functional/diff.py +3 -3
- bmcgo/functional/json_check.py +109 -0
- bmcgo/functional/upgrade.py +31 -1
- bmcgo/misc.py +32 -2
- bmcgo/target/install_sdk.yml +6 -0
- bmcgo/tasks/task.py +69 -43
- bmcgo/tasks/task_build_conan.py +6 -2
- bmcgo/tasks/task_build_wbd_up.py +4 -4
- bmcgo/utils/basic_enums.py +45 -0
- bmcgo/utils/config.py +20 -8
- bmcgo/utils/install_manager.py +75 -20
- bmcgo/utils/installations/base_installer.py +114 -7
- bmcgo/utils/installations/install_consts.py +3 -1
- bmcgo/utils/installations/install_plans/bingo.yml +2 -4
- bmcgo/utils/installations/install_workflow.py +6 -2
- bmcgo/utils/installations/installers/apt_installer.py +58 -136
- bmcgo/utils/installations/installers/pip_installer.py +52 -18
- bmcgo/utils/installations/version_util.py +1 -1
- bmcgo/utils/json_validator.py +241 -0
- {openubmc_bingo-0.5.243.dist-info → openubmc_bingo-0.5.254.dist-info}/METADATA +2 -1
- {openubmc_bingo-0.5.243.dist-info → openubmc_bingo-0.5.254.dist-info}/RECORD +67 -60
- /bmcgo/codegen/lua/script/{render_utils/base.py → base.py} +0 -0
- {openubmc_bingo-0.5.243.dist-info → openubmc_bingo-0.5.254.dist-info}/WHEEL +0 -0
- {openubmc_bingo-0.5.243.dist-info → openubmc_bingo-0.5.254.dist-info}/entry_points.txt +0 -0
- {openubmc_bingo-0.5.243.dist-info → openubmc_bingo-0.5.254.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,458 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# coding=utf-8
|
|
3
|
+
# Copyright (c) 2025 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 bmcgo.codegen.lua.script.dto.options import Options
|
|
17
|
+
from bmcgo.codegen.lua.script.base import Base
|
|
18
|
+
from bmcgo.codegen.lua.script.factory import Factory
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
BASE_TYPE = "baseType"
|
|
22
|
+
ITEMS = "items"
|
|
23
|
+
NON_CONVERT_ITEMS = ["validator", "req_type", "rsp_type", "feature", "default_value", "read", "write"]
|
|
24
|
+
FILTERED_ITEMS = ["description", "$ref", "default", "items", "req", "rsp", "featureTag", "privilege"]
|
|
25
|
+
OBJECT_PROPERTIES_INTERFACE = "bmc.kepler.Object.Properties"
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class ConsistencyModelLuaUtils(Base, Utils):
|
|
29
|
+
|
|
30
|
+
def __init__(self, data: dict, options: Options):
|
|
31
|
+
super().__init__(data, options=options)
|
|
32
|
+
|
|
33
|
+
@staticmethod
|
|
34
|
+
def has_path(msg):
|
|
35
|
+
return 'path' in msg
|
|
36
|
+
|
|
37
|
+
@staticmethod
|
|
38
|
+
def has_properties(msg):
|
|
39
|
+
return 'properties' in msg
|
|
40
|
+
|
|
41
|
+
@staticmethod
|
|
42
|
+
def has_interfaces(msg):
|
|
43
|
+
return 'interfaces' in msg
|
|
44
|
+
|
|
45
|
+
@staticmethod
|
|
46
|
+
def has_methods(msg):
|
|
47
|
+
return 'methods' in msg
|
|
48
|
+
|
|
49
|
+
@staticmethod
|
|
50
|
+
def has_signals(msg):
|
|
51
|
+
return 'signals' in msg
|
|
52
|
+
|
|
53
|
+
@staticmethod
|
|
54
|
+
def has_table_name(msg):
|
|
55
|
+
return 'tableName' in msg
|
|
56
|
+
|
|
57
|
+
@staticmethod
|
|
58
|
+
def has_parent(msg):
|
|
59
|
+
return 'parent' in msg
|
|
60
|
+
|
|
61
|
+
@staticmethod
|
|
62
|
+
def is_enum_array(prop_config):
|
|
63
|
+
return prop_config[BASE_TYPE] == 'Array' and ITEMS in prop_config and BASE_TYPE in prop_config[ITEMS] \
|
|
64
|
+
and prop_config[ITEMS][BASE_TYPE] == 'Enum'
|
|
65
|
+
|
|
66
|
+
@staticmethod
|
|
67
|
+
def combine_privileges(privileges):
|
|
68
|
+
prefix = "privilege."
|
|
69
|
+
return prefix + (" | " + prefix).join(sorted(privileges))
|
|
70
|
+
|
|
71
|
+
def class_has_block_io(self, msg):
|
|
72
|
+
if self.has_path(msg):
|
|
73
|
+
for (interface, _) in msg['interfaces'].items():
|
|
74
|
+
if interface == 'bmc.kepler.Chip.BlockIO':
|
|
75
|
+
return True
|
|
76
|
+
return False
|
|
77
|
+
|
|
78
|
+
def has_block_io(self, root):
|
|
79
|
+
for (_, msg) in root.items():
|
|
80
|
+
if self.class_has_block_io(msg):
|
|
81
|
+
return True
|
|
82
|
+
return False
|
|
83
|
+
|
|
84
|
+
def convert_dict_to_lua_table(self, msg):
|
|
85
|
+
string = '{\n'
|
|
86
|
+
i = 1
|
|
87
|
+
for (prop, value) in msg.items():
|
|
88
|
+
if prop in FILTERED_ITEMS:
|
|
89
|
+
continue
|
|
90
|
+
if prop == "pattern":
|
|
91
|
+
string += f"['{prop}'] = [=[{value}]=],\n"
|
|
92
|
+
elif prop == "privilege_value" and isinstance(value, str):
|
|
93
|
+
string += f"['{prop}'] = {value},\n"
|
|
94
|
+
elif prop in NON_CONVERT_ITEMS:
|
|
95
|
+
string += f"['{prop}'] = {value},\n"
|
|
96
|
+
else:
|
|
97
|
+
string += f"['{prop}'] = " + self.convert_to_lua(value) + ",\n"
|
|
98
|
+
i += 1
|
|
99
|
+
return string + '}'
|
|
100
|
+
|
|
101
|
+
def convert_to_lua(self, value):
|
|
102
|
+
if isinstance(value, str):
|
|
103
|
+
return "'" + value + "'"
|
|
104
|
+
elif isinstance(value, bool):
|
|
105
|
+
return 'true' if value else 'false'
|
|
106
|
+
elif isinstance(value, int) or isinstance(value, float):
|
|
107
|
+
return str(value)
|
|
108
|
+
elif isinstance(value, dict):
|
|
109
|
+
return self.convert_dict_to_lua_table(value)
|
|
110
|
+
elif isinstance(value, list):
|
|
111
|
+
string = "{"
|
|
112
|
+
for val in value:
|
|
113
|
+
string += self.convert_to_lua(val) + ","
|
|
114
|
+
string += "}"
|
|
115
|
+
return string
|
|
116
|
+
raise Exception("无效值类型")
|
|
117
|
+
|
|
118
|
+
def get_enum_value(self, ref, enum_type):
|
|
119
|
+
if ref.startswith("types.json"):
|
|
120
|
+
return "types." + ref.replace("types.json#/defs/", "") + "." + enum_type
|
|
121
|
+
elif ref.startswith("mdb://"):
|
|
122
|
+
spices = ref.split(".json#")
|
|
123
|
+
return self.get_intf_type(Utils.get_unique_intf_name(spices[0].replace("/", "."))) + "." + \
|
|
124
|
+
spices[1].replace("/defs/", "") + "." + enum_type
|
|
125
|
+
raise Exception("枚举引用定义错误")
|
|
126
|
+
|
|
127
|
+
def get_prop_default_value(self, class_name, prop, prop_config):
|
|
128
|
+
if 'default' not in prop_config:
|
|
129
|
+
if BASE_TYPE in prop_config and prop_config[BASE_TYPE] == 'Enum':
|
|
130
|
+
return self.get_class_type(class_name) + "." + prop + ".default[1]:value()"
|
|
131
|
+
else:
|
|
132
|
+
return self.get_class_type(class_name) + "." + prop + ".default[1]"
|
|
133
|
+
|
|
134
|
+
default = prop_config['default']
|
|
135
|
+
if 'baseType' not in prop_config:
|
|
136
|
+
return self.convert_to_lua(default)
|
|
137
|
+
|
|
138
|
+
if prop_config[BASE_TYPE] == 'Enum':
|
|
139
|
+
return self.get_enum_value(prop_config["$ref"], default) + ":value()"
|
|
140
|
+
elif self.is_enum_array(prop_config):
|
|
141
|
+
result = "{"
|
|
142
|
+
for enum_type in default:
|
|
143
|
+
result += self.get_enum_value(prop_config[ITEMS]["$ref"], enum_type) + ":value(),"
|
|
144
|
+
return result + "}"
|
|
145
|
+
|
|
146
|
+
return self.convert_to_lua(default)
|
|
147
|
+
|
|
148
|
+
def get_mdb_prop_default_value(self, intf_name, prop, prop_config):
|
|
149
|
+
pkg_name = self.get_intf_type(intf_name) + "."
|
|
150
|
+
if 'default' not in prop_config:
|
|
151
|
+
if BASE_TYPE in prop_config and prop_config[BASE_TYPE] == 'Enum':
|
|
152
|
+
return pkg_name + prop + ".default[1]:value()"
|
|
153
|
+
else:
|
|
154
|
+
return pkg_name + prop + ".default[1]"
|
|
155
|
+
|
|
156
|
+
default = prop_config['default']
|
|
157
|
+
if 'baseType' not in prop_config:
|
|
158
|
+
return self.convert_to_lua(default)
|
|
159
|
+
|
|
160
|
+
if prop_config[BASE_TYPE] == 'Enum':
|
|
161
|
+
return pkg_name + \
|
|
162
|
+
prop_config["$ref"].replace("#/defs/", "") + "." + default + ":value()"
|
|
163
|
+
elif self.is_enum_array(prop_config):
|
|
164
|
+
result = "{"
|
|
165
|
+
for enum_type in default:
|
|
166
|
+
result += pkg_name + prop_config[ITEMS]["$ref"].replace("#/defs/", "") + "." + enum_type + ":value(),"
|
|
167
|
+
return result + "}"
|
|
168
|
+
|
|
169
|
+
return self.convert_to_lua(default)
|
|
170
|
+
|
|
171
|
+
def get_path(self, root, msg):
|
|
172
|
+
if not self.has_path(msg):
|
|
173
|
+
return ''
|
|
174
|
+
if not self.has_parent(msg):
|
|
175
|
+
return msg['path']
|
|
176
|
+
return msg['path'].replace(':parent/', self.get_path(root, root[msg['parent']]) + ':parent/')
|
|
177
|
+
|
|
178
|
+
def convert_dynamic_params(self, msg):
|
|
179
|
+
match_obj = re.search("\$\{(.+?)\}", msg)
|
|
180
|
+
if match_obj is None:
|
|
181
|
+
return msg
|
|
182
|
+
|
|
183
|
+
return self.convert_dynamic_params(re.sub('\$\{(.+?)\}', ':' + match_obj.group(1), msg, 1))
|
|
184
|
+
|
|
185
|
+
def get_primary_key(self, msg):
|
|
186
|
+
if self.has_properties(msg):
|
|
187
|
+
for (prop, prop_config) in msg['properties'].items():
|
|
188
|
+
if "primaryKey" in prop_config:
|
|
189
|
+
return self.convert_to_lua({"field": prop, BASE_TYPE: prop_config.get('baseType')})
|
|
190
|
+
|
|
191
|
+
if 'interfaces' not in msg:
|
|
192
|
+
return {}
|
|
193
|
+
|
|
194
|
+
for (_, intf_msg) in msg['interfaces'].items():
|
|
195
|
+
if not self.has_properties(intf_msg):
|
|
196
|
+
continue
|
|
197
|
+
for (prop, prop_config) in intf_msg['properties'].items():
|
|
198
|
+
if "primaryKey" not in prop_config:
|
|
199
|
+
continue
|
|
200
|
+
result = {"field": prop_config.get("alias", prop), BASE_TYPE: prop_config.get('baseType')}
|
|
201
|
+
return self.convert_to_lua(result)
|
|
202
|
+
|
|
203
|
+
return {}
|
|
204
|
+
|
|
205
|
+
def has_prop_configs(self, msg):
|
|
206
|
+
return self.has_properties(msg)
|
|
207
|
+
|
|
208
|
+
def get_prop_configs(self, class_name, msg):
|
|
209
|
+
for (prop, prop_config) in msg['properties'].items():
|
|
210
|
+
prop_config["default_value"] = self.get_prop_default_value(class_name, prop, prop_config)
|
|
211
|
+
prop_config["validator"] = self.get_class_type(class_name) + "." + prop
|
|
212
|
+
return self.convert_to_lua(msg['properties'])
|
|
213
|
+
|
|
214
|
+
def get_default_props(self, class_name, msg):
|
|
215
|
+
string = '{'
|
|
216
|
+
for (prop, prop_config) in msg['properties'].items():
|
|
217
|
+
string += "['" + str(prop) + "'] = " + \
|
|
218
|
+
str(self.get_prop_default_value(class_name, prop, prop_config)) + ","
|
|
219
|
+
|
|
220
|
+
return string + '}'
|
|
221
|
+
|
|
222
|
+
def has_mdb_prop_configs(self, msg):
|
|
223
|
+
if not self.has_path(msg):
|
|
224
|
+
return False
|
|
225
|
+
|
|
226
|
+
for (_, intf_msg) in msg['interfaces'].items():
|
|
227
|
+
if self.has_properties(intf_msg):
|
|
228
|
+
return True
|
|
229
|
+
|
|
230
|
+
return False
|
|
231
|
+
|
|
232
|
+
def get_mdb_prop_configs(self, msg):
|
|
233
|
+
string = '{'
|
|
234
|
+
path_privilege = msg.get("privilege", [])
|
|
235
|
+
for (interface, intf_msg) in msg['interfaces'].items():
|
|
236
|
+
if not self.has_properties(intf_msg):
|
|
237
|
+
continue
|
|
238
|
+
interface_privilege = intf_msg.get("privilege", [])
|
|
239
|
+
intf_name = self.get_intf_name(interface, intf_msg)
|
|
240
|
+
for (prop, prop_config) in intf_msg['properties'].items():
|
|
241
|
+
prop_config["default_value"] = self.get_mdb_prop_default_value(intf_name, prop, prop_config)
|
|
242
|
+
prop_config["validator"] = f"{self.get_intf_type(intf_name)}.{prop}"
|
|
243
|
+
property_read_privilege = prop_config.get("privilege", {}).get("read", [])
|
|
244
|
+
property_write_privilege = prop_config.get("privilege", {}).get("write", [])
|
|
245
|
+
r = list(set(path_privilege + interface_privilege + property_read_privilege))
|
|
246
|
+
w = list(set(path_privilege + interface_privilege + property_write_privilege))
|
|
247
|
+
if r or w:
|
|
248
|
+
prop_config["privilege_value"] = {"read": self.combine_privileges(r),
|
|
249
|
+
"write": self.combine_privileges(w)}
|
|
250
|
+
string += f"['{interface}'] = {self.convert_to_lua(intf_msg['properties'])},"
|
|
251
|
+
|
|
252
|
+
return string + '}'
|
|
253
|
+
|
|
254
|
+
def convert_methods(self, methods):
|
|
255
|
+
result = {}
|
|
256
|
+
for (method, method_config) in methods.items():
|
|
257
|
+
result[method] = {}
|
|
258
|
+
for (body, params) in method_config.items():
|
|
259
|
+
if body != 'req' and body != 'rsp':
|
|
260
|
+
result[method][body] = params
|
|
261
|
+
continue
|
|
262
|
+
result[method][body] = []
|
|
263
|
+
for (param, param_config) in params.items():
|
|
264
|
+
param_config["param"] = param
|
|
265
|
+
result[method][body].append(param_config)
|
|
266
|
+
return result
|
|
267
|
+
|
|
268
|
+
def convert_signals(self, signals):
|
|
269
|
+
result = {}
|
|
270
|
+
for (signal, signal_config) in signals.items():
|
|
271
|
+
result[signal] = []
|
|
272
|
+
for (param, param_config) in signal_config.items():
|
|
273
|
+
param_config["param"] = param
|
|
274
|
+
result[signal].append(param_config)
|
|
275
|
+
return result
|
|
276
|
+
|
|
277
|
+
def has_mdb_method_configs(self, msg):
|
|
278
|
+
if not self.has_path(msg):
|
|
279
|
+
return False
|
|
280
|
+
|
|
281
|
+
for (intf_name, intf_msg) in msg['interfaces'].items():
|
|
282
|
+
if intf_name == OBJECT_PROPERTIES_INTERFACE:
|
|
283
|
+
continue
|
|
284
|
+
if self.has_methods(intf_msg):
|
|
285
|
+
return True
|
|
286
|
+
|
|
287
|
+
return False
|
|
288
|
+
|
|
289
|
+
def has_private_method_configs(self, msg):
|
|
290
|
+
return self.has_methods(msg)
|
|
291
|
+
|
|
292
|
+
def fill_method_validator(self, msg_type, methods, privileges):
|
|
293
|
+
for method, method_config in methods.items():
|
|
294
|
+
method_privilege = method_config.get("privilege", [])
|
|
295
|
+
p = list(set(privileges + method_privilege))
|
|
296
|
+
if p:
|
|
297
|
+
method_config["privilege_value"] = self.combine_privileges(p)
|
|
298
|
+
if "featureTag" in method_config:
|
|
299
|
+
method_config["feature"] = method_config["featureTag"]
|
|
300
|
+
method_config["req_type"] = msg_type + "." + method + "Req"
|
|
301
|
+
method_config["rsp_type"] = msg_type + "." + method + "Rsp"
|
|
302
|
+
|
|
303
|
+
def get_mdb_method_configs(self, msg):
|
|
304
|
+
string = '{'
|
|
305
|
+
path_privilege = msg.get("privilege", [])
|
|
306
|
+
for (interface, intf_msg) in msg['interfaces'].items():
|
|
307
|
+
if interface == OBJECT_PROPERTIES_INTERFACE:
|
|
308
|
+
continue
|
|
309
|
+
interface_privilege = intf_msg.get("privilege", [])
|
|
310
|
+
if self.has_methods(intf_msg):
|
|
311
|
+
intf_name = self.get_intf_name(interface, intf_msg)
|
|
312
|
+
self.fill_method_validator(self.get_intf_type(intf_name), intf_msg["methods"],
|
|
313
|
+
list(set(path_privilege + interface_privilege)))
|
|
314
|
+
methods = self.convert_methods(intf_msg['methods'])
|
|
315
|
+
string += "['" + str(interface) + "'] = " + self.convert_to_lua(methods) + ","
|
|
316
|
+
return string + '}'
|
|
317
|
+
|
|
318
|
+
def get_private_method_configs(self, class_name, msg):
|
|
319
|
+
self.fill_method_validator(self.get_class_type(class_name), msg['methods'], [])
|
|
320
|
+
methods = self.convert_methods(msg["methods"])
|
|
321
|
+
return self.convert_to_lua(methods)
|
|
322
|
+
|
|
323
|
+
def has_mdb_signal_configs(self, msg):
|
|
324
|
+
if not self.has_path(msg):
|
|
325
|
+
return False
|
|
326
|
+
|
|
327
|
+
for (intf_name, intf_msg) in msg['interfaces'].items():
|
|
328
|
+
if intf_name == OBJECT_PROPERTIES_INTERFACE:
|
|
329
|
+
continue
|
|
330
|
+
if self.has_signals(intf_msg):
|
|
331
|
+
return True
|
|
332
|
+
|
|
333
|
+
return False
|
|
334
|
+
|
|
335
|
+
def get_mdb_signal_configs(self, msg):
|
|
336
|
+
string = '{'
|
|
337
|
+
for (interface, intf_msg) in msg['interfaces'].items():
|
|
338
|
+
if self.has_signals(intf_msg):
|
|
339
|
+
signals = self.convert_signals(intf_msg['signals'])
|
|
340
|
+
string += "['" + str(interface) + "'] = " + self.convert_to_lua(signals) + ","
|
|
341
|
+
|
|
342
|
+
return string + '}'
|
|
343
|
+
|
|
344
|
+
def has_alias(self, msg):
|
|
345
|
+
if not self.has_path(msg):
|
|
346
|
+
return False
|
|
347
|
+
|
|
348
|
+
for (_, intf_msg) in msg['interfaces'].items():
|
|
349
|
+
if not self.has_properties(intf_msg):
|
|
350
|
+
continue
|
|
351
|
+
|
|
352
|
+
for (_, prop_config) in intf_msg['properties'].items():
|
|
353
|
+
if 'alias' in prop_config:
|
|
354
|
+
return True
|
|
355
|
+
|
|
356
|
+
return False
|
|
357
|
+
|
|
358
|
+
def get_alias_map(self, msg):
|
|
359
|
+
result = {}
|
|
360
|
+
for (interface, intf_msg) in msg['interfaces'].items():
|
|
361
|
+
if not self.has_properties(intf_msg):
|
|
362
|
+
continue
|
|
363
|
+
|
|
364
|
+
for (prop, prop_config) in intf_msg['properties'].items():
|
|
365
|
+
if 'alias' in prop_config:
|
|
366
|
+
result[prop_config['alias']] = {"original_name": prop, "interface": interface}
|
|
367
|
+
|
|
368
|
+
return self.convert_to_lua(result)
|
|
369
|
+
|
|
370
|
+
def get_full_path(self, root, msg):
|
|
371
|
+
return self.convert_to_lua(self.deduplicate_path(self.convert_dynamic_params(self.get_path(root, msg))))
|
|
372
|
+
|
|
373
|
+
def get_interface_types(self, msg):
|
|
374
|
+
string = "{"
|
|
375
|
+
for (interface, intf_msg) in msg["interfaces"].items():
|
|
376
|
+
intf_name = self.get_intf_name(interface, intf_msg)
|
|
377
|
+
string += f"['{interface}'] = {self.get_intf_type(intf_name)},"
|
|
378
|
+
return string + "}"
|
|
379
|
+
|
|
380
|
+
def get_intf_name(self, interface, intf_msg):
|
|
381
|
+
slices = interface.split(".")
|
|
382
|
+
if "implement" in intf_msg:
|
|
383
|
+
return slices[-2] + slices[-1]
|
|
384
|
+
return Utils.get_unique_intf_name(interface)
|
|
385
|
+
|
|
386
|
+
def get_property_privilege(self, config):
|
|
387
|
+
result = {}
|
|
388
|
+
if 'privilege' not in config:
|
|
389
|
+
return result
|
|
390
|
+
|
|
391
|
+
for item, privileges in config['privilege'].items():
|
|
392
|
+
privilege = []
|
|
393
|
+
for priv in privileges:
|
|
394
|
+
privilege.append('privilege.' + priv)
|
|
395
|
+
|
|
396
|
+
result[item] = " | ".join(privilege)
|
|
397
|
+
|
|
398
|
+
return result
|
|
399
|
+
|
|
400
|
+
def get_class_type(self, class_name):
|
|
401
|
+
return Utils.camel_to_snake(class_name) + '_class_types'
|
|
402
|
+
|
|
403
|
+
def get_class_types(self, project_name, root):
|
|
404
|
+
types = {}
|
|
405
|
+
for (class_name, msg) in root.items():
|
|
406
|
+
if not msg.get('properties', {}) and not msg.get('methods', {}):
|
|
407
|
+
continue
|
|
408
|
+
|
|
409
|
+
if msg.get('properties', {}):
|
|
410
|
+
if any(('default' in prop_config and prop_config.get(BASE_TYPE, {}) == 'Enum' and \
|
|
411
|
+
prop_config["$ref"].startswith("types.json")) for prop_config in msg['properties'].values()):
|
|
412
|
+
type_json_type = 'types'
|
|
413
|
+
types[type_json_type] = f"local {type_json_type} = require 'class.types.types'\n"
|
|
414
|
+
|
|
415
|
+
c_type = self.get_class_type(class_name)
|
|
416
|
+
if project_name != 'dft' and project_name != 'debug':
|
|
417
|
+
types[c_type] = f"local {c_type} = require 'class.types.{class_name}'\n"
|
|
418
|
+
else:
|
|
419
|
+
types[c_type] = f"local {c_type} = require '{project_name}.class.types.{class_name}'\n"
|
|
420
|
+
return types
|
|
421
|
+
|
|
422
|
+
def get_intf_type(self, intf_name):
|
|
423
|
+
return Utils.camel_to_snake(intf_name) + '_intf_types'
|
|
424
|
+
|
|
425
|
+
def get_intf_types(self, project_name, root):
|
|
426
|
+
types = {}
|
|
427
|
+
for (_, msg) in root.items():
|
|
428
|
+
for (interface, intf_msg) in msg.get('interfaces', {}).items():
|
|
429
|
+
intf_name = self.get_intf_name(interface, intf_msg)
|
|
430
|
+
intf_type = self.get_intf_type(intf_name)
|
|
431
|
+
types[intf_type] = f"local {intf_type} = require '{project_name}.json_types.{intf_name}'\n"
|
|
432
|
+
return types
|
|
433
|
+
|
|
434
|
+
def render_types(self, project_name, root):
|
|
435
|
+
types = {}
|
|
436
|
+
types.update(self.get_class_types(project_name, root))
|
|
437
|
+
types.update(self.get_intf_types(project_name, root))
|
|
438
|
+
|
|
439
|
+
string = ''
|
|
440
|
+
for _, value in types.items():
|
|
441
|
+
string += value
|
|
442
|
+
return string
|
|
443
|
+
|
|
444
|
+
def collect_features(self, intf_msg, features):
|
|
445
|
+
for method_config in intf_msg.get('methods', {}).values():
|
|
446
|
+
if "featureTag" in method_config:
|
|
447
|
+
features.add(method_config["featureTag"])
|
|
448
|
+
|
|
449
|
+
def get_features(self, root):
|
|
450
|
+
features = set()
|
|
451
|
+
if "private" in root:
|
|
452
|
+
self.collect_features(root["private"], features)
|
|
453
|
+
for msg in root.values():
|
|
454
|
+
for intf_msg in msg.get('interfaces', {}).values():
|
|
455
|
+
self.collect_features(intf_msg, features)
|
|
456
|
+
return sorted(list(features))
|
|
457
|
+
|
|
458
|
+
Factory().register("v1/templates/apps/model.lua.mako", ConsistencyModelLuaUtils)
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
${make_header('lua')}
|
|
2
|
+
local privilege = require 'mc.privilege'
|
|
3
|
+
% if render_utils.get_features(root):
|
|
4
|
+
require 'mc.plugin.loader'.load()
|
|
5
|
+
% for feature in render_utils.get_features(root):
|
|
6
|
+
local ${feature} = require '${project_name}.features.${feature}'.get_instance()
|
|
7
|
+
% endfor
|
|
8
|
+
% endif
|
|
9
|
+
|
|
10
|
+
${render_utils.render_types(project_name, root)}
|
|
11
|
+
|
|
12
|
+
local classes = {}
|
|
13
|
+
|
|
14
|
+
% for (class_name, msg) in root.items():
|
|
15
|
+
|
|
16
|
+
classes.${class_name} = {
|
|
17
|
+
% if render_utils.has_table_name(msg):
|
|
18
|
+
['table_name'] = '${msg['tableName']}',
|
|
19
|
+
% endif
|
|
20
|
+
% if render_utils.has_alias(msg):
|
|
21
|
+
['alias_map'] = ${render_utils.get_alias_map(msg)},
|
|
22
|
+
% endif
|
|
23
|
+
% if render_utils.has_prop_configs(msg):
|
|
24
|
+
['prop_configs'] = ${render_utils.get_prop_configs(class_name, msg)},
|
|
25
|
+
% endif
|
|
26
|
+
% if render_utils.has_mdb_prop_configs(msg):
|
|
27
|
+
['mdb_prop_configs'] = ${render_utils.get_mdb_prop_configs(msg)},
|
|
28
|
+
% endif
|
|
29
|
+
% if render_utils.has_private_method_configs(msg):
|
|
30
|
+
['method_configs'] = ${render_utils.get_private_method_configs(class_name, msg)},
|
|
31
|
+
% endif
|
|
32
|
+
% if render_utils.has_mdb_method_configs(msg):
|
|
33
|
+
['mdb_method_configs'] = ${render_utils.get_mdb_method_configs(msg)},
|
|
34
|
+
% endif
|
|
35
|
+
% if render_utils.has_mdb_signal_configs(msg):
|
|
36
|
+
['mdb_signal_configs'] = ${render_utils.get_mdb_signal_configs(msg)},
|
|
37
|
+
% endif
|
|
38
|
+
% if render_utils.has_path(msg):
|
|
39
|
+
['path'] = ${render_utils.get_full_path(root, msg)},
|
|
40
|
+
% endif
|
|
41
|
+
% if render_utils.has_interfaces(msg):
|
|
42
|
+
['interface_types'] = ${render_utils.get_interface_types(msg)},
|
|
43
|
+
% endif
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
% endfor
|
|
47
|
+
|
|
48
|
+
% if render_utils.has_block_io(root):
|
|
49
|
+
M.block_io_classes = {
|
|
50
|
+
% for (class_name, msg) in root.items():
|
|
51
|
+
% if render_utils.has_path(msg):
|
|
52
|
+
% for (interface, intf_msg) in msg['interfaces'].items():
|
|
53
|
+
% if interface == 'bmc.kepler.Chip.BlockIO':
|
|
54
|
+
'${class_name}',
|
|
55
|
+
% endif
|
|
56
|
+
%endfor
|
|
57
|
+
% endif
|
|
58
|
+
% endfor
|
|
59
|
+
}
|
|
60
|
+
% endif
|
|
61
|
+
|
|
62
|
+
return {classes = classes${", block_io_classes = block_io_classes" if render_utils.has_block_io(root) else ""}}
|