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,185 @@
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
+ class ErrorLuaUtils(Base, Utils):
22
+ LOG_MAP = {
23
+ "error": "log.ERROR",
24
+ "warning": "log.WARN",
25
+ "debug": "log.DEBUG",
26
+ "trace": "log.TRACE",
27
+ }
28
+
29
+ def __init__(self, data: dict, options: Options):
30
+ super().__init__(data, options=options)
31
+
32
+ @staticmethod
33
+ def get_error_name(code):
34
+ err = code.split(".")
35
+ if err == -1 or len(err) != 3: # 不满足3段式格式则抛错
36
+ raise Exception("无法满足 <xx.xx.xx> 的格式要求, %s" % code)
37
+ idx = code.rfind(".")
38
+ if idx == -1:
39
+ return code
40
+ return code[idx + 1:]
41
+
42
+ @staticmethod
43
+ def match_placeholders(msg):
44
+ return sorted(set([int(v) for v in re.findall(r"{(\d+)}", msg)]))
45
+
46
+ @staticmethod
47
+ def format_hex(data):
48
+ return "0x%02X" % data
49
+
50
+ @staticmethod
51
+ def format(msg):
52
+ return re.sub(r"{(\d+)}", r"%s", msg)
53
+
54
+ @staticmethod
55
+ def get_app_name(code):
56
+ name = code.split(".")
57
+ if name == -1:
58
+ return code
59
+ return name[1]
60
+
61
+ @staticmethod
62
+ def get_http_response(root, err):
63
+ ret = -1
64
+ if 'http_response' in err:
65
+ ret = err['http_response']
66
+ elif 'http_response' in root:
67
+ ret = root['http_response']
68
+ http_check_list = [
69
+ 400, 401, 402, 403, 404, 405, 406, 408, 409, 410, 426,
70
+ 429, 444, 451, 500, 501, 502, 503, 504, 505, 507
71
+ ]
72
+ if ret == -1: # 没有配置则返回nil
73
+ return 'nil'
74
+ if ret not in http_check_list: # 不在规定的返回码列表中则抛错
75
+ raise Exception("http 响应无效: %d" % ret)
76
+ return str(ret)
77
+
78
+ @staticmethod
79
+ def get_redfish_response(root, err):
80
+ if 'redfish_response' in err and len(err['redfish_response']) > 0:
81
+ return "\"{}\"".format(err['redfish_response'])
82
+ if 'redfish_response' in root and len(root['redfish_response']) > 0:
83
+ return "\"{}\"".format(root['redfish_response'])
84
+ return 'nil'
85
+
86
+ @staticmethod
87
+ def ret_check_ipmi(res):
88
+ generic_completion_codes = [
89
+ 0x00,
90
+ 0xC0,
91
+ 0xC1,
92
+ 0xC2,
93
+ 0xC3,
94
+ 0xC4,
95
+ 0xC5,
96
+ 0xC6,
97
+ 0xC7,
98
+ 0xC8,
99
+ 0xC9,
100
+ 0xCA,
101
+ 0xCB,
102
+ 0xCC,
103
+ 0xCD,
104
+ 0xCE,
105
+ 0xCF,
106
+ 0xD0,
107
+ 0xD1,
108
+ 0xD2,
109
+ 0xD3,
110
+ 0xD4,
111
+ 0xD5,
112
+ 0xD6,
113
+ 0xFF,
114
+ ]
115
+ device_specific_codes = range(0x01, 0x7E + 1)
116
+ command_specific_codes = range(0x80, 0xBE + 1)
117
+ if res == -1: # 没有配置则返回nil
118
+ return "nil"
119
+ valid = res in generic_completion_codes or res in device_specific_codes \
120
+ or res in command_specific_codes
121
+ if not valid: # 不在规定的返回码范围中则抛错
122
+ raise Exception("ipmi 响应无效: 0x%02X" % res)
123
+ return "0x%02X" % res
124
+
125
+ @staticmethod
126
+ def get_ipmi_response(root, err):
127
+ res = 0
128
+ if "ipmi_response" in err:
129
+ res = err["ipmi_response"]
130
+ elif "ipmi_response" in root:
131
+ res = root["ipmi_response"]
132
+ return ErrorLuaUtils.ret_check_ipmi(res)
133
+
134
+ @staticmethod
135
+ def get_ipmi_response_json(err):
136
+ res = 0
137
+ if "ipmi_response" in err:
138
+ res = int(err["ipmi_response"], 16)
139
+
140
+ return ErrorLuaUtils.ret_check_ipmi(res)
141
+
142
+ @staticmethod
143
+ def get_backtrace_level(root, err):
144
+ ret = 0
145
+ if "backtrace_level" in err:
146
+ ret = err["backtrace_level"]
147
+ elif "backtrace_level" in root:
148
+ ret = root["backtrace_level"]
149
+ if ret > 5: # 层级不超过5层
150
+ return 5
151
+ return ret
152
+
153
+ @staticmethod
154
+ def get_severity_err(err):
155
+ if "severity" in err and err["severity"] in ErrorLuaUtils.LOG_MAP:
156
+ return ErrorLuaUtils.LOG_MAP.get(err["severity"])
157
+ return "log.DEBUG" # 不在log_map映射表中则默认返回debug
158
+
159
+ @staticmethod
160
+ def get_severity(root, err):
161
+ if 'severity' in err and err['severity'] in ErrorLuaUtils.LOG_MAP:
162
+ return ErrorLuaUtils.LOG_MAP.get(err['severity'])
163
+ if 'severity' in root and root['severity'] in ErrorLuaUtils.LOG_MAP:
164
+ return ErrorLuaUtils.LOG_MAP.get(root['severity'])
165
+ return 'log.DEBUG' # 不在log_map映射表中则默认返回debug
166
+
167
+ def error_params(self, err):
168
+ s = self.params(err["message"])
169
+ if len(s) == 0:
170
+ return ""
171
+ return f", {s}"
172
+
173
+ def params(self, msg):
174
+ placeholders = self.match_placeholders(msg)
175
+ if len(placeholders) == 0:
176
+ return ""
177
+ elif len(placeholders) != placeholders[len(placeholders) - 1]:
178
+ raise RuntimeError("无效错误信息: `{}`, 未匹配到占位符".format(msg))
179
+ return ", ".join(["val" + str(v) for v in placeholders])
180
+
181
+ def get_function_name(self, code):
182
+ return Utils.camel_to_snake(self.get_error_name(code))
183
+
184
+
185
+ Factory().register("errors.lua.mako", ErrorLuaUtils)
@@ -0,0 +1,52 @@
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 typing import Optional
14
+
15
+ from dto.options import Options
16
+ from render_utils.base import Base
17
+
18
+
19
+ class NoRenderUtilsException(Exception):
20
+ pass
21
+
22
+
23
+ class Factory:
24
+ _instance = None
25
+ _has_init = False
26
+
27
+ @classmethod
28
+ def __new__(cls, *args, **kwargs):
29
+ if not isinstance(Factory._instance, Factory):
30
+ Factory._instance = object.__new__(cls)
31
+ return Factory._instance
32
+
33
+ def __init__(self):
34
+ if Factory._has_init:
35
+ return
36
+ self._utils_dict: dict = {}
37
+ Factory._has_init = True
38
+
39
+ def new_utils(self, template_name: str, data: dict, options: Options) -> Optional[Base]:
40
+ if not self._utils_dict.get(template_name):
41
+ return NoRenderUtilsException
42
+
43
+ if template_name == 'model.lua.mako' and options.version < 4:
44
+ template_name = 'old_model.lua.mako'
45
+
46
+ return self._utils_dict.get(template_name)(data, options)
47
+
48
+ def register(self, template_name: str, utils_type: type):
49
+ self._utils_dict.setdefault(template_name, utils_type)
50
+
51
+ def get(self, template_name: str):
52
+ return self._utils_dict.get(template_name)
@@ -0,0 +1,159 @@
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 dto.options import Options
14
+ from render_utils.base import Base
15
+ from render_utils.factory import Factory
16
+
17
+
18
+ class IpmiLuaUtils(Base):
19
+ def __init__(self, data: dict, options: Options):
20
+ super().__init__(data, options=options)
21
+
22
+ @staticmethod
23
+ def params(msg):
24
+ return ", ".join([p["name"] for p in msg["properties"]])
25
+
26
+ @staticmethod
27
+ def params_array(msg):
28
+ return (
29
+ "{" + ", ".join([("'" + p["name"] + "'") for p in msg["properties"]]) + "}"
30
+ )
31
+
32
+ @staticmethod
33
+ def is_req(t):
34
+ return t["name"] == "Req"
35
+
36
+ @staticmethod
37
+ def is_rsp(t):
38
+ return t["name"] == "Rsp"
39
+
40
+ @staticmethod
41
+ def get_option(ipmi, option):
42
+ return (
43
+ ipmi["options"][option]
44
+ if option in ipmi["options"] and ipmi["options"][option]
45
+ else ""
46
+ )
47
+
48
+ @staticmethod
49
+ def format_hex(data):
50
+ return "0x%02x" % data
51
+
52
+ @staticmethod
53
+ def wrap_json(msg):
54
+ return (
55
+ "{"
56
+ + (", ".join([(p["name"] + " = " + p["name"]) for p in msg["properties"]]))
57
+ + "}"
58
+ )
59
+
60
+ @staticmethod
61
+ def get_privilege(ipmi):
62
+ if len(ipmi['options']['privilege']) == 0:
63
+ return 'nil'
64
+ return " | ".join([("privilege." + p) for p in ipmi['options']['privilege']])
65
+
66
+ def req(self, ipmi):
67
+ result = None
68
+ if "nested_type" not in ipmi:
69
+ return result
70
+
71
+ req_list = [p for p in ipmi["nested_type"] if self.is_req(p)]
72
+ return req_list[0] if req_list else None
73
+
74
+ def rsp(self, ipmi):
75
+ result = None
76
+ if "nested_type" not in ipmi:
77
+ return result
78
+
79
+ rsp_list = [p for p in ipmi["nested_type"] if self.is_rsp(p)]
80
+ return rsp_list[0] if rsp_list else None
81
+
82
+ def req_params(self, ipmi):
83
+ req_info = self.req(ipmi)
84
+ return self.params(req_info) if req_info else ""
85
+
86
+ def req_properties(self, ipmi):
87
+ req_info = self.req(ipmi)
88
+ return req_info["properties"] if req_info else []
89
+
90
+ def rsp_properties(self, ipmi):
91
+ rsp_info = self.rsp(ipmi)
92
+ return rsp_info["properties"] if rsp_info else []
93
+
94
+ def req_json(self, ipmi):
95
+ req_info = self.req(ipmi)
96
+ return self.wrap_json(req_info) if req_info else ""
97
+
98
+ def get_netfn(self, ipmi):
99
+ if "net_fn" in ipmi["options"]:
100
+ return ipmi["options"]["net_fn"]
101
+ if "netfn" in ipmi["options"]:
102
+ return ipmi["options"]["netfn"]
103
+ return ""
104
+
105
+ def get_priority(self, ipmi):
106
+ if "prio" in ipmi["options"]:
107
+ return ipmi["options"]["prio"]
108
+ if "priority" in ipmi["options"]:
109
+ return ipmi["options"]["priority"]
110
+ return ""
111
+
112
+
113
+ def get_sys_locked_policy(self, ipmi):
114
+ if "sysLockedPolicy" in ipmi["options"]:
115
+ return ipmi["options"]["sysLockedPolicy"]
116
+ return "Allowed"
117
+
118
+ def is_generate_service(self, ipmi):
119
+ if "prio" in ipmi["options"] and ipmi["options"]["prio"]:
120
+ return True
121
+ if "priority" in ipmi["options"] and ipmi["options"]["priority"]:
122
+ return True
123
+ return False
124
+
125
+ def has_generate_service(self):
126
+ for ipmi in self.data["data"]:
127
+ if self.is_generate_service(ipmi):
128
+ return True
129
+
130
+ return False
131
+
132
+ def has_generate_client(self):
133
+ for ipmi in self.data["data"]:
134
+ if "prio" not in ipmi["options"] or not ipmi["options"]["prio"]:
135
+ return True
136
+ if "priority" not in ipmi["options"] or not ipmi["options"]["priority"]:
137
+ return True
138
+
139
+ return False
140
+
141
+ def get_channel(self, ipmi):
142
+ if "channel" in ipmi["options"] and ipmi["options"]["channel"]:
143
+ return ipmi["options"]["channel"]
144
+ else:
145
+ return self.data["options"]["default_channel"]
146
+
147
+ def get_restricted_channel(self, ipmi):
148
+ if "restricted_channels" in ipmi["options"] and ipmi["options"]["restricted_channels"]:
149
+ return '{' + ','.join([("'" + p + "'") for p in ipmi["options"]["restricted_channels"]]) + '}'
150
+ else:
151
+ return "{}"
152
+
153
+ def get_manufacturer(self, ipmi):
154
+ manufacturer = [-1, -1]
155
+ for i in range(2):
156
+ manufacturer[i] = ipmi["nested_type"][i]["manufacturer"]
157
+ return manufacturer
158
+
159
+ Factory().register("ipmi.lua.mako", IpmiLuaUtils)
@@ -0,0 +1,24 @@
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 dto.options import Options
14
+ from render_utils.base import Base
15
+ from render_utils.factory import Factory
16
+ from render_utils.utils_message_lua import UtilsMessageLua
17
+ from render_utils.validate_lua import ValidateLua
18
+
19
+
20
+ class IpmiMessageUtils(Base, ValidateLua, UtilsMessageLua):
21
+ def __init__(self, data: dict, options: Options):
22
+ super().__init__(data, options)
23
+
24
+ Factory().register("ipmi_message.lua.mako", IpmiMessageUtils)
@@ -0,0 +1,177 @@
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
+ from render_utils.utils_message_lua import UtilsMessageLua
20
+ from render_utils.validate_lua import ValidateLua
21
+
22
+
23
+ class MdbLuaUtils(Base, ValidateLua, UtilsMessageLua):
24
+ flag_names = ['const', 'emit_change', 'emit_no_value', 'explicit']
25
+
26
+ def __init__(self, data: dict, options: Options):
27
+ super().__init__(data, options=options)
28
+
29
+ @staticmethod
30
+ def message_type(msg_type):
31
+ if msg_type == ".google.protobuf.Empty":
32
+ return 'nil'
33
+ return msg_type[1:] if msg_type.startswith('.') else msg_type
34
+
35
+ @staticmethod
36
+ def filename(name):
37
+ if name.endswith("/index.proto"):
38
+ return name[:-len("/index.proto")]
39
+ elif name.endswith(".proto"):
40
+ return name[:-len(".proto")]
41
+ return name
42
+
43
+ @staticmethod
44
+ def count(params, name):
45
+ c = 0
46
+ for n in params:
47
+ if n == name:
48
+ c += 1
49
+ return c
50
+
51
+ @staticmethod
52
+ def has_path(msg):
53
+ return 'options' in msg and 'path' in msg['options']
54
+
55
+ @staticmethod
56
+ def has_interface(msg):
57
+ return 'options' in msg and 'interface' in msg['options']
58
+
59
+ @staticmethod
60
+ def make_methods(root, interface):
61
+ methods = []
62
+ if 'service' not in root:
63
+ return methods
64
+ for method in root['service']:
65
+ if 'options' in method and 'service_interface' in method['options'] and \
66
+ method['options']['service_interface'] == interface:
67
+ methods.append(method)
68
+ return methods
69
+
70
+ @staticmethod
71
+ def has_signals(msg):
72
+ return 'nested_type' in msg and len(msg['nested_type']) > 0
73
+
74
+ @staticmethod
75
+ def make_interface(msg):
76
+ return msg['options']['interface'] if 'options' in msg and 'interface' in msg['options'] else 'bmc.mdb.object'
77
+
78
+ @staticmethod
79
+ def realtime(prop):
80
+ return 'true' if 'realtime' in prop['options'] and prop['options']['realtime'] else 'false'
81
+
82
+ @staticmethod
83
+ def readonly_flag(prop):
84
+ return 'true' if 'readonly' in prop['options'] and prop['options']['readonly'] else 'false'
85
+
86
+ @staticmethod
87
+ def get_req(msg):
88
+ return 'nil' if msg['req'] == '.google.protobuf.Empty' else msg['req'][1:]
89
+
90
+ @staticmethod
91
+ def get_rsp(msg):
92
+ return 'nil' if msg['rsp'] == '.google.protobuf.Empty' else msg['rsp'][1:]
93
+
94
+ @staticmethod
95
+ def get_json_req(msg):
96
+ return 'nil' if msg['req'] == '.google.protobuf.Empty' else ('msg' + msg['req'])
97
+
98
+ @staticmethod
99
+ def get_json_rsp(msg):
100
+ return 'nil' if msg['rsp'] == '.google.protobuf.Empty' else ('msg' + msg['rsp'])
101
+
102
+ def err_module(self):
103
+ return "apps." + Utils(self.data, self.options).camel_to_snake(self.data['package']) + ".error"
104
+
105
+ def sig(self, msg_type):
106
+ msg = Utils(self.data, self.options).make_get_message(msg_type)
107
+ return "".join(
108
+ [Utils(self.data, self.options).do_type_to_dbus(p['type'], p['repeated']) for p in msg.get('properties')])
109
+
110
+ def cb_name(self, rpc):
111
+ return Utils(self.data, self.options).camel_to_snake('__on' + rpc['name'])
112
+
113
+ def rsp_message(self, rpc):
114
+ return self.message_type(rpc['rsp'])
115
+
116
+ def req_message(self, rpc):
117
+ return self.message_type(rpc['req'])
118
+
119
+ def props(self, msg_type):
120
+ msg = Utils(self.data, self.options).make_get_message(msg_type)
121
+ return msg.get('properties')
122
+
123
+ def get_flags(self, prop):
124
+ if 'options' not in prop:
125
+ return '0'
126
+ options = prop['options']
127
+ result = [f"'{name.upper()}'" for name in self.flag_names if name in options and options[name]]
128
+ if len(result) == 0:
129
+ return 'nil'
130
+ return f"{{{','.join(result)}}}"
131
+
132
+ def check_duplicate(self, params):
133
+ for name in params:
134
+ if self.count(params, name) > 1:
135
+ raise RuntimeError(f"重复的参数: {name}")
136
+
137
+ def make_path(self, msg):
138
+ path = msg['options']['path']
139
+ params = Utils.get_path_params(self, path)
140
+ if len(params) == 0:
141
+ return f"'{path}'"
142
+ result = []
143
+ for name in params:
144
+ s = path.partition(f':{name}')
145
+ result.append(f"'{s[0]}'")
146
+ result.append(name)
147
+ path = s[2]
148
+
149
+ return (f"{' .. '.join(result)}") if path == '' else (f"{' .. '.join(result)} .. '{path}'")
150
+
151
+ def default(self, prop):
152
+ if 'default' not in prop['options']:
153
+ return 'nil'
154
+ default_val = prop['options']['default']
155
+ type_name = prop['type']
156
+ if type_name == "string" or type_name == 'bytes':
157
+ default_val = f'"{default_val}"'
158
+ t = Utils(self.data, self.options).load_types(type_name)
159
+ if t and ('type' in t) and t['type'] == 'Enum':
160
+ default_val = f'{t["package"]}.{t["name"]}.' \
161
+ f'{Utils(self.data, self.options).enum_value_name(t["name"], default_val)}'
162
+ return default_val
163
+
164
+ def dependency(self, root):
165
+ if 'dependency' in root:
166
+ return [(pkg, self.filename(data['filename'])) for (pkg, data) in root['dependency'].items()]
167
+ return []
168
+
169
+ def has_msg(self, root):
170
+ for msg in root['data']:
171
+ if self.has_path(msg):
172
+ return True
173
+ return False
174
+
175
+
176
+ Factory().register("mdb.lua.mako", MdbLuaUtils)
177
+ Factory().register("mdb_interface.lua.mako", MdbLuaUtils)