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,263 @@
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 subprocess import Popen, PIPE
14
+ import json
15
+ import logging
16
+ import getopt
17
+ import sys
18
+ import os
19
+ import stat
20
+ import re
21
+
22
+ from mako.lookup import TemplateLookup
23
+
24
+ import mds_util
25
+ from utils import Utils
26
+ IPMI_DICT = "ipmi_dict"
27
+ MODEL_DICT = "model_dict"
28
+ APP_NAME = "app_name"
29
+ APP_SRC = "src"
30
+ IPMI_INPUT = "ipmi_input"
31
+ MODEL_INPUT = "model_input"
32
+
33
+
34
+ def gen_ipmi_cmd(options):
35
+ output_file_path = os.path.join(options['output_dir'], APP_SRC, 'lualib', 'callbacks', 'ipmi_cmd.lua')
36
+ template_path = os.path.join(options['template_dir'], 'ipmi_cmd.lua.mako')
37
+ if not os.path.exists(output_file_path):
38
+ template_render(options, template_path, output_file_path,
39
+ draft_info='本文件依据mds中定义的ipmi命令生成,完成ipmi命令回调函数')
40
+ return
41
+
42
+ output_file = os.fdopen(os.open(output_file_path, os.O_RDWR, stat.S_IWUSR | stat.S_IRUSR), 'w+')
43
+ content = output_file.read()
44
+ new_methods = []
45
+ for ipmi_method in options[IPMI_DICT].get('cmds', []):
46
+ pattern = re.compile(f'function ipmi_cmd.{ipmi_method}')
47
+ result = re.search(pattern, content)
48
+ if result is None:
49
+ new_methods.append(ipmi_method)
50
+ added_content = ""
51
+ for ipmi_method in new_methods:
52
+ added_content += f'''function ipmi_cmd.{ipmi_method}(req, ctx)
53
+ return
54
+ end
55
+
56
+ '''
57
+ end_line = 'factory.register_to_factory(\'ipmi_cmd\', ipmi_cmd)'
58
+ content = content.replace(end_line, added_content + end_line)
59
+ output_file.seek(0)
60
+ output_file.truncate()
61
+ output_file.write(content)
62
+ output_file.close()
63
+
64
+
65
+ def gen_class(options, cls):
66
+ output_file_path = os.path.join(options['output_dir'], APP_SRC, 'lualib',
67
+ 'callbacks', 'classes', cls.lower() + '.lua')
68
+ if not os.path.exists(output_file_path):
69
+ template_path = os.path.join(options['template_dir'], 'class.lua.mako')
70
+ template_render(options, template_path, output_file_path, cls, '本文件依据mds中定义的类生成,完成对应接口方法的回调函数')
71
+ return
72
+ output_file = os.fdopen(os.open(output_file_path, os.O_RDWR, stat.S_IWUSR | stat.S_IRUSR), 'w+')
73
+ content = output_file.read()
74
+
75
+ cls_methods = dict()
76
+ for interface, intf_dict in options[MODEL_DICT][cls].get('interfaces', {}).items():
77
+ intf_name = interface.split('.')[-1]
78
+ for method_name, method_dict in intf_dict.get('methods', {}).items():
79
+ if intf_name == 'Default':
80
+ pre_intf_name = interface.split('.')[-2]
81
+ cls_methods[cls + pre_intf_name + intf_name + method_name] = list(method_dict.get('req', {}).keys())
82
+ else:
83
+ unique_intf_name = Utils.get_unique_intf_name(interface)
84
+ cls_methods[cls + unique_intf_name + method_name] = list(method_dict.get('req', {}).keys())
85
+
86
+ new_methods = []
87
+ for method, args in cls_methods.items():
88
+ pattern = f'function {cls.lower()}:{method}\s*\(([\s\w,]+)\)'
89
+ pattern = re.compile(pattern)
90
+ result = re.search(pattern, content)
91
+ if result is None:
92
+ new_method = f'{method}(obj, ctx'
93
+ new_method += ''.join(map(lambda s: ', ' + s, args))
94
+ new_method += ')'
95
+ new_methods.append(new_method)
96
+ continue
97
+
98
+ user_args = [arg.strip() for arg in result.groups()[0].split(',')]
99
+ if set(user_args[2:]) != set(args):
100
+ replacement = f'function {cls.lower()}:{method}({user_args[0]}, {user_args[1]}'
101
+ replacement += ''.join(map(lambda s: ', ' + s, args))
102
+ replacement += ')'
103
+ content = re.sub(pattern, replacement, content)
104
+
105
+ added_content = ""
106
+ for new_method in new_methods:
107
+ added_content += f'''function {cls.lower()}:{new_method}
108
+
109
+ return 0
110
+ end
111
+
112
+ '''
113
+ end_line = f'factory.register_to_factory(\'{cls}\', {cls.lower()})'
114
+ content = content.replace(end_line, added_content + end_line)
115
+ output_file.seek(0)
116
+ output_file.truncate()
117
+ output_file.write(content)
118
+ output_file.close()
119
+
120
+
121
+ def template_render(options, template_path, output_file_path, class_name="", draft_info=""):
122
+ header = Utils.make_header(template_path, output_file_path, draft_info)
123
+ lookup = TemplateLookup(directories=[options['template_dir']], input_encoding='utf-8')
124
+ template = lookup.get_template(os.path.basename(template_path))
125
+ os.makedirs(os.path.dirname(output_file_path), exist_ok=True)
126
+ output_file = os.fdopen(os.open(output_file_path,
127
+ os.O_WRONLY | os.O_CREAT | os.O_TRUNC, stat.S_IWUSR | stat.S_IRUSR), 'w')
128
+
129
+ render_data = re.sub(r"\n\n\n+", "\n\n", template.render(
130
+ ipmi=options[IPMI_DICT],
131
+ model=options[MODEL_DICT],
132
+ make_header=header,
133
+ project_name=options[APP_NAME],
134
+ class_name=class_name,
135
+ render_utils=Utils
136
+ ))
137
+ output_file.write(render_data)
138
+ output_file.close()
139
+
140
+ if os.path.exists(options['formatter_path']):
141
+ with Popen([options['formatter_path'], output_file_path], stdout=PIPE) as proc:
142
+ data, _ = proc.communicate(timeout=50)
143
+ output_file = os.fdopen(os.open(
144
+ output_file_path, os.O_WRONLY | os.O_TRUNC, stat.S_IWUSR | stat.S_IRUSR), 'w')
145
+ output_file.write(data.decode('utf-8'))
146
+ output_file.close()
147
+
148
+
149
+ def generate(options):
150
+ options[IPMI_DICT] = dict()
151
+ options[MODEL_DICT] = dict()
152
+ if os.path.exists(options[IPMI_INPUT]):
153
+ ipmi_f = mds_util.open_file(options[IPMI_INPUT])
154
+ options[IPMI_DICT] = json.load(ipmi_f)
155
+ ipmi_f.close()
156
+ if os.path.exists(options[MODEL_INPUT]):
157
+ model_f = mds_util.open_file(options[MODEL_INPUT])
158
+ options[MODEL_DICT] = json.load(model_f)
159
+ model_f.close()
160
+
161
+ if options[IPMI_DICT]:
162
+ gen_ipmi_cmd(options)
163
+ for cls in options[MODEL_DICT]:
164
+ gen_class(options, cls)
165
+
166
+ overwrite_main_lua = options[APP_NAME] not in ['oms', 'nsm', 'ddns', 'ssdp', 'usb_entry',
167
+ 'event_policy', 'remote_console', 'license', 'cli', 'web_backend', 'redfish', 'firmware_mgmt',
168
+ 'bmc_upgrade', 'libroute_mapper', 'snmp', 'critical_rest', 'rmcp', 'ipmi_core']
169
+
170
+ output_files_info = [
171
+ (os.path.join(APP_SRC, 'lualib', 'app.lua'), '本文件为微组件app的用户代码入口,本组件的初始化入口', False),
172
+ (os.path.join(APP_SRC, 'lualib', 'callbacks', 'mc.lua'), '本文件为框架回调函数的实现', False),
173
+ (os.path.join('gen', options[APP_NAME], 'entry.lua'), '', True),
174
+ (os.path.join('gen', options[APP_NAME], 'signal_listen.lua'), '', True),
175
+ (os.path.join(APP_SRC, 'service', 'main.lua'), '', overwrite_main_lua)
176
+ ]
177
+ for name, draft_info, overwrite in output_files_info:
178
+ mako_name = os.path.basename(name) + '.mako'
179
+ template_path = os.path.join(options['template_dir'], mako_name)
180
+ output_file_path = os.path.join(options['output_dir'], name)
181
+ if os.path.exists(output_file_path):
182
+ if not overwrite:
183
+ continue
184
+ os.remove(output_file_path)
185
+ template_render(options, template_path, output_file_path, draft_info=draft_info)
186
+
187
+
188
+ def gen_factory(options):
189
+ factory_path = os.path.join(options['output_dir'], 'gen', options[APP_NAME], 'factory.lua')
190
+ if os.path.exists(factory_path):
191
+ os.remove(factory_path)
192
+ factory_content = '''local factory = {}
193
+ function factory.register_to_factory(class_name, cls)
194
+ factory[class_name] = cls
195
+ end
196
+
197
+ function factory.get_obj_cb(class_name, method)
198
+ local cls = factory[class_name]
199
+ return function(...)
200
+ return cls[method](cls, ...)
201
+ end
202
+ end
203
+
204
+ return factory
205
+ '''
206
+ factory_file = os.fdopen(os.open(factory_path,
207
+ os.O_WRONLY | os.O_CREAT | os.O_TRUNC, stat.S_IWUSR | stat.S_IRUSR), 'w')
208
+ factory_file.write(factory_content)
209
+ factory_file.close()
210
+
211
+
212
+ def usage():
213
+ logging.info("gen_entry.py -i <ipmifile> -m <modelfile> -o <outdir> -n <appname> -f <formatter> -t <template>")
214
+
215
+
216
+ def main(argv):
217
+ logging.getLogger().setLevel(logging.INFO)
218
+ options = dict()
219
+ try:
220
+ opts, _ = getopt.getopt(argv, "hi:m:o:n:f:t:", ["help", "ipmi=", "model=",
221
+ "out=", "name=", "formatter=", "template"])
222
+ except getopt.GetoptError as getopt_error:
223
+ logging.error(getopt_error)
224
+ return
225
+ for opt, arg in opts:
226
+ if opt in ("-h", "--help"):
227
+ usage()
228
+ return
229
+ elif opt in ("-i", "--ipmi"):
230
+ options[IPMI_INPUT] = arg
231
+ elif opt in ("-m", "--model"):
232
+ options[MODEL_INPUT] = arg
233
+ elif opt in ("-o", "--out"):
234
+ options['output_dir'] = arg
235
+ elif opt in ("-n", "--name"):
236
+ options[APP_NAME] = arg
237
+ elif opt in ("-f", "--formatter"):
238
+ options['formatter_path'] = arg
239
+ elif opt in ("-t", "--template"):
240
+ options['template_dir'] = arg
241
+ elif opt in ("-v", "--version"):
242
+ options['version'] = arg
243
+ else:
244
+ raise RuntimeError("不支持的选项: {}".format(opt))
245
+ required_keys = {
246
+ IPMI_INPUT, MODEL_INPUT, 'output_dir', APP_NAME,
247
+ 'formatter_path', 'template_dir'
248
+ }
249
+ if set(options.keys()) != required_keys:
250
+ logging.error("缺少选项")
251
+ usage()
252
+ return
253
+ if not os.path.exists(options[IPMI_INPUT]):
254
+ logging.warning("mds/ipmi.json 文件不存在")
255
+ if not os.path.exists(options[MODEL_INPUT]):
256
+ logging.warning("mds/model.json 文件不存在")
257
+
258
+ generate(options)
259
+ gen_factory(options)
260
+
261
+
262
+ if __name__ == "__main__":
263
+ main(sys.argv[1:])
@@ -0,0 +1,156 @@
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 logging
15
+ import getopt
16
+ import sys
17
+ import mds_util as utils
18
+ from utils import Utils
19
+
20
+
21
+ def insert_into_nested_dict(nested_dict, keys, value):
22
+ if len(keys) == 1:
23
+ nested_dict[keys[0]] = value
24
+ elif len(keys) >= 2:
25
+ if keys[0] not in nested_dict:
26
+ nested_dict[keys[0]] = {}
27
+ insert_into_nested_dict(nested_dict[keys[0]], keys[1:], value)
28
+
29
+
30
+ def make_public(class_name, class_data, datas):
31
+ intfs = {}
32
+ for intf_name, intf_data in class_data.items():
33
+ name = Utils.get_unique_intf_name(intf_name)
34
+ intfs[name] = intf_data
35
+ sorted_intfs = {key: intfs.get(key) for key in sorted(intfs.keys())}
36
+
37
+ datas[class_name] = sorted_intfs
38
+
39
+
40
+ def make_publics(public_feature, datas):
41
+ for class_name, class_data in public_feature.items():
42
+ datas[class_name] = {}
43
+ make_public(class_name, class_data, datas)
44
+
45
+
46
+ def save_feature_json(feature, feature_data, out_dir):
47
+ imports = [
48
+ "google/protobuf/descriptor.proto",
49
+ "ipmi_types.proto",
50
+ "types.proto"
51
+ ]
52
+ dependency = ["types.proto"]
53
+ datas = {
54
+ "imports": imports,
55
+ "dependency": dependency,
56
+ "options": {},
57
+ "feature": feature,
58
+ "public": {},
59
+ "private": {}
60
+ }
61
+
62
+ if "public" in feature_data:
63
+ make_publics(feature_data["public"], datas["public"])
64
+ if "private" in feature_data:
65
+ datas["private"] = feature_data["private"]
66
+
67
+ utils.save_proto_json(out_dir + "/" + feature + ".proto.json", datas)
68
+
69
+
70
+ def save_feature_jsons(features, out_dir):
71
+ for feature, feature_data in features.items():
72
+ save_feature_json(feature, feature_data, out_dir)
73
+
74
+
75
+ def collect_private_features(class_data, features):
76
+ for method_name, method_data in class_data.get("methods", {}).items():
77
+ if "featureTag" in method_data:
78
+ insert_into_nested_dict(features, [method_data["featureTag"], "private", method_name], True)
79
+
80
+
81
+ def collect_public_features(class_name, class_data, features):
82
+ for intf_name, intf_data in class_data.get("interfaces", {}).items():
83
+ for method_name, method_data in intf_data.get("methods", {}).items():
84
+ if "featureTag" not in method_data:
85
+ continue
86
+ insert_into_nested_dict(features, [method_data["featureTag"], "public", class_name, intf_name,
87
+ method_name], True)
88
+
89
+
90
+ def sort_public_features(feature_data, class_data):
91
+ for _, class_data in feature_data.items():
92
+ for intf_name, intf_data in class_data.items():
93
+ class_data[intf_name] = sorted(intf_data.keys())
94
+
95
+
96
+ def gen_features(model_path, out_dir):
97
+ load_f = utils.open_file(model_path)
98
+ load_dict = json.load(load_f)
99
+
100
+ features = {}
101
+ for class_name, class_data in load_dict.items():
102
+ if class_name == "private":
103
+ collect_private_features(class_data, features)
104
+ else:
105
+ collect_public_features(class_name, class_data, features)
106
+
107
+ for _, feature_data in features.items():
108
+ if "private" in feature_data:
109
+ feature_data["private"] = sorted(feature_data["private"].keys())
110
+ if "public" in feature_data:
111
+ sort_public_features(feature_data["public"], class_data)
112
+
113
+ save_feature_jsons(features, out_dir)
114
+
115
+
116
+ def usage():
117
+ logging.info(
118
+ "gen_plugin_json.py -i <inputfile> -o <outputfile> -n <project_name> -f"
119
+ )
120
+
121
+
122
+ def main(argv):
123
+ m_input = ""
124
+ output = ""
125
+ project_name = ""
126
+ try:
127
+ opts, _ = getopt.getopt(
128
+ argv,
129
+ "hi:o:n:f",
130
+ ["help", "input=", "out=", "project_name="],
131
+ )
132
+ except getopt.GetoptError:
133
+ help()
134
+ return
135
+ for opt, arg in opts:
136
+ if opt in ("-h", "--help"):
137
+ usage()
138
+ return
139
+ elif opt in ("-i", "--input"):
140
+ m_input = arg
141
+ elif opt in ("-o", "--out"):
142
+ output = arg
143
+ elif opt in ("-n", "--project_name"):
144
+ project_name = arg
145
+ elif opt in ("-f", "--feature"):
146
+ gen_features(m_input, output)
147
+ return
148
+ else:
149
+ raise RuntimeError("不支持的选项: {}".format(opt))
150
+ if not m_input or not output:
151
+ usage()
152
+ return
153
+
154
+
155
+ if __name__ == "__main__":
156
+ main(sys.argv[1:])
@@ -0,0 +1,88 @@
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 logging
14
+ import getopt
15
+ import sys
16
+ import os
17
+ import re
18
+ import mds_util as utils
19
+
20
+
21
+ def get_historical_tables(file):
22
+ historical_tables = {}
23
+ hit_class = ''
24
+ table_pattern = r'\.([^\s]+)\s'
25
+ field_pattern = r'([^\s]+) =.*:cid\((\d+)\)'
26
+
27
+ for line in file:
28
+ if 'db:Table' in line:
29
+ match = re.search(table_pattern, line)
30
+ if not match:
31
+ continue
32
+ hit_class = match.group(0)[1:-1]
33
+ historical_tables[hit_class] = []
34
+ elif hit_class != '':
35
+ match = re.search(field_pattern, line)
36
+ if not match:
37
+ continue
38
+ field_name = match.group(1)
39
+ cid = match.group(2)
40
+ extend_field = ':extend_field()' in line
41
+ historical_tables[hit_class].append({"name": field_name, "cid": int(cid), "extend_field": extend_field})
42
+ elif 'create_if_not_exist' in line:
43
+ hit_class = ''
44
+
45
+ return historical_tables
46
+
47
+
48
+ def generate(if_name, of_name):
49
+ if not os.path.exists(if_name):
50
+ return
51
+
52
+ historical_tables = {}
53
+ with open(if_name, 'r') as file:
54
+ historical_tables = get_historical_tables(file)
55
+
56
+ utils.save_proto_json(of_name, historical_tables)
57
+
58
+
59
+ def usage():
60
+ logging.info("gen_db_json.py -i <inputfile> -o <file>")
61
+
62
+
63
+ def main(argv):
64
+ m_input = ""
65
+ output = ""
66
+ try:
67
+ opts, _ = getopt.getopt(argv, "hi:o:d:", ["help", "input=", "out="])
68
+ except getopt.GetoptError:
69
+ help()
70
+ return
71
+ for opt, arg in opts:
72
+ if opt in ("-h", "--help"):
73
+ usage()
74
+ return
75
+ elif opt in ("-i", "--input"):
76
+ m_input = arg
77
+ elif opt in ("-o", "--out"):
78
+ output = arg
79
+ else:
80
+ raise RuntimeError("不支持的选项: {}".format(opt))
81
+ if not m_input or not output:
82
+ usage()
83
+ return
84
+ generate(m_input, output)
85
+
86
+
87
+ if __name__ == "__main__":
88
+ main(sys.argv[1:])