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,130 @@
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
+ import re
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.validate_lua import ValidateLua
20
+ from render_utils.mdb_register import MdbRegister
21
+
22
+
23
+ class ServicesUtils(Base, ValidateLua, Utils, MdbRegister):
24
+ def __init__(self, data: dict, options: Options):
25
+ super().__init__(data, options=options)
26
+
27
+ @staticmethod
28
+ def message_type(t):
29
+ if t == ".google.protobuf.Empty":
30
+ return "nil"
31
+ return t[1:] if t.startswith(".") else t
32
+
33
+ @staticmethod
34
+ def count(params, name):
35
+ num = 0
36
+ for param in params:
37
+ if param == name:
38
+ num += 1
39
+ return num
40
+
41
+ @staticmethod
42
+ def contains_csr(prop_configs):
43
+ for prop_config in prop_configs.values():
44
+ for usage in prop_config.get("usage", []):
45
+ if usage == "CSR":
46
+ return True
47
+
48
+ return False
49
+
50
+ def err_module(self):
51
+ return (
52
+ "apps."
53
+ + Utils(self.data, self.options).camel_to_snake(self.data["package"])
54
+ + ".error"
55
+ )
56
+
57
+ def sig(self, msg_type):
58
+ msg = Utils(self.data, self.options).make_get_message(msg_type)
59
+ return "".join(
60
+ [
61
+ Utils(self.data, self.options).do_type_to_dbus(p["type"], p["repeated"])
62
+ for p in msg.get("properties")
63
+ ]
64
+ )
65
+
66
+ def params(self, msg_type):
67
+ msg = Utils(self.data, self.options).make_get_message(msg_type)
68
+ return ", ".join([p["name"] for p in msg.get("properties")])
69
+
70
+ def cb_name(self, rpc):
71
+ return Utils(self.data, self.options).camel_to_snake("__on" + rpc["name"])
72
+
73
+ def rsp_message(self, rpc):
74
+ return self.message_type(rpc["rsp"])
75
+
76
+ def req_message(self, rpc):
77
+ return self.message_type(rpc["req"])
78
+
79
+ def props(self, msg_type):
80
+ msg = Utils(self.data, self.options).make_get_message(msg_type)
81
+ return msg.get("properties")
82
+
83
+ def check_file_exist(self, file):
84
+ return os.path.exists(file)
85
+
86
+ def is_dynamic_obj(self, path):
87
+ return path.find(':') != -1
88
+
89
+ def make_path(self, path):
90
+ path = self.force_to_colon(path)
91
+ params = re.compile(r":([a-zA-Z_][0-9a-zA-Z_]+)").findall(path)
92
+ if len(params) == 0:
93
+ return f"'{path}'"
94
+ result = []
95
+ for name in params:
96
+ path_s = path.partition(f":{name}")
97
+ result.append(f"'{path_s[0]}'")
98
+ result.append(name)
99
+ path = path_s[2]
100
+
101
+ return (f"{' .. '.join(result)}") if path == '' else (f"{' .. '.join(result)} .. '{path}'")
102
+
103
+ def check_duplicate(self, params):
104
+ for name in params:
105
+ if self.count(params, name) > 1:
106
+ raise RuntimeError(f"重复参数: {name}")
107
+
108
+ def get_not_recover_tables(self, root):
109
+ not_recover_tables = {}
110
+ classes = {}
111
+ classes.update(root.get("class_require", {}))
112
+ classes.update(root.get("private_class_require", {}))
113
+ for class_data in classes.values():
114
+ data = class_data['data']
115
+ if "tableName" not in data:
116
+ continue
117
+
118
+ if self.contains_csr(data.get("properties", {})):
119
+ not_recover_tables[data["tableName"]] = True
120
+ continue
121
+
122
+ for intf_data in data.get("interfaces", {}).values():
123
+ if self.contains_csr(intf_data.get("properties", {})):
124
+ not_recover_tables[data["tableName"]] = True
125
+ break
126
+
127
+ return self.convert_to_lua(not_recover_tables)
128
+
129
+
130
+ Factory().register("service.lua.mako", ServicesUtils)
@@ -0,0 +1,125 @@
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
+
15
+
16
+ class UtilsMessageLua(Utils):
17
+
18
+ @staticmethod
19
+ def params(msg):
20
+ return ", ".join([p.get('original_name', p['name']) for p in msg['properties']])
21
+
22
+ @staticmethod
23
+ def get_group_names(names):
24
+ return ', '.join([f"'{name}'" for name in names])
25
+
26
+ @staticmethod
27
+ def get_group_names_for_set(names):
28
+ return ', '.join([f"{name}" for name in names])
29
+
30
+ @staticmethod
31
+ def get_group_names_for_join(names):
32
+ return ', '.join([f"body.{name}" for name in names])
33
+
34
+ @staticmethod
35
+ def construct_rename(prop, option_name):
36
+ return prop.get('original_name', prop['name']), prop['options'][option_name]
37
+
38
+ @staticmethod
39
+ def construct_group(prop, groups):
40
+ group_id = prop['options']['group']
41
+ if group_id in groups:
42
+ groups[group_id].append(prop['name'])
43
+ else:
44
+ groups[group_id] = [prop['name']]
45
+
46
+ def json_to_lua_value(self, val):
47
+ if isinstance(val, str):
48
+ return f'[=[{val}]=]'
49
+ if isinstance(val, bool):
50
+ return 'true' if val else 'false'
51
+ if isinstance(val, list):
52
+ result = '{'
53
+ for value in val:
54
+ result += f"{self.json_to_lua_value(value)},"
55
+ return result + '}'
56
+ if isinstance(val, int) or isinstance(val, float):
57
+ return str(val)
58
+ if isinstance(val, dict):
59
+ return self.convert_dict_to_lua_table(val)
60
+ return val
61
+
62
+ def with_default(self, p):
63
+ if 'options' in p and 'default' in p['options']:
64
+ default = p['options']['default']
65
+ if "is_enum" not in p or not p["is_enum"]:
66
+ if p['type'] == 'bool' and default:
67
+ return f"{p.get('original_name', p['name'])} == nil and true or \
68
+ obj.{p.get('original_name', p['name'])}"
69
+ else:
70
+ return f"{p.get('original_name', p['name'])} or {self.json_to_lua_value(default)}"
71
+
72
+ if p["repeated"]:
73
+ result = f"{p.get('original_name', p['name'])} or {{"
74
+ for default_var in default:
75
+ result += f"{p['type']}.{default_var},"
76
+ return result + "}"
77
+ else:
78
+ return f"{p.get('original_name', p['name'])} or {p['type']}.{default}"
79
+ else:
80
+ return p.get('original_name', p['name'])
81
+
82
+ def obj_construct(self, msg):
83
+ return "\n ".join([f"self.{p.get('original_name', p['name'])} = \
84
+ obj.{self.with_default(p)}" for p in msg['properties']])
85
+
86
+ def remove_props_construct(self, msg):
87
+ return "\n ".join(
88
+ [f"if errs.{p['name']} then obj.{self.with_default(p)} = nil end" for p in msg['properties']])
89
+
90
+ def unpack_prop_name(self, p):
91
+ if Utils(self.data, self.options).check_is_enum(p['type']):
92
+ return f"{p.get('original_name', p['name'])}"
93
+ elif Utils(self.data, self.options).check_is_message(self.data, p['type']):
94
+ if 'repeated' in p and p['repeated']:
95
+ return f"utils.unpack(raw, self.{p.get('original_name', p['name'])}, true)"
96
+ else:
97
+ return f"utils.unpack(raw, self.{p.get('original_name', p['name'])})"
98
+ return f"self.{p.get('original_name', p['name'])}"
99
+
100
+ def unpack(self, msg):
101
+ return ", ".join([self.unpack_prop_name(p) for p in msg['properties']])
102
+
103
+ def get_enums(self, msg, ):
104
+ return [p for p in msg['properties'] if Utils(self.data, self.options).check_is_enum(p['type'])]
105
+
106
+ def get_sub_type(self, msg):
107
+ return [p for p in msg['properties'] if Utils(self.data, self.options).check_is_message(self.data, p['type'])]
108
+
109
+ def get_rename_fields(self, msg):
110
+ return [self.construct_rename(prop, 'rename')
111
+ for prop in msg['properties']
112
+ if 'options' in prop and 'rename' in prop['options']]
113
+
114
+ def get_group_fields(self, msg):
115
+ groups = {}
116
+ [self.construct_group(prop, groups)
117
+ for prop in msg['properties']
118
+ if 'options' in prop and 'group' in prop['options']]
119
+ return groups
120
+
121
+ def get_groups(self, msg):
122
+ return ',\n '.join(['{' + self.get_group_names(v) + "}" for v in self.get_group_fields(msg).values()])
123
+
124
+ def is_routes(self, file):
125
+ return file.find("routes/") != -1
@@ -0,0 +1,221 @@
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
+ from utils import Utils
15
+
16
+
17
+ class ValidateLua(Utils):
18
+ readonly_fields = {
19
+ "odata_context",
20
+ "odata_etag",
21
+ "odata_id",
22
+ "odata_type",
23
+ "Actions",
24
+ "Links",
25
+ }
26
+ validate_need_readonly = {"Required", "Optional", "RequiredArray", "OptionalArray"}
27
+ type_default = {
28
+ "uint8" : "0",
29
+ "int8" : "0",
30
+ "int16" : "0",
31
+ "uint16" : "0",
32
+ "int32" : "0",
33
+ "uint32" : "0",
34
+ "uint64" : "0",
35
+ "int64" : "0",
36
+ "string" : "''",
37
+ "bytes" : "''",
38
+ "float" : "0",
39
+ "double" : "0",
40
+ "bool" : "false"
41
+ }
42
+
43
+ @staticmethod
44
+ def is_required(prop):
45
+ options = prop["options"]
46
+ return ("allow_null" not in options) or not options["allow_null"]
47
+
48
+ @staticmethod
49
+ def format_param(vv):
50
+ result = []
51
+ for p in vv[1]:
52
+ if isinstance(p, str):
53
+ if vv[0] == "regex":
54
+ result.append('[=[{}]=]'.format(p))
55
+ else:
56
+ result.append('"{}"'.format(p))
57
+ else:
58
+ result.append("nil" if p is None else str(p))
59
+
60
+ if vv[0] == "enum":
61
+ return "Enum", ["'', {" + ", ".join(result) + "}"]
62
+ return vv[0], result
63
+
64
+ @staticmethod
65
+ def proper_name(name, prefix):
66
+ if not prefix:
67
+ return name
68
+ return prefix + name
69
+
70
+ @staticmethod
71
+ def validate_name(name, prefix):
72
+ if not prefix:
73
+ return f"'{name}'"
74
+ return f"{prefix} .. '{name}'"
75
+
76
+ def get_struct_require(self, prop):
77
+ prop_type = prop["type"]
78
+ if not Utils(self.data, self.options).is_base_type(prop_type) and prop_type != 'Enum':
79
+ return {"type": prop_type, "repeated": prop["repeated"]}
80
+ return {}
81
+
82
+ def get_no_struct_require(self, prop):
83
+ prop_type = prop["type"]
84
+ params = [f'"{prop_type}"']
85
+ if not Utils(self.data, self.options).is_base_type(prop_type) and prop_type != 'Enum':
86
+ return []
87
+
88
+ if self.is_required(prop):
89
+ val = "RequiredArray" if prop["repeated"] else "Required"
90
+ else:
91
+ val = "OptionalArray" if prop["repeated"] else "Optional"
92
+ return [[val, params]]
93
+
94
+ def get_struct_requires(self, msg):
95
+ result = {}
96
+ if "properties" not in msg:
97
+ return result
98
+
99
+ for prop in msg["properties"]:
100
+ prop_type = prop["type"]
101
+ if not Utils(self.data, self.options).is_base_type(prop_type) and prop_type != 'Enum':
102
+ result[prop["name"]] = {"type": prop_type, "repeated": prop["repeated"]}
103
+ return result
104
+
105
+ def get_no_struct_requires(self, msg):
106
+ if "properties" not in msg:
107
+ return []
108
+
109
+ result = []
110
+ for prop in msg["properties"]:
111
+ prop_type = prop["type"]
112
+ params = [f'"{prop_type}"']
113
+ if not Utils(self.data, self.options).is_base_type(prop_type) and prop_type != 'Enum':
114
+ continue
115
+
116
+ if self.is_required(prop):
117
+ val = "RequiredArray" if prop["repeated"] else "Required"
118
+ else:
119
+ val = "OptionalArray" if prop["repeated"] else "Optional"
120
+ result.append((prop, [[val, params]]))
121
+
122
+ return result
123
+
124
+ def params1(self, var, msg):
125
+ if msg["type"] == "Dictionary":
126
+ return var
127
+
128
+ paras = []
129
+ if "properties" in msg:
130
+ for p in msg["properties"]:
131
+ paras.append(var + "." + p["name"])
132
+ return ", ".join(paras)
133
+
134
+ def get_requires(self, msg):
135
+ if "properties" not in msg:
136
+ return []
137
+
138
+ result = []
139
+ for prop in msg["properties"]:
140
+ prop_type = prop["type"]
141
+ params = [f'"{prop_type}"']
142
+
143
+ if self.is_required(prop):
144
+ val = "RequiredArray" if prop["repeated"] else "Required"
145
+ else:
146
+ val = "OptionalArray" if prop["repeated"] else "Optional"
147
+ result.append((prop, [[val, params]]))
148
+
149
+ return result
150
+
151
+ def get_descriptions(self, msg, intf_name):
152
+ pattern = r'^bmc\..*\.(Debug|Release)\..*$'
153
+ if not re.match(pattern, intf_name):
154
+ return ''
155
+
156
+ if "properties" not in msg:
157
+ return ''
158
+
159
+ count = 0
160
+ has_description = False
161
+ name = msg['name']
162
+ result = f'T{name}.descriptions = {{'
163
+ for prop in msg["properties"]:
164
+ if count != 0:
165
+ result += ", "
166
+ count += 1
167
+ if "description" in prop:
168
+ has_description = True
169
+ result += '[=[' + prop["description"] + ']=]'
170
+ else:
171
+ result += "nil"
172
+
173
+ return (result + '}') if has_description else ''
174
+
175
+ def get_default(self, required, type_str):
176
+ type_str = type_str.replace('"', '')
177
+ match_obj = re.search("(.+?)\[\]", type_str)
178
+ if match_obj is not None:
179
+ type_str = match_obj.group(1)
180
+ if type_str in self.type_default:
181
+ type_default = self.type_default[type_str]
182
+ return ("{}") if "Array" in required else type_default
183
+ return ("{}") if "Array" in required else (type_str + '.default')
184
+
185
+ def is_array(self, required):
186
+ return "true" if "Array" in required else "false"
187
+
188
+ def get_struct(self, type_str):
189
+ type_str = type_str.replace('"', '')
190
+ match_obj = re.search("(.+?)\[\]", type_str)
191
+ if match_obj is not None:
192
+ type_str = match_obj.group(1)
193
+ if type_str in self.type_default:
194
+ return "nil"
195
+ return type_str + ".struct"
196
+
197
+ def get_validates(self, msg):
198
+ if "properties" not in msg:
199
+ return []
200
+
201
+ result = []
202
+ for prop in msg["properties"]:
203
+ if "validate" not in prop["options"]:
204
+ continue
205
+
206
+ opt_validate = Utils(self.data, self.options).get_validate(
207
+ prop["options"]["validate"]
208
+ )
209
+
210
+ prop_result = [self.format_param(v) for v in opt_validate]
211
+ result.append((prop, prop_result))
212
+ return result
213
+
214
+ def readonly(self, validate_type, field, types, options):
215
+ if validate_type not in self.validate_need_readonly:
216
+ return ""
217
+ if field in self.readonly_fields or "Resource." in types:
218
+ return ", true"
219
+ if "readonly" in options:
220
+ return ", true"
221
+ return ", false"
@@ -0,0 +1,217 @@
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
+ import os
15
+ import sys
16
+ import json
17
+ import stat
18
+ import logging
19
+ import shutil
20
+ from typing import List, Dict
21
+ from bmcgo.utils.tools import Tools
22
+
23
+ tools = Tools("bmcgo_config")
24
+
25
+
26
+ def get_package_name(ipmi_json_filename: str) -> str:
27
+ """ 从ipmi.json中读取package名 """
28
+ with os.fdopen(os.open(ipmi_json_filename, os.O_RDONLY, stat.S_IRUSR), "r") as json_f:
29
+ ipmi_json_dict = json.load(json_f)
30
+ return ipmi_json_dict.get("package")
31
+
32
+
33
+ def get_cmd_names(ipmi_json_filename: str) -> List[str]:
34
+ """ 从ipmi.json中读取所有命令名 """
35
+ with os.fdopen(os.open(ipmi_json_filename, os.O_RDONLY, stat.S_IRUSR), "r") as json_f:
36
+ ipmi_json_dict = json.load(json_f)
37
+ cmds_dict = ipmi_json_dict.get("cmds")
38
+ return list(cmds_dict.keys())
39
+
40
+
41
+ def get_copyright_comments(lines: List[str]) -> List[str]:
42
+ """ 取出ipmi_message的copyright注释 """
43
+ comments_end = -1
44
+
45
+ # 找到copyright注释的结束位置
46
+ for i, line in enumerate(lines):
47
+ match_obj = re.search(f"local (.+) = require (.+)", line)
48
+ if match_obj:
49
+ comments_end = i
50
+ break
51
+
52
+ copyright_comments = lines[:comments_end]
53
+
54
+ return copyright_comments
55
+
56
+
57
+ def filter_out_cmds_requires(lines: List[str], package_name: str) -> List[str]:
58
+ """ 取出ipmi_message的require语句, 并从lines中删除 """
59
+ requires_end = -1
60
+ requires = []
61
+ remove_lines = []
62
+
63
+ # 找到require语句的结束位置
64
+ for i, line in enumerate(lines):
65
+ match_obj = re.search(f"local {package_name}Msg = ", line)
66
+ if match_obj:
67
+ requires_end = i
68
+ break
69
+
70
+ for i, line in enumerate(lines):
71
+ if i >= requires_end:
72
+ break
73
+ match_obj = re.search(f"local (.+) = require (.+)", line)
74
+ if match_obj:
75
+ remove_lines.append(i)
76
+ requires.append(line)
77
+
78
+ # 从lines中删除require语句
79
+ for i in reversed(remove_lines):
80
+ del lines[i]
81
+
82
+ return requires
83
+
84
+
85
+ def save_cmds_to(output_dir: str, ipmi_cmd_dict: Dict, package_name: str, requires: List[str],
86
+ copyright_comments: List[str]):
87
+ """ 将每个命令保存到output_dir目录单独的文件中 """
88
+ requires_s = ''.join(requires) # require语句
89
+ copyright_comments_s = ''.join(copyright_comments) # copyright注释
90
+ file_list = []
91
+
92
+ for cmd_name in ipmi_cmd_dict:
93
+ cmd_filename = os.path.join(output_dir, f"{cmd_name}.lua")
94
+ with os.fdopen(os.open(cmd_filename, os.O_WRONLY | os.O_CREAT | os.O_TRUNC,
95
+ stat.S_IWUSR | stat.S_IRUSR), 'w') as output_f:
96
+ code_prepend = f"\nlocal {cmd_name} = " + "{}\n\n" # declaration语句
97
+ code_append = f"\nreturn {cmd_name}" # return语句
98
+ code = copyright_comments_s + requires_s + code_prepend + ipmi_cmd_dict[cmd_name]['code'] + code_append
99
+ code = code.replace(f'{package_name}Msg', cmd_name)
100
+ output_f.write(code)
101
+ file_list.append(cmd_filename)
102
+ return file_list
103
+
104
+
105
+ def modify_ipmi_message_lines(lines: List[str], ipmi_cmd_dict: Dict, package_name: str, project_name: str):
106
+ """ 修改lines, 删除多余的命令信息, 添加require语句引用单独的命令文件 """
107
+ trim_start = -1
108
+ trim_end = -1
109
+
110
+ # 找到需要删除的首行和尾行
111
+ for i, line in enumerate(lines):
112
+ match_obj = re.search(f"local {package_name}Msg = ", line)
113
+ if match_obj:
114
+ trim_start = i
115
+ match_obj = re.search(f"return {package_name}Msg", line)
116
+ if match_obj:
117
+ trim_end = i
118
+
119
+ del lines[trim_start: trim_end]
120
+
121
+ # 添加require语句引用单独的命令文件
122
+ requires = [f"local {package_name}Msg = " + "{\n"]
123
+ for i, cmd_name in enumerate(ipmi_cmd_dict):
124
+ requires.append(f" {cmd_name}Req = (require '{project_name}.ipmi.cmds.{cmd_name}').{cmd_name}Req,\n")
125
+ if i == len(ipmi_cmd_dict) - 1:
126
+ requires.append(f" {cmd_name}Rsp = (require '{project_name}.ipmi.cmds.{cmd_name}').{cmd_name}Rsp\n")
127
+ else:
128
+ requires.append(f" {cmd_name}Rsp = (require '{project_name}.ipmi.cmds.{cmd_name}').{cmd_name}Rsp,\n")
129
+ requires.append("}\n")
130
+ requires.append("\n")
131
+
132
+ lines[:] = lines[:trim_start] + requires + lines[trim_start:]
133
+
134
+
135
+ def get_ipmi_cmd_dict(lines: List[str], cmd_names: List[str], package_name: str):
136
+ """ 读取lines, 生成并返回ipmi_cmd_dict """
137
+ ipmi_cmd_dict = {} # cmd_name -> {start: int, end: int, code: str}
138
+
139
+ for i, line in enumerate(lines):
140
+ match_obj = re.search(f"@class {package_name}.(.+)", line)
141
+ if match_obj:
142
+ cmd_name = match_obj.group(1)[:-3] # 最后三位是Rsp/Req
143
+ if cmd_name not in ipmi_cmd_dict:
144
+ ipmi_cmd_dict[cmd_name] = {
145
+ "start": i,
146
+ "end": -1,
147
+ "code": ''
148
+ }
149
+ for cmd_name in cmd_names:
150
+ found_cmd_end = (f'{package_name}Msg.{cmd_name}Req' in line) or (f'{package_name}Msg.{cmd_name}Rsp' in line)
151
+ if cmd_name in ipmi_cmd_dict and found_cmd_end:
152
+ ipmi_cmd_dict[cmd_name]['end'] = i
153
+ code_start = ipmi_cmd_dict[cmd_name].get('start', 0)
154
+ code_end = ipmi_cmd_dict[cmd_name].get('end', -1)
155
+ ipmi_cmd_dict[cmd_name]['code'] = ''.join(lines[code_start: code_end + 1])
156
+
157
+ return ipmi_cmd_dict
158
+
159
+
160
+ def sep_ipmi_message_cmds(ipmi_json_filename: str, ipmi_message_filename: str, output_dir: str, project_name: str,
161
+ lua_format: str):
162
+ """ 分离集中在ipmi_message.lua的命令到单独的文件 """
163
+ if not os.path.isdir(output_dir):
164
+ os.mkdir(output_dir)
165
+ else:
166
+ shutil.rmtree(output_dir)
167
+ os.mkdir(output_dir)
168
+
169
+ package_name = get_package_name(ipmi_json_filename)
170
+ cmd_names = get_cmd_names(ipmi_json_filename)
171
+ lines = []
172
+
173
+ # 读取ipmi_message文件到ipmi_cmd_dict(cmd_name -> {start: int, end: int, code: str})
174
+ with os.fdopen(os.open(ipmi_message_filename, os.O_RDONLY, stat.S_IRUSR), "r") as input_f:
175
+ lines = input_f.readlines()
176
+ ipmi_cmd_dict = get_ipmi_cmd_dict(lines, cmd_names, package_name)
177
+
178
+ copyright_comments = get_copyright_comments(lines)
179
+
180
+ requires = filter_out_cmds_requires(lines, package_name)
181
+
182
+ file_list = save_cmds_to(output_dir, ipmi_cmd_dict, package_name, requires, copyright_comments)
183
+
184
+ # 修改ipmi_message文件,引用分离开的单独的命令
185
+ modify_ipmi_message_lines(lines, ipmi_cmd_dict, package_name, project_name)
186
+ os.chmod(ipmi_message_filename, 0o666)
187
+ with os.fdopen(os.open(ipmi_message_filename, os.O_WRONLY | os.O_CREAT | os.O_TRUNC,
188
+ stat.S_IWUSR | stat.S_IRUSR), 'w') as output_f:
189
+ output_f.write(''.join(lines))
190
+ file_list.append(ipmi_message_filename)
191
+ for file_path in file_list:
192
+ if os.path.exists(lua_format):
193
+ tools.run_command(["python3", lua_format, file_path], command_echo=False)
194
+ os.chmod(file_path, 0o444)
195
+
196
+
197
+ def usage():
198
+ """ 输出脚本使用示例 """
199
+ logging.info("sep_ipmi_message.py <ipmi.json path> <ipmi_message.lua path> <output directory> <lua_format path>")
200
+
201
+
202
+ def main(args: List[str]):
203
+ if len(args) < 5:
204
+ usage()
205
+ return
206
+
207
+ ipmi_json_filename = args[0]
208
+ ipmi_message_filename = args[1]
209
+ output_dir = args[2]
210
+ project_name = args[3]
211
+ lua_format = args[4]
212
+
213
+ sep_ipmi_message_cmds(ipmi_json_filename, ipmi_message_filename, output_dir, project_name, lua_format)
214
+
215
+
216
+ if __name__ == "__main__":
217
+ main(sys.argv[1:])