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,366 @@
1
+ <% import inflection %>
2
+ <% import re %>
3
+ #include "mdb_base.h"
4
+ #include "mcc/public.h"
5
+ #include "${inflection.underscore(package_name)}.h"
6
+
7
+ <%def name="message_decode_func(cmd, args, pointer_name)">
8
+ gboolean allocated __attribute__((unused)) = FALSE;
9
+ guint8 temp[IPMI_PAYLOAD_MAX + 1] = {0};
10
+ if (n_data >= IPMI_PAYLOAD_MAX) {
11
+ log_error("n_data bigger than %d, return NULL", IPMI_PAYLOAD_MAX - 1);
12
+ return NULL;
13
+ }
14
+ if (${pointer_name} == NULL) {
15
+ ${pointer_name} = g_new0(${cmd.name}_${pointer_name}, 1);
16
+ allocated = TRUE;
17
+ }
18
+ if (n_data == 0 || data == NULL) {
19
+ // 入参为空都不做任何处理,直接返回
20
+ return ${pointer_name};
21
+ }
22
+ // 存入临时数组,避免内存读越界
23
+ memcpy(temp, data, n_data);
24
+ % if len(args) > 0:
25
+ int pos_bit __attribute__((unused)) = 0;
26
+ guint64 u64_tmp __attribute__((unused)) = 0;\
27
+ <%
28
+ last_is_bit = False
29
+ last_bit = -1
30
+ now_bit = 0
31
+ %>
32
+ % for arg in args:
33
+
34
+ // >>> 开始处理${arg.data} >>>
35
+ % if arg.len.endswith("b"):
36
+ % if arg.ctype.c_len == 1:
37
+ ${pointer_name}->${arg.data} = (temp[pos_bit / BIT_PER_BYTE] >> (pos_bit % BIT_PER_BYTE)) & (0xff >> (BIT_PER_BYTE - ${arg.bit_len}));
38
+ % else:
39
+ % if (last_bit // (8 * arg.ctype.c_len)) != (now_bit // (8 * arg.ctype.c_len)):
40
+ u64_tmp = 0;
41
+ // ${pointer_name}->${arg.data}需要复制${arg.ctype.c_len}字节再取值
42
+ <% bit_offset = 0 %>\
43
+ for (int i = 0; i < ${arg.ctype.c_len}; i++) {
44
+ ((guint8 *)&u64_tmp)[i] = temp[(pos_bit / BIT_PER_BYTE) + i];
45
+ }
46
+ % endif
47
+ % if arg.ctype.c_len == 2:
48
+ // ${arg.data}位宽为${arg.bit_len}, 从u64_tmp的${bit_offset}开始位取${arg.bit_len}位
49
+ ${pointer_name}->${arg.data} = (u64_tmp >> ${bit_offset}) & ${hex(0xffff >> (16 - arg.bit_len))};
50
+ % elif arg.ctype.c_len == 4:
51
+ // ${arg.data}位宽为${arg.bit_len}, 从u64_tmp的${bit_offset}开始位取${arg.bit_len}位
52
+ ${pointer_name}->${arg.data} = (u64_tmp >> ${bit_offset}) & ${hex(0xffffffff >> (32 - arg.bit_len))};
53
+ % elif arg.ctype.c_len == 8:
54
+ // ${arg.data}位宽为${arg.bit_len}, 从u64_tmp的${bit_offset}开始位取${arg.bit_len}位
55
+ ${pointer_name}->${arg.data} = (u64_tmp >> ${bit_offset}) & ${hex(0xffffffffffffffff >> (64 - arg.bit_len))};
56
+ % endif
57
+ <% bit_offset += arg.bit_len %>\
58
+ % endif
59
+ // 加上${arg.bit_len}
60
+ pos_bit += ${arg.bit_len};\
61
+ <%
62
+ last_is_bit = True
63
+ last_bit = now_bit
64
+ now_bit += arg.bit_len
65
+ %>
66
+ % else:
67
+ % if last_is_bit:
68
+ pos_bit = ((pos_bit + BIT_PER_BYTE - 1) / BIT_PER_BYTE) * BIT_PER_BYTE;\
69
+ <%
70
+ last_is_bit = False
71
+ last_bit = -1
72
+ now_bit = 0
73
+ %>
74
+ % endif
75
+ % if arg.base_type == "String *":
76
+ ${pointer_name}->${arg.data} = (gchar *)(data + (pos_bit / BIT_PER_BYTE));
77
+ pos_bit += (strlen(${pointer_name}->${arg.data}) + 1) * 8;
78
+ % elif arg.base_type == "U8 *":
79
+ ${pointer_name}->${arg.data} = (guint8 *)(data + (pos_bit / BIT_PER_BYTE));
80
+ % if not re.match('^[1-9][0-9]+[bB]$', arg.len) and arg.len != '*':
81
+ % if arg.len_from_req == False:
82
+ pos_bit += ${pointer_name}->${arg.len} * 8;
83
+ % else:
84
+ pos_bit += ${pointer_name}->${arg.data}${arg.len} * 8;
85
+ % endif
86
+ % endif
87
+ % elif arg.base_type == "U8" or arg.base_type == "S8":
88
+ ${pointer_name}->${arg.data} = temp[pos_bit / BIT_PER_BYTE];
89
+ pos_bit += BIT_PER_BYTE;
90
+ % else:
91
+ // ${arg.data}位宽为${arg.bit_len}
92
+ for (int i = 0; i < ${arg.bit_len}; i += BIT_PER_BYTE) {
93
+ ((guint8 *)&${pointer_name}->${arg.data})[i / BIT_PER_BYTE] = temp[pos_bit / BIT_PER_BYTE];
94
+ pos_bit += BIT_PER_BYTE;
95
+ }
96
+ % endif
97
+ % endif
98
+ % endfor
99
+ gsize len = (pos_bit + BIT_PER_BYTE - 1) / BIT_PER_BYTE;
100
+ if (len > n_data) {
101
+ log_error("Memory overlay occurred, data size is %zu bigger than %zu", len, n_data);
102
+ g_free(${pointer_name});
103
+ return NULL;
104
+ }
105
+ % endif
106
+ % for arg in args:
107
+ % if arg.value is not None:
108
+ % if arg.base_type.startswith("String"):
109
+ if (strcmp(${pointer_name}->${arg.data}, "${arg.value}") != 0) {
110
+ % else:
111
+ if (${pointer_name}->${arg.data} != ${arg.value}) {
112
+ % endif
113
+ log_error("Filter ${arg.data} not match, need: ${arg.value}");
114
+ if (allocated) {
115
+ g_free(${pointer_name});
116
+ }
117
+ return NULL;
118
+ }
119
+ % endif
120
+ % endfor
121
+ return ${pointer_name};
122
+ </%def>\
123
+ <%def name="message_encode_func(cmd, args, pointer_name)">
124
+ if (${pointer_name} == NULL) {
125
+ return 0;
126
+ }
127
+ if (n_data == 0 || data == NULL) {
128
+ return 0;
129
+ }
130
+ memset(data, 0, n_data);
131
+ % if pointer_name == "rsp":
132
+ if (rsp->${args[0].data} != 0) {
133
+ data[0] = rsp->${args[0].data};
134
+ return 1;
135
+ }
136
+ % endif
137
+ gsize len = 0;
138
+ % if len(args) > 0:
139
+ guint64 u64_tmp __attribute__((unused)) = 0;
140
+ int pos_bit __attribute__((unused)) = 0;\
141
+ <%
142
+ last_is_bit = False
143
+ last_bit = 0
144
+ remain_bit = 0
145
+ %>
146
+ % for arg in args:
147
+ % if arg.len.endswith("b"):
148
+ // ${arg.data}位宽为${arg.bit_len}
149
+ u64_tmp = (guint64)${pointer_name}->${arg.data};
150
+ // 取低${8 - last_bit}位再左移${last_bit}位
151
+ data[pos_bit / BIT_PER_BYTE] |= (u64_tmp & ${hex(0xff >> last_bit)}) << ${last_bit};
152
+ % if arg.bit_len <= (8 - last_bit):
153
+ // bit位置加${arg.bit_len}位
154
+ pos_bit += ${arg.bit_len};
155
+ <%
156
+ remain_bit = 0
157
+ last_bit = last_bit + arg.bit_len;
158
+ %>
159
+ % else:
160
+ // 右移${8 - last_bit}bit位以删除已赋值部分
161
+ u64_tmp = u64_tmp >> ${8 - last_bit};
162
+ // bit位置加${8 - last_bit}位
163
+ pos_bit += ${8 - last_bit};\
164
+ <%
165
+ remain_bit = arg.bit_len - (8 - last_bit)
166
+ last_bit = 0
167
+ %>
168
+ % endif
169
+ % if remain_bit > 0:
170
+ % for i in range(0, remain_bit, 8):
171
+ % if (remain_bit - i) < 8:
172
+ // 右移${i}位后取${i + 8 - remain_bit}位
173
+ data[(pos_bit + ${i}) / BIT_PER_BYTE] = (u64_tmp >> ${i}) & ${hex(0xff >> (i + 8 - remain_bit))};
174
+ % else:
175
+ // 右移${i}位取
176
+ data[(pos_bit + ${i}) / BIT_PER_BYTE] = (u64_tmp >> ${i}) & 0xff;
177
+ % endif
178
+ % endfor
179
+ // bit位置加${remain_bit}位
180
+ pos_bit += ${remain_bit};
181
+ % endif
182
+ <%
183
+ last_is_bit = True
184
+ last_bit += remain_bit % 8
185
+ remain_bit = 0
186
+ %>\
187
+ % else:
188
+ % if last_is_bit == True:
189
+ // 下一个成员不是位域,需要取整
190
+ pos_bit = ((pos_bit + BIT_PER_BYTE - 1) / BIT_PER_BYTE) * BIT_PER_BYTE;\
191
+ <%
192
+ last_is_bit = False
193
+ last_bit = 0
194
+ %>
195
+ % endif
196
+ % if arg.base_type == "String *":
197
+ if (${pointer_name}->${arg.data} != NULL) {
198
+ len = strlen(${pointer_name}->${arg.data}) + 1;
199
+ memmove_s(data + pos_bit / BIT_PER_BYTE, len, ${pointer_name}->${arg.data}, len);
200
+ pos_bit += (len * BIT_PER_BYTE);
201
+ } else {
202
+ data[pos_bit / BIT_PER_BYTE] = '\0';
203
+ pos_bit += 8; // NULL转空字符串""
204
+ }
205
+ % elif arg.base_type == "U8 *":
206
+ % if arg.len_from_req == False:
207
+ ### BEGIN:为支持重复生成,只有版本号大于等于1的才需要判断长度是否为零
208
+ % if version >= 1:
209
+ if (${pointer_name}->${arg.len} > 0) {
210
+ if (${pointer_name}->${arg.data} != NULL) {
211
+ memmove_s(data + pos_bit / BIT_PER_BYTE, ${pointer_name}->${arg.len}, ${pointer_name}->${arg.data}, ${pointer_name}->${arg.len});
212
+ } else {
213
+ return 0;
214
+ }
215
+ }
216
+ % else:
217
+ if (${pointer_name}->${arg.data} != NULL) {
218
+ memmove_s(data + pos_bit / BIT_PER_BYTE, ${pointer_name}->${arg.len}, ${pointer_name}->${arg.data}, ${pointer_name}->${arg.len});
219
+ } else {
220
+ return 0;
221
+ }
222
+ % endif
223
+ ### END 版本号大于等于1的需要判断长度是否为零
224
+ pos_bit += (${pointer_name}->${arg.len} * BIT_PER_BYTE);
225
+ % else:
226
+ ### BEGIN:为支持重复生成,只有版本号大于等于1的才需要判断长度是否为零
227
+ % if version >= 1:
228
+ if (${pointer_name}->${arg.data}${arg.len} > 0) {
229
+ if (${pointer_name}->${arg.data} != NULL) {
230
+ memmove_s(data + pos_bit / BIT_PER_BYTE, ${pointer_name}->${arg.data}${arg.len}, ${pointer_name}->${arg.data}, ${pointer_name}->${arg.data}${arg.len});
231
+ } else {
232
+ return 0;
233
+ }
234
+ }
235
+ % else:
236
+ if (${pointer_name}->${arg.data} != NULL) {
237
+ memmove_s(data + pos_bit / BIT_PER_BYTE, ${pointer_name}->${arg.data}${arg.len}, ${pointer_name}->${arg.data}, ${pointer_name}->${arg.data}${arg.len});
238
+ } else {
239
+ return 0;
240
+ }
241
+ % endif
242
+ ### END 版本号大于等于1的需要判断长度是否为零
243
+ pos_bit += (${pointer_name}->${arg.data}${arg.len} * BIT_PER_BYTE);
244
+ % endif
245
+ % elif arg.base_type == "U8" or arg.base_type == "S8":
246
+ data[pos_bit / BIT_PER_BYTE] = (guint8)${pointer_name}->${arg.data};
247
+ pos_bit += BIT_PER_BYTE;
248
+ % else:
249
+ // ${arg.data}位宽为${arg.bit_len}
250
+ for (int i = 0; i < ${arg.bit_len}; i += BIT_PER_BYTE) {
251
+ data[pos_bit / BIT_PER_BYTE] = ((guint8 *)&${pointer_name}->${arg.data})[i / BIT_PER_BYTE];
252
+ pos_bit += BIT_PER_BYTE;
253
+ }
254
+ % endif
255
+ % endif
256
+ % endfor
257
+ len = (pos_bit + BIT_PER_BYTE - 1) / BIT_PER_BYTE;
258
+ if (len > n_data) {
259
+ log_error("Memory overlay occurred, data size is %zu bigger than %zu", len, n_data);
260
+ return 0;
261
+ }
262
+ % endif
263
+ return len;
264
+ </%def>\
265
+ ${cmd.name}_req *${cmd.name}_req_decode(gsize n_data, guint8 *data,
266
+ ${" ".join("" for _ in range(len(cmd.name)))} ${cmd.name}_req *req)
267
+ {${message_decode_func(cmd, cmd.req_args, "req")}}
268
+
269
+ gsize ${cmd.name}_req_encode(gsize n_data, guint8 *data,
270
+ ${" ".join("" for _ in range(len(cmd.name)))} const ${cmd.name}_req *req)
271
+ {${message_encode_func(cmd, cmd.req_args, "req")}}
272
+
273
+ ${cmd.name}_rsp *${cmd.name}_rsp_decode(gsize n_data, guint8 *data,
274
+ ${" ".join("" for _ in range(len(cmd.name)))} ${cmd.name}_rsp *rsp)
275
+ {${message_decode_func(cmd, cmd.rsp_args, "rsp")}}
276
+
277
+ gsize ${cmd.name}_rsp_encode(gsize n_data, guint8 *data,
278
+ ${" ".join("" for _ in range(len(cmd.name)))} const ${cmd.name}_rsp *rsp)
279
+ {${message_encode_func(cmd, cmd.rsp_args, "rsp")}}
280
+ % if cmd.need_free_rsp:
281
+ void ${cmd.name}_rsp_free(${cmd.name}_rsp *rsp)
282
+ {
283
+ % for arg in cmd.rsp_args:
284
+ % if arg.base_type == "String *" or arg.base_type == "U8 *":
285
+ g_free(rsp->${arg.data});
286
+ rsp->${arg.data} = NULL;
287
+ % endif
288
+ % endfor
289
+ }
290
+ % endif
291
+
292
+ gint ${cmd.name}_call(const IpmiCmdInfo_Cli *object, const CallerContext *caller,
293
+ ${" ".join("" for _ in range(len(cmd.name)))} const ${cmd.name}_req *req, ${cmd.name}_rsp *rsp, GError **error)
294
+ {
295
+ if (error == NULL) {
296
+ log_error("Parameter error");
297
+ return -1;
298
+ }
299
+ if (req == NULL || rsp == NULL) {
300
+ *error = g_error_new(G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "Parameter error");
301
+ return -1;
302
+ }
303
+ guint8 data[IPMI_PAYLOAD_MAX + 1] = {0};
304
+ IpmiCmdInfo_Process_Req payload = {};
305
+ payload.n_Payload = ${cmd.name}_req_encode(sizeof(data), data, req);
306
+ payload.Payload = data;
307
+ payload.n_IpmiContext = 3;
308
+ payload.IpmiContext = (guint8 *)"{}";
309
+ // 权限用户等上下文信息
310
+ if (caller == NULL) {
311
+ caller = caller_context_static();
312
+ }
313
+ GVariant *gcontext = caller_context_build(caller);
314
+ payload.Context = gcontext;
315
+ IpmiCmdInfo_Process_Rsp response = {};
316
+ gint ret = IpmiCmdInfo_Cli_Call_Process(object, &payload, &response, 1000, error);
317
+ g_variant_unref(gcontext);
318
+ if (ret != 0) {
319
+ return ret;
320
+ }
321
+ if (response.n_Response >= IPMI_PAYLOAD_MAX) {
322
+ *error = g_error_new(G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "Response bigger than %d, len: %zu", IPMI_PAYLOAD_MAX - 1, response.n_Response);
323
+ g_free(response.Response);
324
+ return -1;
325
+ }
326
+ // 复制到缓存中,避免输入太少导致解码时越界
327
+ memcpy(data, response.Response, response.n_Response);
328
+ (void)${cmd.name}_rsp_decode(response.n_Response, data, rsp);
329
+ g_free(response.Response);
330
+ return 0;
331
+ }
332
+
333
+ static void ${cmd.name}_start(void)
334
+ {
335
+ ${package_name} *cmds = ${package_name}_cmds();
336
+ // 构造IPMI命令${cmd.name}对象名
337
+ GString *str = g_string_new("");
338
+ g_string_printf(str, "/bmc/kepler/IpmiCmds/%02x/%02x/%s", ${cmd.netfn}, ${cmd.cmd}, "${cmd.name}");
339
+ cleanup_gfree gchar *object_name = g_string_free(str, FALSE);
340
+ // 创建IPMI命令${cmd.name}对象
341
+ const IpmiCmdInfo *obj = (const IpmiCmdInfo *)mcc_object_new(INTERFACE_IPMI_CMD_INFO,
342
+ mcc_bus_name(), object_name, NULL);
343
+ // 配置值
344
+ IpmiCmdInfo_set_NetFn(obj, ${cmd.netfn});
345
+ IpmiCmdInfo_set_Cmd(obj, ${cmd.cmd});
346
+ /* "Default": 10, "Oem": 20, "Odm": 30, "EndUser": 40, "Max": 50 */
347
+ IpmiCmdInfo_set_Priority(obj, ${cmd.priority});
348
+ IpmiCmdInfo_set_Privilege(obj, ${cmd.privilege});
349
+ IpmiCmdInfo_set_ServiceName(obj, mcc_bus_name());
350
+ IpmiCmdInfo_set_Filter(obj, "${cmd.filter}");
351
+ % if version >= 3:
352
+ IpmiCmdInfo_set_Sensitive(obj, ${"TRUE" if cmd.sensitive else "FALSE"});
353
+ % endif
354
+ % if version >= 6:
355
+ gint32 value[2] = ${cmd.manufacturer};
356
+ IpmiCmdInfo_set_Manufacturer(obj, 2, value);
357
+ % endif
358
+ // 绑定IPMI命令的消息处理器
359
+ mcc_object_set_bind(obj, (gpointer)&cmds->${cmd.name}, NULL);
360
+ mcc_object_present_set(obj, TRUE);
361
+ }
362
+
363
+ static void __attribute__((constructor(CONSTRUCTOR_GDBUSPLUS_MODULE_PRIORITY))) ${cmd.name}_service(void)
364
+ {
365
+ mdb_register_module(${cmd.name}_start, "${cmd.name}", STAGE_START);
366
+ }
@@ -0,0 +1,25 @@
1
+ #include "mdb_base.h"
2
+ #include "mcc/public.h"
3
+ #include "${ipmi_cmds.name}.h"
4
+
5
+ static ${ipmi_cmds.package} ipmi_cmds = {
6
+ % for cmd in ipmi_cmds.cmds:
7
+ .${cmd.name} = {
8
+ .impl = NULL,
9
+ .processer = {
10
+ .req_decode = (ipmi_req_decode)${cmd.name}_req_decode,
11
+ .req_encode = (ipmi_req_encode)${cmd.name}_req_encode,
12
+ .rsp_decode = (ipmi_rsp_decode)${cmd.name}_rsp_decode,
13
+ .rsp_encode = (ipmi_rsp_encode)${cmd.name}_rsp_encode,
14
+ % if cmd.need_free_rsp:
15
+ .rsp_free = (ipmi_rsp_free)${cmd.name}_rsp_free,
16
+ % endif
17
+ },
18
+ },
19
+ % endfor
20
+ };
21
+
22
+ ${ipmi_cmds.package} *${ipmi_cmds.package}_cmds(void)
23
+ {
24
+ return &ipmi_cmds;
25
+ }
@@ -0,0 +1,51 @@
1
+ #ifndef __${ipmi_cmds.name.upper()}_IPMI_H__
2
+ #define __${ipmi_cmds.name.upper()}_IPMI_H__
3
+ #include "client/bmc.kepler.CmdInfo.h"
4
+ #include "server/bmc.kepler.CmdInfo.h"
5
+ #pragma pack(1)
6
+ % for cmd in ipmi_cmds.cmds:
7
+
8
+ /* Notes: IPMI回调请求体如果有字符串指针("baseType": "String", "len": "*")的不能释放内存 */
9
+ typedef struct {
10
+ % for arg in cmd.req_args:
11
+ ${arg.c_declear_str};
12
+ % endfor
13
+ } ${cmd.name}_req;
14
+
15
+ /* Notes: IPMI响应请求体如果有字符串指针("baseType": "String", "len": "*")的将由框架释放,请正确分配字符串 */
16
+ typedef struct {
17
+ % for arg in cmd.rsp_args:
18
+ % if arg.len_from_req:
19
+ /* ${cmd.name}定义的${arg.data}成员长度为${arg.len},来自于请求体${cmd.name}_req->${arg.len},该成员不会做为响应的一部分返回 */
20
+ guint8 ${arg.data}${arg.len};
21
+ % endif
22
+ ${arg.c_declear_str};
23
+ % endfor
24
+ } ${cmd.name}_rsp;
25
+ ${cmd.name}_req *${cmd.name}_req_decode(gsize n_data, guint8 *data, ${cmd.name}_req *req);
26
+ gsize ${cmd.name}_req_encode(gsize n_data, guint8 *data, const ${cmd.name}_req *req);
27
+ ${cmd.name}_rsp *${cmd.name}_rsp_decode(gsize n_data, guint8 *data, ${cmd.name}_rsp *rsp);
28
+ gsize ${cmd.name}_rsp_encode(gsize n_data, guint8 *data, const ${cmd.name}_rsp *rsp);
29
+ % if cmd.need_free_rsp:
30
+ void ${cmd.name}_rsp_free(${cmd.name}_rsp *rsp);
31
+ % endif
32
+ gint ${cmd.name}_call(const IpmiCmdInfo_Cli *object, const CallerContext *caller,
33
+ const ${cmd.name}_req *req, ${cmd.name}_rsp *rsp, GError **error);
34
+ typedef int (*${cmd.name}_impl)(const CallerContext *caller, const IpmiCmdCtx *ipmi_ctx,
35
+ const ${cmd.name}_req *req, ${cmd.name}_rsp *rsp, GError **error);
36
+ #pragma pack()
37
+ % endfor
38
+
39
+ typedef struct {
40
+ % for cmd in ipmi_cmds.cmds:
41
+ struct {
42
+ ${cmd.name}_impl impl;
43
+ IpmiCmdProcesser processer;
44
+ gpointer *opaque;
45
+ } ${cmd.name};
46
+ % endfor
47
+ } ${ipmi_cmds.package};
48
+
49
+ ${ipmi_cmds.package} *${ipmi_cmds.package}_cmds(void);
50
+
51
+ #endif /* __${ipmi_cmds.name.upper()}_IPMI_H__ */
bmcgo/logger.py ADDED
@@ -0,0 +1,176 @@
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
+ # descritption: 解析service.json配置文件,生成不同的组件版本service.json配置文件
13
+
14
+ import logging
15
+ import re
16
+ import os
17
+ import inspect
18
+ from colorama import Fore, Back, Style
19
+
20
+
21
+ class CustomFormatter(logging.Formatter):
22
+ def custformat(self, log_level):
23
+ # CI 不打印格式化字符串
24
+ if os.getenv("CLOUD_BUILD_RECORD_ID") is not None:
25
+ formatter = "{message}"
26
+ formats = {
27
+ logging.DEBUG: formatter,
28
+ logging.INFO: formatter,
29
+ logging.WARNING: "WARN: " + formatter,
30
+ logging.ERROR: "ERROR: " + formatter,
31
+ logging.CRITICAL: "CRITICAL: " + formatter
32
+ }
33
+ # 本地未设置打印级别
34
+ elif os.getenv("LOG") is None:
35
+ formatter = "{message}"
36
+ formats = {
37
+ logging.DEBUG: formatter,
38
+ logging.INFO: formatter,
39
+ logging.WARNING: Fore.YELLOW + "WARN: " + formatter + Style.RESET_ALL,
40
+ logging.ERROR: Fore.RED + "ERROR: " + formatter + Style.RESET_ALL,
41
+ logging.CRITICAL: Fore.RED + "CRITICAL: " + formatter + Style.RESET_ALL
42
+ }
43
+ # 本地设置打印级别
44
+ else:
45
+ # 自定义格式化
46
+ formatter = "[{asctime} {levelname}] {message}"
47
+ formats = {
48
+ logging.DEBUG: formatter,
49
+ logging.INFO: formatter,
50
+ logging.WARNING: Fore.YELLOW + formatter + Style.RESET_ALL,
51
+ logging.ERROR: Fore.RED + formatter + Style.RESET_ALL,
52
+ logging.CRITICAL: Fore.RED + formatter + Style.RESET_ALL
53
+ }
54
+ return formats.get(log_level)
55
+
56
+ # 格式化重写
57
+ def format(self, record):
58
+ log_fmt = self.custformat(record.levelno)
59
+ formatter = logging.Formatter(log_fmt, style='{')
60
+ return formatter.format(record)
61
+
62
+
63
+ class Logger(logging.Logger):
64
+ def __init__(self, name="bmcgo", level=logging.INFO, log_file=None):
65
+ """初始化一个日志记录器
66
+
67
+ Args:
68
+ name (str): 记录器的名字
69
+ level (int): 记录器日志级别
70
+
71
+ Returns:
72
+ logger: 返回日志记录器对象
73
+ """
74
+ super().__init__(name)
75
+ self.log_level_env = os.environ.get("LOG")
76
+ self.ci_env = os.getenv("CLOUD_BUILD_RECORD_ID")
77
+ formatter = CustomFormatter()
78
+ if log_file:
79
+ ch = logging.FileHandler(filename=log_file)
80
+ ch.setFormatter(formatter)
81
+ self.addHandler(ch)
82
+ self.is_debug = True
83
+ if self.log_level_env == "info":
84
+ self.setLevel(logging.INFO)
85
+ elif self.log_level_env == "warn":
86
+ self.setLevel(logging.WARNING)
87
+ elif self.log_level_env == "error":
88
+ self.setLevel(logging.ERROR)
89
+ elif self.log_level_env == "debug":
90
+ self.setLevel(logging.DEBUG)
91
+ else:
92
+ self.is_debug = False
93
+ self.setLevel(level)
94
+ ch = logging.StreamHandler()
95
+ ch.setFormatter(formatter)
96
+ self.addHandler(ch)
97
+ # 匹配关键字
98
+ self.tip_msg = "|".join(["error", "failed", "unknown", "unable", "couldn't",
99
+ "invalid", "unexpected", "TypeError"])
100
+ # 判断是否包含关键字,且前后不能紧跟单词下划线和换行,或者前后紧跟换行但不匹配换行符,或以关键词开头结尾
101
+ self.error_pattern = re.compile((f'((?:^|(?<=\n)|.*[^\w\n])(?:{self.tip_msg})(?:[^\w\n].*|(?=\n)|$))'), re.I)
102
+
103
+ def error(self, msg, *args, **kwargs):
104
+ uptrace = kwargs.get("uptrace", None)
105
+ if uptrace is None:
106
+ uptrace = 1
107
+ else:
108
+ uptrace += 1
109
+ del kwargs["uptrace"]
110
+ msg = self._format_msg(msg, uptrace)
111
+ return super().error(msg, *args, **kwargs)
112
+
113
+ def info(self, msg, *args, **kwargs):
114
+ uptrace = kwargs.get("uptrace", None)
115
+ if uptrace is None:
116
+ uptrace = 1
117
+ else:
118
+ uptrace += 1
119
+ del kwargs["uptrace"]
120
+ msg = str(msg)
121
+ match = re.findall(self.error_pattern, msg)
122
+ if match:
123
+ msg = self.set_tip_msg(msg)
124
+ msg = self._format_msg(msg, uptrace)
125
+ return super().info(msg, *args, **kwargs)
126
+
127
+ def debug(self, msg, *args, **kwargs):
128
+ uptrace = kwargs.get("uptrace", None)
129
+ if uptrace is None:
130
+ uptrace = 1
131
+ else:
132
+ uptrace += 1
133
+ del kwargs["uptrace"]
134
+ msg = self._format_msg(msg, uptrace)
135
+ return super().debug(msg, *args, **kwargs)
136
+
137
+ def warning(self, msg, *args, **kwargs):
138
+ uptrace = kwargs.get("uptrace", None)
139
+ if uptrace is None:
140
+ uptrace = 1
141
+ else:
142
+ uptrace += 1
143
+ del kwargs["uptrace"]
144
+ msg = self._format_msg(msg, uptrace)
145
+ return super().warning(msg, *args, **kwargs)
146
+
147
+ def success(self, msg, *args, **kwargs):
148
+ uptrace = kwargs.get("uptrace", None)
149
+ if uptrace is None:
150
+ uptrace = 1
151
+ else:
152
+ uptrace += 1
153
+ del kwargs["uptrace"]
154
+ if self.log_level_env is not None or self.ci_env is None:
155
+ msg = Fore.GREEN + self._format_msg(msg, uptrace) + Style.RESET_ALL
156
+ else:
157
+ msg = self._format_msg(msg, uptrace)
158
+ return super().info(msg, *args, **kwargs)
159
+
160
+ def set_tip_msg(self, msg):
161
+ msgs = re.split(self.error_pattern, msg)
162
+ tip_msg = ""
163
+ # 循环正则切割后的内容,在有关键词的内容添加背景色
164
+ for item in msgs:
165
+ if re.findall(self.error_pattern, item):
166
+ tip_msg = f"{tip_msg}{Back.YELLOW}{item}{Style.RESET_ALL}"
167
+ else:
168
+ tip_msg = f"{tip_msg}{item}"
169
+ return tip_msg
170
+
171
+ def _format_msg(self, msg, uptrace):
172
+ if self.is_debug:
173
+ stack = inspect.stack()[uptrace + 1]
174
+ filename = os.path.basename(stack.filename)
175
+ return f"{filename}:{stack.lineno} {msg}"
176
+ return msg