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.

Files changed (242) hide show
  1. bmcgo/__init__.py +12 -0
  2. bmcgo/bmcgo.py +22 -0
  3. bmcgo/bmcgo_config.py +176 -0
  4. bmcgo/cli/__init__.py +10 -0
  5. bmcgo/cli/cli.py +584 -0
  6. bmcgo/codegen/__init__.py +14 -0
  7. bmcgo/codegen/c/__init__.py +9 -0
  8. bmcgo/codegen/c/annotation.py +52 -0
  9. bmcgo/codegen/c/argument.py +42 -0
  10. bmcgo/codegen/c/codegen.py +153 -0
  11. bmcgo/codegen/c/comment.py +22 -0
  12. bmcgo/codegen/c/ctype_defination.py +353 -0
  13. bmcgo/codegen/c/helper.py +87 -0
  14. bmcgo/codegen/c/interface.py +63 -0
  15. bmcgo/codegen/c/method.py +82 -0
  16. bmcgo/codegen/c/property.py +180 -0
  17. bmcgo/codegen/c/renderer.py +21 -0
  18. bmcgo/codegen/c/signal.py +64 -0
  19. bmcgo/codegen/c/template/client.c.mako +145 -0
  20. bmcgo/codegen/c/template/client.h.mako +36 -0
  21. bmcgo/codegen/c/template/interface.c.mako +0 -0
  22. bmcgo/codegen/c/template/interface.introspect.xml.mako +99 -0
  23. bmcgo/codegen/c/template/micro_component.c.mako +32 -0
  24. bmcgo/codegen/c/template/public.c.mako +228 -0
  25. bmcgo/codegen/c/template/public.h.mako +128 -0
  26. bmcgo/codegen/c/template/server.c.mako +104 -0
  27. bmcgo/codegen/c/template/server.h.mako +36 -0
  28. bmcgo/codegen/lua/.lua-format +7 -0
  29. bmcgo/codegen/lua/Makefile +101 -0
  30. bmcgo/codegen/lua/__init__.py +9 -0
  31. bmcgo/codegen/lua/codegen.py +171 -0
  32. bmcgo/codegen/lua/proto/Makefile +87 -0
  33. bmcgo/codegen/lua/proto/ipmi_types.proto +17 -0
  34. bmcgo/codegen/lua/proto/types.proto +52 -0
  35. bmcgo/codegen/lua/script/check_intfs.py +161 -0
  36. bmcgo/codegen/lua/script/dto/__init__.py +11 -0
  37. bmcgo/codegen/lua/script/dto/exception.py +53 -0
  38. bmcgo/codegen/lua/script/dto/kepler_abstract.py +47 -0
  39. bmcgo/codegen/lua/script/dto/options.py +33 -0
  40. bmcgo/codegen/lua/script/dto/print_simple.py +19 -0
  41. bmcgo/codegen/lua/script/dto/redfish_api.py +241 -0
  42. bmcgo/codegen/lua/script/dto/url_route.py +195 -0
  43. bmcgo/codegen/lua/script/gen_db_json.py +444 -0
  44. bmcgo/codegen/lua/script/gen_depends.py +89 -0
  45. bmcgo/codegen/lua/script/gen_entry.py +263 -0
  46. bmcgo/codegen/lua/script/gen_feature_json.py +156 -0
  47. bmcgo/codegen/lua/script/gen_historical_local_db_json.py +88 -0
  48. bmcgo/codegen/lua/script/gen_intf_json.py +261 -0
  49. bmcgo/codegen/lua/script/gen_intf_rpc_json.py +575 -0
  50. bmcgo/codegen/lua/script/gen_ipmi_json.py +485 -0
  51. bmcgo/codegen/lua/script/gen_mdb_json.py +117 -0
  52. bmcgo/codegen/lua/script/gen_rpc_msg_json.py +487 -0
  53. bmcgo/codegen/lua/script/gen_schema.py +302 -0
  54. bmcgo/codegen/lua/script/ipmi_types_pb2.py +135 -0
  55. bmcgo/codegen/lua/script/loader/__init__.py +11 -0
  56. bmcgo/codegen/lua/script/loader/file_utils.py +33 -0
  57. bmcgo/codegen/lua/script/loader/kepler_abstract_collect.py +79 -0
  58. bmcgo/codegen/lua/script/loader/kepler_abstract_loader.py +47 -0
  59. bmcgo/codegen/lua/script/loader/redfish_loader.py +127 -0
  60. bmcgo/codegen/lua/script/lua_format.py +62 -0
  61. bmcgo/codegen/lua/script/mds_util.py +385 -0
  62. bmcgo/codegen/lua/script/merge_model.py +330 -0
  63. bmcgo/codegen/lua/script/merge_proto_algo.py +85 -0
  64. bmcgo/codegen/lua/script/proto_loader.py +47 -0
  65. bmcgo/codegen/lua/script/proto_plugin.py +140 -0
  66. bmcgo/codegen/lua/script/redfish_source_tree.py +118 -0
  67. bmcgo/codegen/lua/script/render_utils/__init__.py +38 -0
  68. bmcgo/codegen/lua/script/render_utils/base.py +25 -0
  69. bmcgo/codegen/lua/script/render_utils/client_lua.py +98 -0
  70. bmcgo/codegen/lua/script/render_utils/controller_lua.py +71 -0
  71. bmcgo/codegen/lua/script/render_utils/db_lua.py +224 -0
  72. bmcgo/codegen/lua/script/render_utils/error_lua.py +185 -0
  73. bmcgo/codegen/lua/script/render_utils/factory.py +52 -0
  74. bmcgo/codegen/lua/script/render_utils/ipmi_lua.py +159 -0
  75. bmcgo/codegen/lua/script/render_utils/ipmi_message_lua.py +24 -0
  76. bmcgo/codegen/lua/script/render_utils/mdb_lua.py +177 -0
  77. bmcgo/codegen/lua/script/render_utils/mdb_register.py +215 -0
  78. bmcgo/codegen/lua/script/render_utils/message_lua.py +26 -0
  79. bmcgo/codegen/lua/script/render_utils/messages_lua.py +156 -0
  80. bmcgo/codegen/lua/script/render_utils/model_lua.py +485 -0
  81. bmcgo/codegen/lua/script/render_utils/old_model_lua.py +429 -0
  82. bmcgo/codegen/lua/script/render_utils/plugin_lua.py +38 -0
  83. bmcgo/codegen/lua/script/render_utils/redfish_proto.py +86 -0
  84. bmcgo/codegen/lua/script/render_utils/request_lua.py +76 -0
  85. bmcgo/codegen/lua/script/render_utils/service_lua.py +130 -0
  86. bmcgo/codegen/lua/script/render_utils/utils_message_lua.py +125 -0
  87. bmcgo/codegen/lua/script/render_utils/validate_lua.py +221 -0
  88. bmcgo/codegen/lua/script/sep_ipmi_message_cmds.py +217 -0
  89. bmcgo/codegen/lua/script/template.py +166 -0
  90. bmcgo/codegen/lua/script/types_pb2.py +516 -0
  91. bmcgo/codegen/lua/script/utils.py +663 -0
  92. bmcgo/codegen/lua/script/validate.py +80 -0
  93. bmcgo/codegen/lua/script/yaml_to_json.py +73 -0
  94. bmcgo/codegen/lua/templates/Makefile +114 -0
  95. bmcgo/codegen/lua/templates/apps/Makefile +261 -0
  96. bmcgo/codegen/lua/templates/apps/Makefile.mdb.mk +64 -0
  97. bmcgo/codegen/lua/templates/apps/app.lua.mako +19 -0
  98. bmcgo/codegen/lua/templates/apps/class.lua.mako +35 -0
  99. bmcgo/codegen/lua/templates/apps/client.lua.mako +429 -0
  100. bmcgo/codegen/lua/templates/apps/controller.lua.mako +276 -0
  101. bmcgo/codegen/lua/templates/apps/datas.lua.mako +8 -0
  102. bmcgo/codegen/lua/templates/apps/db.lua.mako +89 -0
  103. bmcgo/codegen/lua/templates/apps/entry.lua.mako +128 -0
  104. bmcgo/codegen/lua/templates/apps/feature.lua.mako +37 -0
  105. bmcgo/codegen/lua/templates/apps/generate_route.mako +25 -0
  106. bmcgo/codegen/lua/templates/apps/impl_feature.lua.mako +72 -0
  107. bmcgo/codegen/lua/templates/apps/ipmi.lua.mako +97 -0
  108. bmcgo/codegen/lua/templates/apps/ipmi_cmd.lua.mako +18 -0
  109. bmcgo/codegen/lua/templates/apps/ipmi_message.lua.mako +36 -0
  110. bmcgo/codegen/lua/templates/apps/local_db.lua.mako +263 -0
  111. bmcgo/codegen/lua/templates/apps/main.lua.mako +25 -0
  112. bmcgo/codegen/lua/templates/apps/mc.lua.mako +77 -0
  113. bmcgo/codegen/lua/templates/apps/mdb.lua.mako +45 -0
  114. bmcgo/codegen/lua/templates/apps/mdb_interface.lua.mako +73 -0
  115. bmcgo/codegen/lua/templates/apps/message.lua.mako +38 -0
  116. bmcgo/codegen/lua/templates/apps/model.lua.mako +239 -0
  117. bmcgo/codegen/lua/templates/apps/orm_classes.lua.mako +16 -0
  118. bmcgo/codegen/lua/templates/apps/plugin.lua.mako +8 -0
  119. bmcgo/codegen/lua/templates/apps/redfish.proto.mako +47 -0
  120. bmcgo/codegen/lua/templates/apps/service.lua.mako +440 -0
  121. bmcgo/codegen/lua/templates/apps/signal_listen.lua.mako +19 -0
  122. bmcgo/codegen/lua/templates/apps/utils/default_intf.lua.mako +41 -0
  123. bmcgo/codegen/lua/templates/apps/utils/enum.mako +10 -0
  124. bmcgo/codegen/lua/templates/apps/utils/imports.mako +13 -0
  125. bmcgo/codegen/lua/templates/apps/utils/mdb_intf.lua.mako +25 -0
  126. bmcgo/codegen/lua/templates/apps/utils/mdb_obj.lua.mako +23 -0
  127. bmcgo/codegen/lua/templates/apps/utils/message.mako +160 -0
  128. bmcgo/codegen/lua/templates/apps/utils/request.lua.mako +59 -0
  129. bmcgo/codegen/lua/templates/apps/utils/validate.mako +83 -0
  130. bmcgo/codegen/lua/templates/errors.lua.mako +36 -0
  131. bmcgo/codegen/lua/templates/messages.lua.mako +32 -0
  132. bmcgo/codegen/lua/templates/new_app/.clang-format.mako +170 -0
  133. bmcgo/codegen/lua/templates/new_app/.gitignore.mako +26 -0
  134. bmcgo/codegen/lua/templates/new_app/CHANGELOG.md.mako +0 -0
  135. bmcgo/codegen/lua/templates/new_app/CMakeLists.txt.mako +29 -0
  136. bmcgo/codegen/lua/templates/new_app/Makefile.mako +25 -0
  137. bmcgo/codegen/lua/templates/new_app/README.md.mako +0 -0
  138. bmcgo/codegen/lua/templates/new_app/conanfile.py.mako +7 -0
  139. bmcgo/codegen/lua/templates/new_app/config.cfg.mako +6 -0
  140. bmcgo/codegen/lua/templates/new_app/mds/model.json.mako +3 -0
  141. bmcgo/codegen/lua/templates/new_app/mds/service.json.mako +21 -0
  142. bmcgo/codegen/lua/templates/new_app/permissions.ini.mako +16 -0
  143. bmcgo/codegen/lua/templates/new_app/src/lualib/${project_name}_app.lua.mako +16 -0
  144. bmcgo/codegen/lua/templates/new_app/src/service/main.lua.mako +25 -0
  145. bmcgo/codegen/lua/templates/new_app/test/integration/test_${project_name}.conf.mako +9 -0
  146. bmcgo/codegen/lua/templates/new_app/test/integration/test_${project_name}.lua.mako +47 -0
  147. bmcgo/codegen/lua/templates/new_app/test/unit/test.lua.mako +23 -0
  148. bmcgo/codegen/lua/templates/new_app/user_conf/rootfs/etc/systemd/system/${project_name}.service.mako +18 -0
  149. bmcgo/codegen/lua/templates/new_app/user_conf/rootfs/etc/systemd/system/multi-user.target.wants/${project_name}.service.link +1 -0
  150. bmcgo/component/__init__.py +10 -0
  151. bmcgo/component/analysis/analysis.py +183 -0
  152. bmcgo/component/analysis/build_deps.py +165 -0
  153. bmcgo/component/analysis/data_deps.py +333 -0
  154. bmcgo/component/analysis/dep-rules.json +912 -0
  155. bmcgo/component/analysis/dep_node.py +110 -0
  156. bmcgo/component/analysis/intf_deps.py +163 -0
  157. bmcgo/component/analysis/intf_validation.py +254 -0
  158. bmcgo/component/analysis/rule.py +211 -0
  159. bmcgo/component/analysis/smc_dfx_whitelist.json +11 -0
  160. bmcgo/component/analysis/sr_validation.py +391 -0
  161. bmcgo/component/build.py +222 -0
  162. bmcgo/component/component_dt_version_parse.py +348 -0
  163. bmcgo/component/component_helper.py +114 -0
  164. bmcgo/component/coverage/__init__.py +11 -0
  165. bmcgo/component/coverage/c_incremental_cov_report.template +53 -0
  166. bmcgo/component/coverage/incremental_cov.py +464 -0
  167. bmcgo/component/deploy.py +110 -0
  168. bmcgo/component/gen.py +169 -0
  169. bmcgo/component/package_info.py +236 -0
  170. bmcgo/component/template/conanbase.py.mako +278 -0
  171. bmcgo/component/template/conanfile.deploy.py.mako +40 -0
  172. bmcgo/component/test.py +947 -0
  173. bmcgo/errors.py +119 -0
  174. bmcgo/frame.py +217 -0
  175. bmcgo/functional/__init__.py +10 -0
  176. bmcgo/functional/analysis.py +96 -0
  177. bmcgo/functional/bmc_studio_action.py +98 -0
  178. bmcgo/functional/check.py +185 -0
  179. bmcgo/functional/conan_index_build.py +251 -0
  180. bmcgo/functional/config.py +332 -0
  181. bmcgo/functional/csr_build.py +724 -0
  182. bmcgo/functional/deploy.py +263 -0
  183. bmcgo/functional/diff.py +235 -0
  184. bmcgo/functional/fetch.py +235 -0
  185. bmcgo/functional/full_component.py +391 -0
  186. bmcgo/functional/maintain.py +381 -0
  187. bmcgo/functional/new.py +166 -0
  188. bmcgo/functional/schema_valid.py +111 -0
  189. bmcgo/functional/simple_sign.py +104 -0
  190. bmcgo/functional/upgrade.py +78 -0
  191. bmcgo/ipmigen/__init__.py +13 -0
  192. bmcgo/ipmigen/ctype_defination.py +82 -0
  193. bmcgo/ipmigen/ipmigen.py +309 -0
  194. bmcgo/ipmigen/template/cmd.c.mako +366 -0
  195. bmcgo/ipmigen/template/ipmi.c.mako +25 -0
  196. bmcgo/ipmigen/template/ipmi.h.mako +51 -0
  197. bmcgo/logger.py +176 -0
  198. bmcgo/misc.py +117 -0
  199. bmcgo/target/app.yml +17 -0
  200. bmcgo/target/install_sdk.yml +15 -0
  201. bmcgo/target/personal.yml +53 -0
  202. bmcgo/target/publish.yml +45 -0
  203. bmcgo/tasks/__init__.py +11 -0
  204. bmcgo/tasks/download_buildtools_hm.py +124 -0
  205. bmcgo/tasks/misc.py +15 -0
  206. bmcgo/tasks/task.py +354 -0
  207. bmcgo/tasks/task_build_conan.py +714 -0
  208. bmcgo/tasks/task_build_rootfs_img.py +595 -0
  209. bmcgo/tasks/task_buildgppbin.py +88 -0
  210. bmcgo/tasks/task_buildhpm_ext4.py +82 -0
  211. bmcgo/tasks/task_create_interface_config.py +122 -0
  212. bmcgo/tasks/task_download_buildtools.py +99 -0
  213. bmcgo/tasks/task_download_dependency.py +72 -0
  214. bmcgo/tasks/task_hpm_envir_prepare.py +112 -0
  215. bmcgo/tasks/task_packet_to_supporte.py +87 -0
  216. bmcgo/tasks/task_prepare.py +105 -0
  217. bmcgo/tasks/task_sign_and_pack_hpm.py +42 -0
  218. bmcgo/utils/__init__.py +10 -0
  219. bmcgo/utils/buffer.py +128 -0
  220. bmcgo/utils/combine_json_schemas.py +170 -0
  221. bmcgo/utils/component_post.py +54 -0
  222. bmcgo/utils/component_version_check.py +86 -0
  223. bmcgo/utils/config.py +1067 -0
  224. bmcgo/utils/fetch_component_code.py +232 -0
  225. bmcgo/utils/install_manager.py +61 -0
  226. bmcgo/utils/installations/__init__.py +10 -0
  227. bmcgo/utils/installations/base_installer.py +70 -0
  228. bmcgo/utils/installations/install_consts.py +30 -0
  229. bmcgo/utils/installations/install_plans/bingo.yml +11 -0
  230. bmcgo/utils/installations/install_workflow.py +50 -0
  231. bmcgo/utils/installations/installers/apt_installer.py +177 -0
  232. bmcgo/utils/installations/installers/pip_installer.py +46 -0
  233. bmcgo/utils/installations/version_util.py +100 -0
  234. bmcgo/utils/mapping_config_patch.py +443 -0
  235. bmcgo/utils/perf_analysis.py +114 -0
  236. bmcgo/utils/tools.py +704 -0
  237. bmcgo/worker.py +417 -0
  238. openubmc_bingo-0.5.240.dist-info/METADATA +30 -0
  239. openubmc_bingo-0.5.240.dist-info/RECORD +242 -0
  240. openubmc_bingo-0.5.240.dist-info/WHEEL +5 -0
  241. openubmc_bingo-0.5.240.dist-info/entry_points.txt +2 -0
  242. openubmc_bingo-0.5.240.dist-info/top_level.txt +1 -0
@@ -0,0 +1,429 @@
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
+ ALIAS = "alias"
24
+ PROPERTIES = "properties"
25
+ ENUM = "Enum"
26
+ DEFAULT = "default"
27
+
28
+
29
+ class OldModelLuaUtils(Base, Utils):
30
+ TYPE_TO_DEFAULT_MAP = {
31
+ "U8": 0,
32
+ "U16": 0,
33
+ "U32": 0,
34
+ "U64": 0,
35
+ "S8": 0,
36
+ "S16": 0,
37
+ "S32": 0,
38
+ "S64": 0,
39
+ "Double": 0,
40
+ 'String': "''",
41
+ "Boolean": 'false'
42
+ }
43
+
44
+ def __init__(self, data: dict, options: Options):
45
+ super().__init__(data, options=options)
46
+
47
+ @staticmethod
48
+ def has_path(msg):
49
+ return 'path' in msg
50
+
51
+ @staticmethod
52
+ def has_properties(msg):
53
+ return PROPERTIES in msg
54
+
55
+ @staticmethod
56
+ def make_class(classes):
57
+ string = '{\n'
58
+ for i in range(len(classes)):
59
+ string += ' ' + list(classes)[i] + ' = ' + list(
60
+ classes)[i] + ('\n' if (i == len(classes) - 1) else ',\n')
61
+ return string + '}\n'
62
+
63
+ @staticmethod
64
+ def has_methods(msg):
65
+ return 'methods' in msg
66
+
67
+ @staticmethod
68
+ def has_signals(msg):
69
+ return 'signals' in msg
70
+
71
+ @staticmethod
72
+ def has_table_name(msg):
73
+ return 'tableName' in msg
74
+
75
+ @staticmethod
76
+ def has_parent(msg):
77
+ return 'parent' in msg
78
+
79
+ @staticmethod
80
+ def has_arg_in(msg):
81
+ return 'req' in msg
82
+
83
+ @staticmethod
84
+ def get_arg_in_params(msg):
85
+ result = []
86
+ for (param, _) in msg.items():
87
+ result.append(param)
88
+ return result
89
+
90
+ @staticmethod
91
+ def get_intf_package_name(intf_name):
92
+ intfs = intf_name.split(".")
93
+ if intfs[-1] == "Default":
94
+ return intfs[-2] + intfs[-1]
95
+ return intfs[-1]
96
+
97
+ @staticmethod
98
+ def is_enum_array(prop_config):
99
+ return prop_config[BASE_TYPE] == 'Array' and ITEMS in prop_config and BASE_TYPE in prop_config[ITEMS] \
100
+ and prop_config[ITEMS][BASE_TYPE] == ENUM
101
+
102
+ def class_has_block_io(self, msg):
103
+ if self.has_path(msg):
104
+ for (interface, _) in msg['interfaces'].items():
105
+ if interface == 'bmc.kepler.Chip.BlockIO':
106
+ return True
107
+ return False
108
+
109
+ def has_block_io(self, root):
110
+ for (_, msg) in root.items():
111
+ if self.class_has_block_io(msg):
112
+ return True
113
+ return False
114
+
115
+ def convert_dict_to_lua_table(self, msg):
116
+ string = '{\n'
117
+ i = 1
118
+ for (prop, value) in msg.items():
119
+ if prop == "pattern":
120
+ string += f"['{prop}'] = [=[{value}]=],\n"
121
+ elif prop == "validator":
122
+ string += f"['{prop}'] = {value},\n"
123
+ else:
124
+ string += f"['{prop}'] = " + self.convert_to_lua(value) + ",\n"
125
+ i += 1
126
+ return string + '}'
127
+
128
+ def convert_to_lua(self, value):
129
+ if isinstance(value, str):
130
+ return "'" + value + "'"
131
+ elif isinstance(value, bool):
132
+ return 'true' if value else 'false'
133
+ elif isinstance(value, int) or isinstance(value, float):
134
+ return str(value)
135
+ elif isinstance(value, dict):
136
+ return self.convert_dict_to_lua_table(value)
137
+ elif isinstance(value, list):
138
+ string = "{"
139
+ for val in value:
140
+ string += self.convert_to_lua(val) + ","
141
+ string += "}"
142
+ return string
143
+ raise Exception("无效值类型")
144
+
145
+ def get_enum_value(self, project_name, ref, enum_type):
146
+ if ref.startswith("types.json"):
147
+ return "require 'class.types.types'." + \
148
+ ref.replace("types.json#/defs/", "") + "." + enum_type
149
+ elif ref.startswith("mdb://"):
150
+ spices = ref.split(".json#")
151
+ return "require '" + project_name + ".json_types." + \
152
+ Utils.get_unique_intf_name(spices[0].replace("/", ".")) + "'." + \
153
+ spices[1].replace("/defs/", "") + "." + enum_type
154
+ raise Exception("枚举引用定义错误")
155
+
156
+ def get_prop_default_value(self, project_name, class_name, prop, prop_config):
157
+ if project_name != 'dft' and project_name != 'debug':
158
+ if DEFAULT not in prop_config:
159
+ if BASE_TYPE in prop_config and prop_config[BASE_TYPE] == ENUM:
160
+ return f"require 'class.types.{class_name}'.{prop}.default[1]:value()"
161
+ else:
162
+ return f"require 'class.types.{class_name}'.{prop}.default[1]"
163
+ else:
164
+ if DEFAULT not in prop_config:
165
+ if BASE_TYPE in prop_config and prop_config[BASE_TYPE] == ENUM:
166
+ return f"require '{project_name}.class.types.{class_name}'.{prop}.default[1]:value()"
167
+ else:
168
+ return f"require '{project_name}.class.types.{class_name}'.{prop}.default[1]"
169
+
170
+ default = prop_config[DEFAULT]
171
+ if BASE_TYPE not in prop_config:
172
+ return self.convert_to_lua(default)
173
+
174
+ if prop_config[BASE_TYPE] == ENUM:
175
+ return self.get_enum_value(project_name, prop_config["$ref"], default) + ":value()"
176
+ elif self.is_enum_array(prop_config):
177
+ result = "{"
178
+ for enum_type in default:
179
+ result += self.get_enum_value(project_name, prop_config[ITEMS]["$ref"], enum_type) + ":value(),"
180
+ return result + "}"
181
+
182
+ return self.convert_to_lua(default)
183
+
184
+ def get_mdb_prop_default_value(self, project_name, intf_name, prop, prop_config):
185
+ pkg_name = "require '" + project_name + ".json_types." + intf_name + "'."
186
+ if DEFAULT not in prop_config:
187
+ if BASE_TYPE in prop_config and prop_config[BASE_TYPE] == ENUM:
188
+ return pkg_name + prop + ".default[1]:value()"
189
+ else:
190
+ return pkg_name + prop + ".default[1]"
191
+
192
+ default = prop_config[DEFAULT]
193
+ if BASE_TYPE not in prop_config:
194
+ return self.convert_to_lua(default)
195
+
196
+ if prop_config[BASE_TYPE] == ENUM:
197
+ return pkg_name + \
198
+ prop_config["$ref"].replace("#/defs/", "") + "." + default + ":value()"
199
+ elif self.is_enum_array(prop_config):
200
+ result = "{"
201
+ for enum_type in default:
202
+ result += pkg_name + prop_config[ITEMS]["$ref"].replace("#/defs/", "") + "." + enum_type + ":value(),"
203
+ return result + "}"
204
+
205
+ return self.convert_to_lua(default)
206
+
207
+ def get_path(self, root, msg):
208
+ if not self.has_path(msg):
209
+ return ''
210
+ if not self.has_parent(msg):
211
+ return msg['path']
212
+ return msg['path'].replace(':parent/', self.get_path(root, root[msg['parent']]) + ':parent/')
213
+
214
+ def convert_dynamic_params(self, msg):
215
+ match_obj = re.search("\$\{(.+?)\}", msg)
216
+ if match_obj is None:
217
+ return msg
218
+
219
+ return self.convert_dynamic_params(re.sub('\$\{(.+?)\}', ':' + match_obj.group(1), msg, 1))
220
+
221
+ def get_primary_key(self, msg):
222
+ if self.has_properties(msg):
223
+ for (prop, prop_config) in msg[PROPERTIES].items():
224
+ if "primaryKey" in prop_config:
225
+ return self.convert_to_lua({"field": prop, BASE_TYPE: prop_config.get(BASE_TYPE)})
226
+
227
+ if 'interfaces' not in msg:
228
+ return {}
229
+
230
+ for (_, intf_msg) in msg['interfaces'].items():
231
+ if not self.has_properties(intf_msg):
232
+ continue
233
+ for (prop, prop_config) in intf_msg[PROPERTIES].items():
234
+ if "primaryKey" not in prop_config:
235
+ continue
236
+ result = {"field": prop_config.get(ALIAS, prop), BASE_TYPE: prop_config.get(BASE_TYPE)}
237
+ return self.convert_to_lua(result)
238
+
239
+ return {}
240
+
241
+ def get_prop_configs(self, class_name, msg, project_name):
242
+ if not self.has_properties(msg):
243
+ return '{}'
244
+ if project_name != 'dft' and project_name != 'debug':
245
+ for (prop, prop_config) in msg[PROPERTIES].items():
246
+ prop_config["validator"] = "require 'class.types." + class_name + "'." + prop
247
+ else:
248
+ for (prop, prop_config) in msg[PROPERTIES].items():
249
+ prop_config["validator"] = "require '" + project_name + ".class.types." + class_name + "'." + prop
250
+ return self.convert_to_lua(msg[PROPERTIES])
251
+
252
+ def get_default_props(self, project_name, class_name, msg):
253
+ if not self.has_properties(msg):
254
+ return '{}'
255
+ string = '{'
256
+ for (prop, prop_config) in msg[PROPERTIES].items():
257
+ string += "['" + str(prop) + "'] = " + \
258
+ str(self.get_prop_default_value(project_name, class_name, prop, prop_config)) + ","
259
+
260
+ return string + '}'
261
+
262
+ def get_mdb_default_props(self, project_name, msg):
263
+ if not self.has_path(msg):
264
+ return '{}'
265
+ string = '{'
266
+ for (interface, intf_msg) in msg['interfaces'].items():
267
+ if not self.has_properties(intf_msg):
268
+ continue
269
+ intf_name = self.get_intf_name(interface, intf_msg)
270
+ for (prop, prop_config) in intf_msg[PROPERTIES].items():
271
+ string += "['" + str(prop_config.get(ALIAS, prop)) + "'] = " + \
272
+ str(self.get_mdb_prop_default_value(project_name, intf_name, prop, prop_config)) + ","
273
+
274
+ return string + '}'
275
+
276
+ def get_mdb_prop_configs(self, project_name, msg):
277
+ if not self.has_path(msg):
278
+ return '{}'
279
+ string = '{'
280
+ for (interface, intf_msg) in msg['interfaces'].items():
281
+ if not self.has_properties(intf_msg):
282
+ continue
283
+ intf_name = self.get_intf_name(interface, intf_msg)
284
+ for (prop, prop_config) in intf_msg[PROPERTIES].items():
285
+ prop_config["validator"] = f"require '{project_name}.json_types.{intf_name}'.{prop}"
286
+ string += f"['{interface}'] = {self.convert_to_lua(intf_msg[PROPERTIES])},"
287
+
288
+ return string + '}'
289
+
290
+ def convert_methods(self, methods):
291
+ result = {}
292
+ for (method, method_config) in methods.items():
293
+ result[method] = {}
294
+ for (body, params) in method_config.items():
295
+ if body != 'req' and body != 'rsp':
296
+ result[method][body] = params
297
+ continue
298
+ result[method][body] = []
299
+ for (param, param_config) in params.items():
300
+ param_config["param"] = param
301
+ result[method][body].append(param_config)
302
+ return result
303
+
304
+ def convert_signals(self, signals):
305
+ result = {}
306
+ for (signal, signal_config) in signals.items():
307
+ result[signal] = []
308
+ for (param, param_config) in signal_config.items():
309
+ param_config["param"] = param
310
+ result[signal].append(param_config)
311
+ return result
312
+
313
+ def get_mdb_method_configs(self, msg):
314
+ if not self.has_path(msg):
315
+ return '{}'
316
+ string = '{'
317
+ for (interface, intf_msg) in msg['interfaces'].items():
318
+ if self.has_methods(intf_msg):
319
+ methods = self.convert_methods(intf_msg['methods'])
320
+ string += "['" + str(interface) + "'] = " + self.convert_to_lua(methods) + ","
321
+
322
+ return string + '}'
323
+
324
+ def get_mdb_signal_configs(self, msg):
325
+ if not self.has_path(msg):
326
+ return '{}'
327
+
328
+ string = '{'
329
+ for (interface, intf_msg) in msg['interfaces'].items():
330
+ if self.has_signals(intf_msg):
331
+ signals = self.convert_signals(intf_msg['signals'])
332
+ string += "['" + str(interface) + "'] = " + self.convert_to_lua(signals) + ","
333
+
334
+ return string + '}'
335
+
336
+ def get_alias_map(self, msg):
337
+ result = {}
338
+ if self.has_properties(msg):
339
+ for (prop, prop_config) in msg[PROPERTIES].items():
340
+ if ALIAS in prop_config:
341
+ result[prop_config[ALIAS]] = {"original_name": prop}
342
+
343
+ if not self.has_path(msg):
344
+ return self.convert_to_lua(result)
345
+
346
+ for (interface, intf_msg) in msg['interfaces'].items():
347
+ if not self.has_properties(intf_msg):
348
+ continue
349
+
350
+ for (prop, prop_config) in intf_msg[PROPERTIES].items():
351
+ if ALIAS in prop_config:
352
+ result[prop_config[ALIAS]] = {"original_name": prop, "interface": interface}
353
+
354
+ return self.convert_to_lua(result)
355
+
356
+ def get_mdb_classes(self, root, msg):
357
+ if not self.has_path(msg):
358
+ return '{}'
359
+
360
+ return "mdb.get_class_obj('" + self.deduplicate_path(self.convert_dynamic_params(self.get_path(root, msg))) + \
361
+ "')"
362
+
363
+ def get_intf_name(self, interface, intf_msg):
364
+ slices = interface.split(".")
365
+ if "implement" in intf_msg:
366
+ return slices[-2] + slices[-1]
367
+ return Utils.get_unique_intf_name(interface)
368
+
369
+ def get_privilege(self, config):
370
+ if 'privilege' not in config:
371
+ return 'nil'
372
+ privilege = []
373
+ for priv in config['privilege']:
374
+ privilege.append('privilege.' + priv)
375
+ return " | ".join(privilege)
376
+
377
+ def get_privileges(self, configs):
378
+ privileges = {}
379
+ for prop, prop_config in configs.items():
380
+ if 'privilege' not in prop_config:
381
+ continue
382
+ privileges[prop] = self.get_privilege(prop_config)
383
+
384
+ string = '{\n'
385
+ for (prop, value) in privileges.items():
386
+ string += "['" + prop + "'] = " + value + ",\n"
387
+ return string + '}'
388
+
389
+ def get_property_privilege(self, config):
390
+ result = {}
391
+ if 'privilege' not in config:
392
+ return result
393
+
394
+ for item, privileges in config['privilege'].items():
395
+ privilege = []
396
+ for priv in privileges:
397
+ privilege.append('privilege.' + priv)
398
+
399
+ result[item] = " | ".join(privilege)
400
+
401
+ return result
402
+
403
+ def get_property_privileges(self, configs):
404
+ privileges = {}
405
+ for prop, prop_config in configs.items():
406
+ if 'privilege' not in prop_config:
407
+ continue
408
+ privileges[prop] = self.get_property_privilege(prop_config)
409
+
410
+ result = '{\n'
411
+ for (prop, value) in privileges.items():
412
+ priv = '{\n'
413
+ for item, privilege in value.items():
414
+ priv += "['" + item + "'] = " + privilege + ",\n"
415
+ priv += '}'
416
+
417
+ result += "['" + prop + "'] = " + priv + ",\n"
418
+ return result + '}'
419
+
420
+ def get_readonlys(self, configs):
421
+ readonlys = {}
422
+ for prop, prop_config in configs.items():
423
+ if 'readOnly' not in prop_config:
424
+ continue
425
+ readonlys[prop] = prop_config['readOnly']
426
+ return self.convert_to_lua(readonlys)
427
+
428
+
429
+ Factory().register("old_model.lua.mako", OldModelLuaUtils)
@@ -0,0 +1,38 @@
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 utils import Utils
14
+ from dto.options import Options
15
+ from render_utils.base import Base
16
+ from render_utils.factory import Factory
17
+
18
+
19
+ class PluginLuaUtils(Base, Utils):
20
+
21
+ def __init__(self, data: dict, options: Options):
22
+ super().__init__(data, options=options)
23
+
24
+ def collect_features(self, intf_msg, features):
25
+ for method_config in intf_msg.get('methods', {}).values():
26
+ if "featureTag" in method_config:
27
+ features.add(method_config["featureTag"])
28
+
29
+ def get_features(self, root):
30
+ features = set()
31
+ if "private" in root:
32
+ self.collect_features(root["private"], features)
33
+ for msg in root.values():
34
+ for intf_msg in msg.get('interfaces', {}).values():
35
+ self.collect_features(intf_msg, features)
36
+ return sorted(list(features))
37
+
38
+ Factory().register("plugin.lua.mako", PluginLuaUtils)
@@ -0,0 +1,86 @@
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 merge_proto_algo
14
+ from dto.options import Options
15
+ from render_utils.base import Base
16
+ from render_utils.factory import Factory
17
+
18
+
19
+ class RedfishProtoUtils(Base):
20
+ def __init__(self, data: dict, options: Options):
21
+ super().__init__(data, options=options)
22
+
23
+ @staticmethod
24
+ def replace_tag(field):
25
+ return field.translate(str.maketrans({'@': '', '#': '', '.': '_', '-': '_', '+': '_', ' ': '_'}))
26
+
27
+ @staticmethod
28
+ def get_class_name(file_name):
29
+ resource_string_fields = {'Id', 'Name', 'UUID', 'Description', 'VLANPriority', 'SubnetMask', 'MACAddress'}
30
+ should_in32_fields = {'VLANId', 'PrefixLength'}
31
+ target = file_name.split('/')[-1]
32
+ if target in resource_string_fields:
33
+ return 'string'
34
+ if target in should_in32_fields:
35
+ return 'int32'
36
+ if 'http' in file_name:
37
+ if 'Resource.json' in file_name:
38
+ return 'Resource.' + file_name.split('/')[-1]
39
+ elif 'odata' in file_name:
40
+ return 'string'
41
+ else:
42
+ return 'Common.ODataID'
43
+ return file_name.split('/')[-1]
44
+
45
+ @staticmethod
46
+ def get_lua_type(field, para_type):
47
+ type_map = {
48
+ 'array': 'repeated ' + field, 'boolean': 'bool', 'integer': 'int32',
49
+ 'number': 'int32', 'string': 'string'
50
+ }
51
+ return type_map.get(para_type, '')
52
+
53
+ @staticmethod
54
+ def attr_option_field(field):
55
+ option_list = []
56
+ for attr in field.keys():
57
+ value = field.get(attr)
58
+ if merge_proto_algo.is_attr_option(attr, value):
59
+ if isinstance(value, (bytes, str)):
60
+ option_list.append('''(%s) = "%s"''' % (attr, value))
61
+ else:
62
+ option_list.append("(%s) = %s" % (attr, ("%s" % value).lower()))
63
+ if not option_list:
64
+ return ""
65
+ return "[%s]" % (",".join(option_list))
66
+
67
+ def get_type(self, field, para_type):
68
+ all_type = ['array', 'boolean', 'integer', 'number', 'string']
69
+ ret = ''
70
+ if isinstance(para_type, list):
71
+ for sub_type in para_type:
72
+ if sub_type in all_type:
73
+ ret = self.get_lua_type(field, sub_type)
74
+ return ret
75
+ else:
76
+ ret = self.get_lua_type(field, para_type)
77
+ return ret
78
+
79
+ def get_file_name(self):
80
+ temp = self.data['$id'].split('/')[-1]
81
+ return temp.split('.')[0]
82
+
83
+
84
+
85
+
86
+ Factory().register("redfish.proto.mako", RedfishProtoUtils)
@@ -0,0 +1,76 @@
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 os
14
+ from typing import Dict
15
+
16
+ from dto.exception import UrlNotMatchException
17
+ from dto.kepler_abstract import KeplerAbstractMgr
18
+ from dto.options import Options
19
+ from dto.redfish_api import MessageSchemaMgr, MessageSchema, Property
20
+ from dto.url_route import UrlRouteDict
21
+ from loader import kepler_abstract_loader
22
+ from loader.redfish_loader import RedfishLoader
23
+ from render_utils.factory import Factory
24
+ from render_utils.base import Base
25
+
26
+
27
+ class RequestLua:
28
+ def __init__(self, msg_mgr: MessageSchemaMgr, abstract_mgr: KeplerAbstractMgr, kepler_msg_mgr: MessageSchemaMgr):
29
+ self.msg_mgr = msg_mgr
30
+ self.abstract_mgr = abstract_mgr
31
+ self.msg_route_map: Dict[str, UrlRouteDict] = {}
32
+ self.kepler_msg_mgr: MessageSchemaMgr = kepler_msg_mgr
33
+
34
+ def get(self, message_name: str) -> MessageSchema:
35
+ return self.msg_mgr.messages.get(message_name)
36
+
37
+ def related_objects(self, message_name: str) -> UrlRouteDict:
38
+ if self.msg_route_map.get(message_name):
39
+ return self.msg_route_map.get(message_name)
40
+ msg = self.get(message_name)
41
+ ret = self.msg_mgr.related_objects(msg)
42
+ self.msg_route_map.setdefault(message_name, ret)
43
+ return ret
44
+
45
+ def related_message(self, url_feature: str) -> MessageSchema:
46
+ abstract = self.abstract_mgr.get(url_feature)
47
+ if not abstract:
48
+ raise UrlNotMatchException(url_feature)
49
+ return self.kepler_msg_mgr.messages.get(abstract.class_type())
50
+
51
+ def inner_var(self, message_name: str, pt: Property) -> str:
52
+ url_feature = self.related_objects(message_name).url_dict.get(pt.url_route.inner_url_code()).url_feature
53
+ return self.related_message(url_feature).class_var_name()
54
+
55
+
56
+ class RequestLuaExt(RequestLua):
57
+ def __init__(self, data, options: Options):
58
+ self.data = data
59
+ loader = RedfishLoader(options.proto_json_root_path, options.source_file_path)
60
+ schema_mgr = MessageSchemaMgr()
61
+ interfaces = loader.interface_list(schema_mgr)
62
+ abstract_mgr = kepler_abstract_loader.load(os.path.join(options.kepler_root_path, "abstract.json"))
63
+ kepler_schema_mgr = kepler_abstract_loader.load_related_kepler_schemas(
64
+ options.kepler_root_path, interfaces, schema_mgr, abstract_mgr)
65
+ super().__init__(schema_mgr, abstract_mgr, kepler_schema_mgr)
66
+
67
+
68
+ class RequestLuaUtils(Base, RequestLuaExt):
69
+ def __init__(self, data: dict, options: Options):
70
+ super().__init__(data=data, options=options)
71
+
72
+ def name(self) -> str:
73
+ return "request.lua.mako"
74
+
75
+
76
+ Factory().register("request.lua.mako", RequestLuaUtils)