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,127 @@
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 Set, List, Dict
15
+
16
+ from dto.exception import MessageParseException
17
+ from dto.redfish_api import MessageSchemaMgr, MessageSchema, MessageType, join_father_options, ALLOW_BASIC_TYPES, \
18
+ FatherFields
19
+ from loader.file_utils import load_json
20
+
21
+
22
+ def json_file_path(rel_path: str):
23
+ if not rel_path.endswith(".json"):
24
+ return f"{rel_path}.json"
25
+ return rel_path
26
+
27
+
28
+ class RedfishLoader:
29
+ def __init__(self, root_path: str, full_file_path: str, father_options_dict: Dict[str, dict] = None):
30
+ self.root_path: str = root_path
31
+ self.full_file_path: str = full_file_path
32
+ self.father_options_dict: Dict[str, dict] = father_options_dict
33
+ if self.father_options_dict is None:
34
+ self.father_options_dict = {}
35
+
36
+ @staticmethod
37
+ def _get_property_json(msg: dict, attr_name: str) -> dict:
38
+ for pt in msg.get("properties"):
39
+ if pt.get("name") == attr_name:
40
+ return pt
41
+ raise MessageParseException(f"在 {msg.get('package')}.{msg.get('name')} 中无法找到 {attr_name}")
42
+
43
+ @staticmethod
44
+ def _extend_property_options(index, msg, parsed_msg_list):
45
+ for pt in parsed_msg_list[index].properties:
46
+ pt_json = RedfishLoader._get_property_json(msg, pt.attr_name)
47
+ join_father_options(pt_json, msg.get("options"))
48
+ pt.url_route.merge_options(pt_json.get("options"))
49
+
50
+ def parse(self, schema_mgr: MessageSchemaMgr, parsed_file_set: Set[str] = None,
51
+ father_options: dict = None) -> List[MessageSchema]:
52
+ if parsed_file_set is None:
53
+ parsed_file_set = set()
54
+ json_data = load_json(self.full_file_path)
55
+ father_fields = FatherFields()
56
+ father_fields.father_options = father_options
57
+ interfaces = self._parse_data(json_data.get("data"), schema_mgr, parsed_file_set, father_fields)
58
+ self._parse_dependency(json_data, parsed_file_set, schema_mgr)
59
+ return interfaces
60
+
61
+ def interface_list(self, schema_mgr: MessageSchemaMgr) -> List[MessageSchema]:
62
+ return [msg for msg in self.parse(schema_mgr) if msg.msg_type == MessageType.INTERFACE]
63
+
64
+ def join_extend_options(self, father_options, msg):
65
+ temp_father_options = self.father_options_dict.get(msg.get("package") + "." + msg.get("name"))
66
+ if temp_father_options is None:
67
+ temp_father_options = father_options
68
+ join_father_options(msg, temp_father_options)
69
+
70
+ def _collect_property_options(self, message, msg, force: bool = False):
71
+ for pt in message.properties:
72
+ if pt.attr_type not in ALLOW_BASIC_TYPES:
73
+ if force:
74
+ self.father_options_dict[pt.attr_type] = msg.get("options")
75
+ else:
76
+ self.father_options_dict.setdefault(pt.attr_type, msg.get("options"))
77
+
78
+ def _parse_dependency(self, json_data, parsed_file_set, schema_mgr):
79
+ if not json_data.get("dependency"):
80
+ return
81
+ for dependency in json_data.get("dependency"):
82
+ if dependency == "types.proto":
83
+ continue
84
+ file_path = os.path.normpath(os.path.join(self.root_path, json_file_path(dependency)))
85
+ if file_path in parsed_file_set:
86
+ continue
87
+ parsed_file_set.add(file_path)
88
+ loader = RedfishLoader(self.root_path, file_path, self.father_options_dict)
89
+ loader.parse(schema_mgr, parsed_file_set)
90
+
91
+ def _parse_data(self, msg_list: List[dict], schema_mgr: MessageSchemaMgr, parsed_file_set: Set[str],
92
+ father_fields: FatherFields) -> List[MessageSchema]:
93
+ if not msg_list:
94
+ return []
95
+ ret: List[MessageSchema] = []
96
+ for msg in msg_list:
97
+ self.join_extend_options(father_fields.father_options, msg)
98
+ message = MessageSchema.from_proto_json(msg, father_fields.father, msg.get("options"))
99
+ schema_mgr.append(message)
100
+ self._collect_property_options(message, msg)
101
+ ret.append(message)
102
+ f_fields = FatherFields()
103
+ f_fields.father_options = msg.get("options")
104
+ f_fields.father = message.class_type()
105
+ ret.extend(
106
+ self._parse_data(msg.get("nested_type"), schema_mgr, parsed_file_set, f_fields))
107
+ self._extend_msg_options(father_fields.father_options, msg_list, ret)
108
+ return ret
109
+
110
+ def _extend_msg_options(self, father_options: dict,
111
+ raw_msg_list: List[dict], parsed_msg_list: List[MessageSchema], input_index: int = 0):
112
+ if not raw_msg_list:
113
+ return input_index
114
+ has_changed = True
115
+ while has_changed:
116
+ has_changed = False
117
+ index = input_index
118
+ for msg in raw_msg_list:
119
+ self.join_extend_options(father_options, msg)
120
+ if parsed_msg_list[index].url_route.merge_options(msg.get("options")):
121
+ has_changed = True
122
+ self._extend_property_options(index, msg, parsed_msg_list)
123
+ self._collect_property_options(parsed_msg_list[index], msg, force=True)
124
+ index += 1
125
+ index = self._extend_msg_options(msg.get("options"), msg.get("nested_type"),
126
+ parsed_msg_list, index)
127
+ return index
@@ -0,0 +1,62 @@
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 argparse
14
+ import shutil
15
+ import os
16
+ import stat
17
+ from subprocess import Popen, PIPE
18
+
19
+
20
+ def find_lua_format():
21
+ lua_format = shutil.which('lua-format', mode=os.X_OK)
22
+ if lua_format:
23
+ return lua_format
24
+ lua_format = os.getenv('LUA_FORMAT')
25
+ if os.access(lua_format, os.X_OK):
26
+ return lua_format
27
+ raise RuntimeError('找不到工具 lua-format')
28
+
29
+
30
+ def find_config_file(file):
31
+ parent_dir = os.path.dirname(file)
32
+ while len(parent_dir) > 1:
33
+ if os.path.exists(os.path.join(parent_dir, '.lua-format')):
34
+ return os.path.join(parent_dir, '.lua-format')
35
+ parent_dir = os.path.dirname(parent_dir)
36
+
37
+
38
+ def main():
39
+ parser = argparse.ArgumentParser()
40
+ parser.add_argument('files', metavar='FILE', type=str, nargs='+',
41
+ help='Source File Paths')
42
+ options = parser.parse_args()
43
+ files = options.files
44
+ if len(files) == 0:
45
+ return
46
+ if len(files) > 1:
47
+ raise RuntimeError('格式化文件不得超过一个')
48
+
49
+ cmds = [find_lua_format()]
50
+ cfg = find_config_file(__file__)
51
+ if cfg:
52
+ cmds += ['-c', cfg]
53
+ cmds += files
54
+ with Popen(cmds, stdout=PIPE) as proc:
55
+ data, _ = proc.communicate(timeout=50)
56
+ output = data.decode('utf-8')
57
+ with os.fdopen(os.open(files[0], os.O_WRONLY | os.O_TRUNC, stat.S_IWUSR | stat.S_IRUSR), 'w') as out_fp:
58
+ out_fp.write(output)
59
+
60
+
61
+ if __name__ == "__main__":
62
+ main()
@@ -0,0 +1,385 @@
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 json
14
+ import os
15
+ import re
16
+ import stat
17
+ from collections import OrderedDict
18
+ from utils import Utils
19
+
20
+ USAGE = "usage"
21
+
22
+
23
+ def get_real_path(path):
24
+ if path == "*":
25
+ return path
26
+
27
+ path = cut_ids(path)
28
+ return os.path.realpath(path)
29
+
30
+
31
+ def convert_path_params(path: str):
32
+ return re.sub(r":[\w\.]*", "*", re.sub(r"\$\{[\w\.]*\}", "*", path))
33
+
34
+
35
+ def get_intf(interface, mdb_path):
36
+ real_path = ("/").join(
37
+ [mdb_path, "intf", "mdb", interface.replace(".", "/") + ".json"]
38
+ )
39
+ with os.fdopen(os.open(real_path, os.O_RDONLY, stat.S_IRUSR), "r") as intf_file:
40
+ return OrderedDict(json.load(intf_file))
41
+
42
+
43
+ def get_path(class_name, mdb_path, path):
44
+ real_path = ("/").join([mdb_path, "path",
45
+ "mdb", path, class_name + ".json"])
46
+
47
+ with os.fdopen(os.open(real_path, os.O_RDONLY, stat.S_IRUSR), "r") as obj_file:
48
+ return OrderedDict(json.load(obj_file))
49
+
50
+
51
+ def get_path_by_interface(mdb_path: str, interface, path):
52
+ real_path = os.path.join(mdb_path, "path", "mdb", get_real_path(path).lstrip("/"))
53
+ expected_path = convert_path_params(path)
54
+ for obj_file in os.scandir(real_path):
55
+ if not obj_file.is_file():
56
+ continue
57
+ with os.fdopen(os.open(obj_file, os.O_RDONLY, stat.S_IRUSR), "r") as obj_fp:
58
+ obj_dict = OrderedDict(json.load(obj_fp))
59
+ for class_name, class_data in obj_dict.items():
60
+ converted_path = convert_path_params(class_data.get("path"))
61
+ if converted_path == expected_path and interface in class_data["interfaces"]:
62
+ return class_name, obj_dict
63
+ error_msg = f"service.json中配置的接口{interface}和路径{path}在mdb_interface中没有匹配的定义\n"\
64
+ f"mdb_interface路径匹配目录为: {real_path}"
65
+ raise RuntimeError(error_msg)
66
+
67
+
68
+ def save_proto_json(of_name, data):
69
+ with os.fdopen(
70
+ os.open(
71
+ of_name, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, stat.S_IWUSR | stat.S_IRUSR
72
+ ),
73
+ "w",
74
+ ) as load_f:
75
+ json.dump(data, load_f, indent=4)
76
+
77
+
78
+ def open_file(file):
79
+ return os.fdopen(os.open(file, os.O_RDONLY, stat.S_IRUSR), "r")
80
+
81
+
82
+ ALLOW_BASIC_TYPES = {
83
+ "Boolean": "bool",
84
+ "String": "string",
85
+ "S32": "int32",
86
+ "U32": "uint32",
87
+ "S64": "int64",
88
+ "U64": "uint64",
89
+ "Double": "double",
90
+ "U8": "uint8",
91
+ "S8": "int8",
92
+ "U16": "uint16",
93
+ "S16": "int16",
94
+ "Array": "message",
95
+ "Binary": "string"
96
+ }
97
+
98
+
99
+ def get_base_type(base_type, is_array):
100
+ if is_array:
101
+ return base_type[0:-2]
102
+ return base_type
103
+
104
+
105
+ def get_ref_type(referenced_type):
106
+ if referenced_type.startswith("types.json"):
107
+ return referenced_type.replace(
108
+ "types.json#/defs/", "def_types.defs_").replace("/", ".")
109
+ elif referenced_type.startswith("mdb://"):
110
+ slices = referenced_type.split(".json#")
111
+ return (Utils.get_unique_intf_name(slices[0].replace("/", ".")) + slices[1]) \
112
+ .replace("/defs/", ".defs_").replace("/", ".")
113
+ else:
114
+ return referenced_type.replace("#/", "").replace("/", ".")
115
+
116
+
117
+ def get_types(prop_name, prop_data):
118
+ if "baseType" in prop_data:
119
+ if prop_data["baseType"] == "Struct" or prop_data["baseType"] == "Enum" \
120
+ or prop_data["baseType"] == "Dictionary":
121
+ return False, get_ref_type(prop_data["$ref"])
122
+ elif prop_data["baseType"] == "Array":
123
+ return True, get_ref_type(prop_data["items"]["$ref"])
124
+ elif prop_data["baseType"].endswith("[]"):
125
+ return True, ALLOW_BASIC_TYPES[prop_data["baseType"][0:-2]]
126
+ else:
127
+ return False, ALLOW_BASIC_TYPES[prop_data["baseType"]]
128
+ if "$ref" not in prop_data:
129
+ raise RuntimeError(f"属性 {prop_name} 没有基类定义或找不到引用")
130
+ return False, get_ref_type(prop_data["$ref"])
131
+
132
+
133
+ def get_validate_option(prop_data):
134
+ validate_opt = ''
135
+ if "maximum" in prop_data or "minimum" in prop_data:
136
+ validate_opt += "ranges({}, {}),".format(
137
+ prop_data["minimum"] if "minimum" in prop_data else None,
138
+ prop_data["maximum"] if "maximum" in prop_data else None
139
+ )
140
+ if "maxLength" in prop_data or "minLength" in prop_data:
141
+ validate_opt += "lens({}, {}),".format(
142
+ prop_data["minLength"] if "minLength" in prop_data else None,
143
+ prop_data["maxLength"] if "maxLength" in prop_data else None
144
+ )
145
+ if "enum" in prop_data:
146
+ validate_opt += "enum({}),".format(prop_data["enum"])
147
+ if "pattern" in prop_data:
148
+ validate_opt += 'regex("{}"),'.format(prop_data["pattern"])
149
+ return validate_opt
150
+
151
+
152
+ def get_options(prop_name, prop_data):
153
+ options = {}
154
+ if "readOnly" in prop_data and prop_data["readOnly"]:
155
+ options["readonly"] = True
156
+ if "default" in prop_data:
157
+ options["default"] = prop_data["default"]
158
+ if "deprecated" in prop_data:
159
+ options["deprecated"] = prop_data["deprecated"]
160
+
161
+ options["validate"] = get_validate_option(prop_data)
162
+ options["allow_null"] = not prop_data.get("notAllowNull", False)
163
+
164
+ if "primaryKey" in prop_data and prop_data["primaryKey"]:
165
+ options["primary_key"] = prop_data["primaryKey"]
166
+ if not prop_data.get("notAllowNull", True):
167
+ raise RuntimeError(f"属性{prop_name}冲突: primaryKey 为真, 同时 notAllowNull 又为假")
168
+ options["allow_null"] = False
169
+
170
+ if "uniqueKey" in prop_data and prop_data["uniqueKey"]:
171
+ options["unique"] = prop_data["uniqueKey"]
172
+
173
+ if USAGE in prop_data:
174
+ options[USAGE] = prop_data[USAGE]
175
+
176
+ options["critical"] = prop_data.get("critical", False)
177
+ return options
178
+
179
+
180
+ def is_enum(prop_data):
181
+ if 'baseType' not in prop_data:
182
+ return False
183
+ elif prop_data['baseType'] == "Enum":
184
+ return True
185
+ elif prop_data['baseType'] == "Array" and 'baseType' in prop_data["items"] \
186
+ and prop_data["items"]['baseType'] == "Enum":
187
+ return True
188
+ else:
189
+ return False
190
+
191
+
192
+ # only db.lua need index
193
+ def get_property(prop_name, prop_data, index):
194
+ original_name = prop_name
195
+ repeated, prop_type = get_types(prop_name, prop_data)
196
+
197
+ if "alias" in prop_data:
198
+ prop_name = prop_data["alias"]
199
+
200
+ data = {
201
+ "original_name": original_name,
202
+ "name": prop_name,
203
+ "type": prop_type,
204
+ "options": get_options(prop_name, prop_data),
205
+ "id": index,
206
+ "repeated": repeated,
207
+ "is_enum": is_enum(prop_data)
208
+ }
209
+
210
+ if "displayDescription" in prop_data:
211
+ data["description"] = prop_data["displayDescription"]
212
+ return data
213
+
214
+
215
+ def get_dict_item(prop_name, prop_data, index):
216
+ repeated, prop_type = get_types(prop_name, prop_data)
217
+
218
+ data = {
219
+ "original_name": prop_name,
220
+ "name": prop_name,
221
+ "type": prop_type,
222
+ "options": get_options(prop_name, prop_data),
223
+ "id": index,
224
+ "repeated": repeated,
225
+ "is_enum": is_enum(prop_data)
226
+ }
227
+
228
+ if "displayDescription" in prop_data:
229
+ data["description"] = prop_data["displayDescription"]
230
+ return data
231
+
232
+
233
+ def get_enum(prop_name, prop_data, index):
234
+ return {
235
+ "name": prop_name,
236
+ "value": prop_data,
237
+ "id": index
238
+ }
239
+
240
+
241
+ def get_message_type(struct_data):
242
+ if 'key' in struct_data and 'value' in struct_data:
243
+ return 'dict'
244
+
245
+ dict_iter = iter(struct_data)
246
+ first_key = next(dict_iter, None)
247
+ if first_key is None or isinstance(struct_data[first_key], dict):
248
+ return 'struct'
249
+
250
+ return 'enum'
251
+
252
+
253
+ def get_struct_message(package, struct_name, struct_data):
254
+ struct_properties = []
255
+ index = 0
256
+ for prop, prop_data in struct_data.items():
257
+ struct_properties.append(get_property(prop, prop_data, index))
258
+ index = index + 1
259
+
260
+ return {
261
+ "package": package,
262
+ "name": struct_name,
263
+ "options": {},
264
+ "type": "Message",
265
+ "properties": struct_properties,
266
+ "nested_type": [],
267
+ }
268
+
269
+
270
+ def get_enum_message(package, struct_name, struct_data):
271
+ enum_type = str
272
+ index = 0
273
+ enum_values = []
274
+ for prop, prop_data in struct_data.items():
275
+ if not isinstance(prop_data, (int, str)):
276
+ raise RuntimeError("确保枚举 {} 有正确的类型".format(prop))
277
+ if index == 0:
278
+ enum_type = type(prop_data)
279
+ elif not isinstance(prop_data, enum_type):
280
+ raise RuntimeError("确保枚举 {} 有正确的类型".format(prop))
281
+ enum_values.append(get_enum(prop, prop_data, 0))
282
+ index += 1
283
+
284
+ return {
285
+ "package": package,
286
+ "name": struct_name,
287
+ "options": {},
288
+ "type": "Enum",
289
+ "default": 2147483647 if enum_type == int else "''",
290
+ "values": enum_values
291
+ }
292
+
293
+
294
+ def get_dict_message(package, struct_name, struct_data):
295
+ return {
296
+ "package": package,
297
+ "name": struct_name,
298
+ "options": {},
299
+ "type": "Dictionary",
300
+ "properties": [
301
+ get_dict_item('key', struct_data['key'], 0),
302
+ get_dict_item('value', struct_data['value'], 1)
303
+ ]
304
+ }
305
+
306
+
307
+ def cut_ids_new(path):
308
+ paths = []
309
+ current = 0
310
+
311
+ pos = path.find("${")
312
+ while pos != -1:
313
+ paths.append(path[current:pos])
314
+ end = path.find("}", pos)
315
+ if end != -1:
316
+ path = path[end + 1:]
317
+ pos = path.find("${")
318
+ else:
319
+ path = ""
320
+ pos = -1
321
+ paths.append(path)
322
+ paths.append("/")
323
+ return "".join(paths)
324
+
325
+
326
+ def cut_ids(path):
327
+ path = path.replace(" ", "")
328
+ paths = []
329
+ current = 0
330
+ path = cut_ids_new(path)
331
+ pos = path.find(":")
332
+ while pos != -1:
333
+ paths.append(path[current:pos])
334
+ end = path.find("/", pos)
335
+ if end != -1:
336
+ path = path[end:]
337
+ pos = path.find(":")
338
+ else:
339
+ path = ""
340
+ pos = -1
341
+ paths.append(path)
342
+ paths.append("/")
343
+ return "".join(paths)
344
+
345
+
346
+ def get_intf_package_name(intf_name):
347
+ intfs = intf_name.split(".")
348
+ if intfs[-1] == "Default":
349
+ return intfs[-2] + intfs[-1]
350
+ return intfs[-1]
351
+
352
+
353
+ def get_default_intf(intf_data, origin_intf):
354
+ if "properties" in origin_intf:
355
+ intf_data["properties"] = origin_intf["properties"]
356
+
357
+ if "signals" in origin_intf:
358
+ intf_data["signals"] = origin_intf["signals"]
359
+
360
+ if "methods" not in origin_intf:
361
+ return
362
+ intf_data["methods"] = {}
363
+ default = intf_data["methods"]
364
+ for method, method_intf in origin_intf["methods"].items():
365
+ new_method = method
366
+ default[new_method] = {}
367
+ if "req" in method_intf:
368
+ default[new_method]["req"] = {}
369
+ default[new_method]["req"]["path"] = {"baseType": "String"}
370
+ for arg, arg_data in method_intf["req"].items():
371
+ default[new_method]["req"][arg] = arg_data.copy()
372
+ if "rsp" in method_intf:
373
+ default[new_method]["rsp"] = method_intf["rsp"].copy()
374
+
375
+
376
+ def generate_default(load_dict, mdb_path):
377
+ for intf_data in load_dict.values():
378
+ if "implement" in intf_data:
379
+ if "properties" not in intf_data:
380
+ intf_data["properties"] = {}
381
+ default_intf = intf_data["implement"]
382
+ intf = get_intf(default_intf, mdb_path)[default_intf]
383
+ get_default_intf(intf_data, intf)
384
+
385
+ return load_dict