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.
- bmcgo/__init__.py +12 -0
- bmcgo/bmcgo.py +22 -0
- bmcgo/bmcgo_config.py +176 -0
- bmcgo/cli/__init__.py +10 -0
- bmcgo/cli/cli.py +584 -0
- bmcgo/codegen/__init__.py +14 -0
- bmcgo/codegen/c/__init__.py +9 -0
- bmcgo/codegen/c/annotation.py +52 -0
- bmcgo/codegen/c/argument.py +42 -0
- bmcgo/codegen/c/codegen.py +153 -0
- bmcgo/codegen/c/comment.py +22 -0
- bmcgo/codegen/c/ctype_defination.py +353 -0
- bmcgo/codegen/c/helper.py +87 -0
- bmcgo/codegen/c/interface.py +63 -0
- bmcgo/codegen/c/method.py +82 -0
- bmcgo/codegen/c/property.py +180 -0
- bmcgo/codegen/c/renderer.py +21 -0
- bmcgo/codegen/c/signal.py +64 -0
- bmcgo/codegen/c/template/client.c.mako +145 -0
- bmcgo/codegen/c/template/client.h.mako +36 -0
- bmcgo/codegen/c/template/interface.c.mako +0 -0
- bmcgo/codegen/c/template/interface.introspect.xml.mako +99 -0
- bmcgo/codegen/c/template/micro_component.c.mako +32 -0
- bmcgo/codegen/c/template/public.c.mako +228 -0
- bmcgo/codegen/c/template/public.h.mako +128 -0
- bmcgo/codegen/c/template/server.c.mako +104 -0
- bmcgo/codegen/c/template/server.h.mako +36 -0
- bmcgo/codegen/lua/.lua-format +7 -0
- bmcgo/codegen/lua/Makefile +101 -0
- bmcgo/codegen/lua/__init__.py +9 -0
- bmcgo/codegen/lua/codegen.py +171 -0
- bmcgo/codegen/lua/proto/Makefile +87 -0
- bmcgo/codegen/lua/proto/ipmi_types.proto +17 -0
- bmcgo/codegen/lua/proto/types.proto +52 -0
- bmcgo/codegen/lua/script/check_intfs.py +161 -0
- bmcgo/codegen/lua/script/dto/__init__.py +11 -0
- bmcgo/codegen/lua/script/dto/exception.py +53 -0
- bmcgo/codegen/lua/script/dto/kepler_abstract.py +47 -0
- bmcgo/codegen/lua/script/dto/options.py +33 -0
- bmcgo/codegen/lua/script/dto/print_simple.py +19 -0
- bmcgo/codegen/lua/script/dto/redfish_api.py +241 -0
- bmcgo/codegen/lua/script/dto/url_route.py +195 -0
- bmcgo/codegen/lua/script/gen_db_json.py +444 -0
- bmcgo/codegen/lua/script/gen_depends.py +89 -0
- bmcgo/codegen/lua/script/gen_entry.py +263 -0
- bmcgo/codegen/lua/script/gen_feature_json.py +156 -0
- bmcgo/codegen/lua/script/gen_historical_local_db_json.py +88 -0
- bmcgo/codegen/lua/script/gen_intf_json.py +261 -0
- bmcgo/codegen/lua/script/gen_intf_rpc_json.py +575 -0
- bmcgo/codegen/lua/script/gen_ipmi_json.py +485 -0
- bmcgo/codegen/lua/script/gen_mdb_json.py +117 -0
- bmcgo/codegen/lua/script/gen_rpc_msg_json.py +487 -0
- bmcgo/codegen/lua/script/gen_schema.py +302 -0
- bmcgo/codegen/lua/script/ipmi_types_pb2.py +135 -0
- bmcgo/codegen/lua/script/loader/__init__.py +11 -0
- bmcgo/codegen/lua/script/loader/file_utils.py +33 -0
- bmcgo/codegen/lua/script/loader/kepler_abstract_collect.py +79 -0
- bmcgo/codegen/lua/script/loader/kepler_abstract_loader.py +47 -0
- bmcgo/codegen/lua/script/loader/redfish_loader.py +127 -0
- bmcgo/codegen/lua/script/lua_format.py +62 -0
- bmcgo/codegen/lua/script/mds_util.py +385 -0
- bmcgo/codegen/lua/script/merge_model.py +330 -0
- bmcgo/codegen/lua/script/merge_proto_algo.py +85 -0
- bmcgo/codegen/lua/script/proto_loader.py +47 -0
- bmcgo/codegen/lua/script/proto_plugin.py +140 -0
- bmcgo/codegen/lua/script/redfish_source_tree.py +118 -0
- bmcgo/codegen/lua/script/render_utils/__init__.py +38 -0
- bmcgo/codegen/lua/script/render_utils/base.py +25 -0
- bmcgo/codegen/lua/script/render_utils/client_lua.py +98 -0
- bmcgo/codegen/lua/script/render_utils/controller_lua.py +71 -0
- bmcgo/codegen/lua/script/render_utils/db_lua.py +224 -0
- bmcgo/codegen/lua/script/render_utils/error_lua.py +185 -0
- bmcgo/codegen/lua/script/render_utils/factory.py +52 -0
- bmcgo/codegen/lua/script/render_utils/ipmi_lua.py +159 -0
- bmcgo/codegen/lua/script/render_utils/ipmi_message_lua.py +24 -0
- bmcgo/codegen/lua/script/render_utils/mdb_lua.py +177 -0
- bmcgo/codegen/lua/script/render_utils/mdb_register.py +215 -0
- bmcgo/codegen/lua/script/render_utils/message_lua.py +26 -0
- bmcgo/codegen/lua/script/render_utils/messages_lua.py +156 -0
- bmcgo/codegen/lua/script/render_utils/model_lua.py +485 -0
- bmcgo/codegen/lua/script/render_utils/old_model_lua.py +429 -0
- bmcgo/codegen/lua/script/render_utils/plugin_lua.py +38 -0
- bmcgo/codegen/lua/script/render_utils/redfish_proto.py +86 -0
- bmcgo/codegen/lua/script/render_utils/request_lua.py +76 -0
- bmcgo/codegen/lua/script/render_utils/service_lua.py +130 -0
- bmcgo/codegen/lua/script/render_utils/utils_message_lua.py +125 -0
- bmcgo/codegen/lua/script/render_utils/validate_lua.py +221 -0
- bmcgo/codegen/lua/script/sep_ipmi_message_cmds.py +217 -0
- bmcgo/codegen/lua/script/template.py +166 -0
- bmcgo/codegen/lua/script/types_pb2.py +516 -0
- bmcgo/codegen/lua/script/utils.py +663 -0
- bmcgo/codegen/lua/script/validate.py +80 -0
- bmcgo/codegen/lua/script/yaml_to_json.py +73 -0
- bmcgo/codegen/lua/templates/Makefile +114 -0
- bmcgo/codegen/lua/templates/apps/Makefile +261 -0
- bmcgo/codegen/lua/templates/apps/Makefile.mdb.mk +64 -0
- bmcgo/codegen/lua/templates/apps/app.lua.mako +19 -0
- bmcgo/codegen/lua/templates/apps/class.lua.mako +35 -0
- bmcgo/codegen/lua/templates/apps/client.lua.mako +429 -0
- bmcgo/codegen/lua/templates/apps/controller.lua.mako +276 -0
- bmcgo/codegen/lua/templates/apps/datas.lua.mako +8 -0
- bmcgo/codegen/lua/templates/apps/db.lua.mako +89 -0
- bmcgo/codegen/lua/templates/apps/entry.lua.mako +128 -0
- bmcgo/codegen/lua/templates/apps/feature.lua.mako +37 -0
- bmcgo/codegen/lua/templates/apps/generate_route.mako +25 -0
- bmcgo/codegen/lua/templates/apps/impl_feature.lua.mako +72 -0
- bmcgo/codegen/lua/templates/apps/ipmi.lua.mako +97 -0
- bmcgo/codegen/lua/templates/apps/ipmi_cmd.lua.mako +18 -0
- bmcgo/codegen/lua/templates/apps/ipmi_message.lua.mako +36 -0
- bmcgo/codegen/lua/templates/apps/local_db.lua.mako +263 -0
- bmcgo/codegen/lua/templates/apps/main.lua.mako +25 -0
- bmcgo/codegen/lua/templates/apps/mc.lua.mako +77 -0
- bmcgo/codegen/lua/templates/apps/mdb.lua.mako +45 -0
- bmcgo/codegen/lua/templates/apps/mdb_interface.lua.mako +73 -0
- bmcgo/codegen/lua/templates/apps/message.lua.mako +38 -0
- bmcgo/codegen/lua/templates/apps/model.lua.mako +239 -0
- bmcgo/codegen/lua/templates/apps/orm_classes.lua.mako +16 -0
- bmcgo/codegen/lua/templates/apps/plugin.lua.mako +8 -0
- bmcgo/codegen/lua/templates/apps/redfish.proto.mako +47 -0
- bmcgo/codegen/lua/templates/apps/service.lua.mako +440 -0
- bmcgo/codegen/lua/templates/apps/signal_listen.lua.mako +19 -0
- bmcgo/codegen/lua/templates/apps/utils/default_intf.lua.mako +41 -0
- bmcgo/codegen/lua/templates/apps/utils/enum.mako +10 -0
- bmcgo/codegen/lua/templates/apps/utils/imports.mako +13 -0
- bmcgo/codegen/lua/templates/apps/utils/mdb_intf.lua.mako +25 -0
- bmcgo/codegen/lua/templates/apps/utils/mdb_obj.lua.mako +23 -0
- bmcgo/codegen/lua/templates/apps/utils/message.mako +160 -0
- bmcgo/codegen/lua/templates/apps/utils/request.lua.mako +59 -0
- bmcgo/codegen/lua/templates/apps/utils/validate.mako +83 -0
- bmcgo/codegen/lua/templates/errors.lua.mako +36 -0
- bmcgo/codegen/lua/templates/messages.lua.mako +32 -0
- bmcgo/codegen/lua/templates/new_app/.clang-format.mako +170 -0
- bmcgo/codegen/lua/templates/new_app/.gitignore.mako +26 -0
- bmcgo/codegen/lua/templates/new_app/CHANGELOG.md.mako +0 -0
- bmcgo/codegen/lua/templates/new_app/CMakeLists.txt.mako +29 -0
- bmcgo/codegen/lua/templates/new_app/Makefile.mako +25 -0
- bmcgo/codegen/lua/templates/new_app/README.md.mako +0 -0
- bmcgo/codegen/lua/templates/new_app/conanfile.py.mako +7 -0
- bmcgo/codegen/lua/templates/new_app/config.cfg.mako +6 -0
- bmcgo/codegen/lua/templates/new_app/mds/model.json.mako +3 -0
- bmcgo/codegen/lua/templates/new_app/mds/service.json.mako +21 -0
- bmcgo/codegen/lua/templates/new_app/permissions.ini.mako +16 -0
- bmcgo/codegen/lua/templates/new_app/src/lualib/${project_name}_app.lua.mako +16 -0
- bmcgo/codegen/lua/templates/new_app/src/service/main.lua.mako +25 -0
- bmcgo/codegen/lua/templates/new_app/test/integration/test_${project_name}.conf.mako +9 -0
- bmcgo/codegen/lua/templates/new_app/test/integration/test_${project_name}.lua.mako +47 -0
- bmcgo/codegen/lua/templates/new_app/test/unit/test.lua.mako +23 -0
- bmcgo/codegen/lua/templates/new_app/user_conf/rootfs/etc/systemd/system/${project_name}.service.mako +18 -0
- bmcgo/codegen/lua/templates/new_app/user_conf/rootfs/etc/systemd/system/multi-user.target.wants/${project_name}.service.link +1 -0
- bmcgo/component/__init__.py +10 -0
- bmcgo/component/analysis/analysis.py +183 -0
- bmcgo/component/analysis/build_deps.py +165 -0
- bmcgo/component/analysis/data_deps.py +333 -0
- bmcgo/component/analysis/dep-rules.json +912 -0
- bmcgo/component/analysis/dep_node.py +110 -0
- bmcgo/component/analysis/intf_deps.py +163 -0
- bmcgo/component/analysis/intf_validation.py +254 -0
- bmcgo/component/analysis/rule.py +211 -0
- bmcgo/component/analysis/smc_dfx_whitelist.json +11 -0
- bmcgo/component/analysis/sr_validation.py +391 -0
- bmcgo/component/build.py +222 -0
- bmcgo/component/component_dt_version_parse.py +348 -0
- bmcgo/component/component_helper.py +114 -0
- bmcgo/component/coverage/__init__.py +11 -0
- bmcgo/component/coverage/c_incremental_cov_report.template +53 -0
- bmcgo/component/coverage/incremental_cov.py +464 -0
- bmcgo/component/deploy.py +110 -0
- bmcgo/component/gen.py +169 -0
- bmcgo/component/package_info.py +236 -0
- bmcgo/component/template/conanbase.py.mako +278 -0
- bmcgo/component/template/conanfile.deploy.py.mako +40 -0
- bmcgo/component/test.py +947 -0
- bmcgo/errors.py +119 -0
- bmcgo/frame.py +217 -0
- bmcgo/functional/__init__.py +10 -0
- bmcgo/functional/analysis.py +96 -0
- bmcgo/functional/bmc_studio_action.py +98 -0
- bmcgo/functional/check.py +185 -0
- bmcgo/functional/conan_index_build.py +251 -0
- bmcgo/functional/config.py +332 -0
- bmcgo/functional/csr_build.py +724 -0
- bmcgo/functional/deploy.py +263 -0
- bmcgo/functional/diff.py +235 -0
- bmcgo/functional/fetch.py +235 -0
- bmcgo/functional/full_component.py +391 -0
- bmcgo/functional/maintain.py +381 -0
- bmcgo/functional/new.py +166 -0
- bmcgo/functional/schema_valid.py +111 -0
- bmcgo/functional/simple_sign.py +104 -0
- bmcgo/functional/upgrade.py +78 -0
- bmcgo/ipmigen/__init__.py +13 -0
- bmcgo/ipmigen/ctype_defination.py +82 -0
- bmcgo/ipmigen/ipmigen.py +309 -0
- bmcgo/ipmigen/template/cmd.c.mako +366 -0
- bmcgo/ipmigen/template/ipmi.c.mako +25 -0
- bmcgo/ipmigen/template/ipmi.h.mako +51 -0
- bmcgo/logger.py +176 -0
- bmcgo/misc.py +117 -0
- bmcgo/target/app.yml +17 -0
- bmcgo/target/install_sdk.yml +15 -0
- bmcgo/target/personal.yml +53 -0
- bmcgo/target/publish.yml +45 -0
- bmcgo/tasks/__init__.py +11 -0
- bmcgo/tasks/download_buildtools_hm.py +124 -0
- bmcgo/tasks/misc.py +15 -0
- bmcgo/tasks/task.py +354 -0
- bmcgo/tasks/task_build_conan.py +714 -0
- bmcgo/tasks/task_build_rootfs_img.py +595 -0
- bmcgo/tasks/task_buildgppbin.py +88 -0
- bmcgo/tasks/task_buildhpm_ext4.py +82 -0
- bmcgo/tasks/task_create_interface_config.py +122 -0
- bmcgo/tasks/task_download_buildtools.py +99 -0
- bmcgo/tasks/task_download_dependency.py +72 -0
- bmcgo/tasks/task_hpm_envir_prepare.py +112 -0
- bmcgo/tasks/task_packet_to_supporte.py +87 -0
- bmcgo/tasks/task_prepare.py +105 -0
- bmcgo/tasks/task_sign_and_pack_hpm.py +42 -0
- bmcgo/utils/__init__.py +10 -0
- bmcgo/utils/buffer.py +128 -0
- bmcgo/utils/combine_json_schemas.py +170 -0
- bmcgo/utils/component_post.py +54 -0
- bmcgo/utils/component_version_check.py +86 -0
- bmcgo/utils/config.py +1067 -0
- bmcgo/utils/fetch_component_code.py +232 -0
- bmcgo/utils/install_manager.py +61 -0
- bmcgo/utils/installations/__init__.py +10 -0
- bmcgo/utils/installations/base_installer.py +70 -0
- bmcgo/utils/installations/install_consts.py +30 -0
- bmcgo/utils/installations/install_plans/bingo.yml +11 -0
- bmcgo/utils/installations/install_workflow.py +50 -0
- bmcgo/utils/installations/installers/apt_installer.py +177 -0
- bmcgo/utils/installations/installers/pip_installer.py +46 -0
- bmcgo/utils/installations/version_util.py +100 -0
- bmcgo/utils/mapping_config_patch.py +443 -0
- bmcgo/utils/perf_analysis.py +114 -0
- bmcgo/utils/tools.py +704 -0
- bmcgo/worker.py +417 -0
- openubmc_bingo-0.5.240.dist-info/METADATA +30 -0
- openubmc_bingo-0.5.240.dist-info/RECORD +242 -0
- openubmc_bingo-0.5.240.dist-info/WHEEL +5 -0
- openubmc_bingo-0.5.240.dist-info/entry_points.txt +2 -0
- openubmc_bingo-0.5.240.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,663 @@
|
|
|
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
|
+
from datetime import datetime, timezone
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
|
|
19
|
+
from dto.options import Options
|
|
20
|
+
from validate import all_validates
|
|
21
|
+
from bmcgo.codegen import __version__ as codegen_version
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class Utils:
|
|
25
|
+
TYPE_TO_DBUS_MAP = {
|
|
26
|
+
'int8': 'y',
|
|
27
|
+
'uint8': 'y',
|
|
28
|
+
'int16': 'n',
|
|
29
|
+
'uint16': 'q',
|
|
30
|
+
'int32': 'i',
|
|
31
|
+
'uint32': 'u',
|
|
32
|
+
'int64': 'x',
|
|
33
|
+
'uint64': 't',
|
|
34
|
+
'double': 'd',
|
|
35
|
+
'float': 'd',
|
|
36
|
+
'bytes': 'ay',
|
|
37
|
+
'string': 's',
|
|
38
|
+
'bool': 'b'
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
TYPE_TO_LUA = {
|
|
42
|
+
'int8': 'integer',
|
|
43
|
+
'uint8': 'integer',
|
|
44
|
+
'int16': 'integer',
|
|
45
|
+
'uint16': 'integer',
|
|
46
|
+
'int32': 'integer',
|
|
47
|
+
'uint32': 'integer',
|
|
48
|
+
'int64': 'integer',
|
|
49
|
+
'uint64': 'integer',
|
|
50
|
+
'double': 'number',
|
|
51
|
+
'float': 'number',
|
|
52
|
+
'bytes': 'string',
|
|
53
|
+
'string': 'string',
|
|
54
|
+
'bool': 'boolean'
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
INTEGER_TYPE = {
|
|
58
|
+
'int8': 'integer',
|
|
59
|
+
'uint8': 'integer',
|
|
60
|
+
'int16': 'integer',
|
|
61
|
+
'uint16': 'integer',
|
|
62
|
+
'int32': 'integer',
|
|
63
|
+
'uint32': 'integer',
|
|
64
|
+
'int64': 'integer',
|
|
65
|
+
'uint64': 'integer',
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
OPEN_PROJECTS = {
|
|
69
|
+
'profile_schema',
|
|
70
|
+
'mdb_interface',
|
|
71
|
+
'hica',
|
|
72
|
+
'rootfs_user',
|
|
73
|
+
'webui',
|
|
74
|
+
'rackmount',
|
|
75
|
+
'rack_mgmt',
|
|
76
|
+
'fructrl',
|
|
77
|
+
'sensor',
|
|
78
|
+
'frudata',
|
|
79
|
+
'chassis',
|
|
80
|
+
'power_mgmt',
|
|
81
|
+
'thermal_mgmt',
|
|
82
|
+
'network_adapter',
|
|
83
|
+
'storage',
|
|
84
|
+
'pcie_device',
|
|
85
|
+
'bios',
|
|
86
|
+
'general_hardware',
|
|
87
|
+
'lsw',
|
|
88
|
+
'manufacture',
|
|
89
|
+
'account'
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
def __init__(self, data: dict, options: Options):
|
|
93
|
+
self.data = data
|
|
94
|
+
self.options = options
|
|
95
|
+
|
|
96
|
+
@staticmethod
|
|
97
|
+
def enum_value_name(e, prop):
|
|
98
|
+
if prop.startswith(e + '_'):
|
|
99
|
+
if prop[len(e) + 1:].isdigit():
|
|
100
|
+
return prop
|
|
101
|
+
else:
|
|
102
|
+
return prop[len(e) + 1:]
|
|
103
|
+
return prop
|
|
104
|
+
|
|
105
|
+
@staticmethod
|
|
106
|
+
def camel_to_snake(name):
|
|
107
|
+
name = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name)
|
|
108
|
+
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', name).lower()
|
|
109
|
+
|
|
110
|
+
@staticmethod
|
|
111
|
+
def convert_dictionary_to_lua_table(msg):
|
|
112
|
+
string = '{\n'
|
|
113
|
+
i = 1
|
|
114
|
+
for (prop, value) in msg.items():
|
|
115
|
+
string += f"['{prop}'] = " + Utils.to_lua_value(value) + ",\n"
|
|
116
|
+
i += 1
|
|
117
|
+
return string + '}'
|
|
118
|
+
|
|
119
|
+
@staticmethod
|
|
120
|
+
def to_lua_value(val):
|
|
121
|
+
if isinstance(val, str):
|
|
122
|
+
return f'[=[{val}]=]'
|
|
123
|
+
if isinstance(val, bool):
|
|
124
|
+
return 'true' if val else 'false'
|
|
125
|
+
if isinstance(val, list):
|
|
126
|
+
result = '{'
|
|
127
|
+
for value in val:
|
|
128
|
+
result += f"{Utils.to_lua_value(value)},"
|
|
129
|
+
return result + '}'
|
|
130
|
+
if isinstance(val, int) or isinstance(val, float):
|
|
131
|
+
return str(val)
|
|
132
|
+
if isinstance(val, dict):
|
|
133
|
+
return Utils.convert_dictionary_to_lua_table(val)
|
|
134
|
+
return val
|
|
135
|
+
|
|
136
|
+
@staticmethod
|
|
137
|
+
def get_msg_property(t, name):
|
|
138
|
+
ret = None
|
|
139
|
+
if 'properties' not in t:
|
|
140
|
+
return ret
|
|
141
|
+
for p in t['properties']:
|
|
142
|
+
if p['name'] == name:
|
|
143
|
+
ret = p
|
|
144
|
+
return ret
|
|
145
|
+
|
|
146
|
+
@staticmethod
|
|
147
|
+
def add_types(types, root):
|
|
148
|
+
if 'data' in root:
|
|
149
|
+
for data in root['data']:
|
|
150
|
+
package = data['package']
|
|
151
|
+
name = data['name']
|
|
152
|
+
types[f'{package}.{name}'] = data
|
|
153
|
+
|
|
154
|
+
@staticmethod
|
|
155
|
+
def get_create_date(target_file):
|
|
156
|
+
if os.path.exists(target_file):
|
|
157
|
+
file = open(target_file, "r")
|
|
158
|
+
content = file.read()
|
|
159
|
+
file.close()
|
|
160
|
+
date = re.search(r"Create: (\d+)-(\d+)-(\d+)", content)
|
|
161
|
+
if date:
|
|
162
|
+
return date[1], date[2], date[3]
|
|
163
|
+
now = datetime.now(tz=timezone.utc)
|
|
164
|
+
return now.year, now.month, now.day
|
|
165
|
+
|
|
166
|
+
@staticmethod
|
|
167
|
+
def make_prefix(lang):
|
|
168
|
+
prefix = ['-- ', '-- ', '', '--'] # lua style is default
|
|
169
|
+
if lang in ['c', 'cpp', 'java', 'rust', 'proto']:
|
|
170
|
+
prefix = ['/* ', ' * ', ' */\n', ' *'] # c style for C/C++/proto etc.
|
|
171
|
+
elif lang in ['python', 'shell']:
|
|
172
|
+
prefix = ['#\! ', ' # ', '', ' #'] # python style for shell/python
|
|
173
|
+
return prefix
|
|
174
|
+
|
|
175
|
+
@staticmethod
|
|
176
|
+
def maybe_array_type_to_lua(r, is_array):
|
|
177
|
+
return r if not is_array else f'{r}[]'
|
|
178
|
+
|
|
179
|
+
@staticmethod
|
|
180
|
+
def maybe_array_type_to_dbus(r: str, is_array):
|
|
181
|
+
return r if not is_array else f'a{r}'
|
|
182
|
+
|
|
183
|
+
@staticmethod
|
|
184
|
+
def get_message_type(data_type):
|
|
185
|
+
res = re.match(r'^\.?([^.]+)\.(.+)$', data_type)
|
|
186
|
+
if res:
|
|
187
|
+
return res.group(2), res.group(1)
|
|
188
|
+
return data_type, False
|
|
189
|
+
|
|
190
|
+
@staticmethod
|
|
191
|
+
def get_validate(validate_str):
|
|
192
|
+
if not validate_str:
|
|
193
|
+
return []
|
|
194
|
+
return eval('[{}]'.format(validate_str), all_validates())
|
|
195
|
+
|
|
196
|
+
@staticmethod
|
|
197
|
+
def oem_is_exist(source_name):
|
|
198
|
+
path = os.path.join(os.getcwd(), "..", "..", "proto", "apps", "redfish", "resource", "oem", "hw",
|
|
199
|
+
source_name + '.proto')
|
|
200
|
+
return os.path.exists(path)
|
|
201
|
+
|
|
202
|
+
@staticmethod
|
|
203
|
+
def get_lua_codegen_version():
|
|
204
|
+
env_version = os.getenv('LUA_CODEGEN_VERSION')
|
|
205
|
+
if env_version is None or env_version == "-1" or not env_version.isdigit():
|
|
206
|
+
return codegen_version
|
|
207
|
+
return int(env_version)
|
|
208
|
+
|
|
209
|
+
@staticmethod
|
|
210
|
+
def formatter(header, date, filename, lang, draft_info):
|
|
211
|
+
if draft_info:
|
|
212
|
+
author = '<change to your name>'
|
|
213
|
+
create = '<模板自动生成初稿, 需要您进行编辑>'
|
|
214
|
+
description = draft_info
|
|
215
|
+
else:
|
|
216
|
+
author = 'auto generate'
|
|
217
|
+
create = date
|
|
218
|
+
description = f'DO NOT EDIT; Code generated by "{filename}"'
|
|
219
|
+
|
|
220
|
+
return header.format(date[:4], author, create, description,
|
|
221
|
+
Utils.make_prefix(
|
|
222
|
+
lang)[1], Utils.make_prefix(lang)[0],
|
|
223
|
+
Utils.make_prefix(lang)[2], Utils.make_prefix(lang)[3])
|
|
224
|
+
|
|
225
|
+
@staticmethod
|
|
226
|
+
def make_header(tpl, target_file, draft_info=""):
|
|
227
|
+
pattern = r'(.*)/gen/(.*)'
|
|
228
|
+
gen_bak_file = re.sub(pattern, r'\1/gen_bak/\2', target_file)
|
|
229
|
+
year, month, day = Utils.get_create_date(gen_bak_file)
|
|
230
|
+
date = f'{year}-{month}-{day}'
|
|
231
|
+
filename = os.path.basename(tpl)
|
|
232
|
+
header = '''{5}Copyright (c) Huawei Technologies Co., Ltd. {0}. All rights reserved.
|
|
233
|
+
{7}
|
|
234
|
+
{4}this file licensed under the Mulan PSL v2.
|
|
235
|
+
{4}You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
236
|
+
{4}You may obtain a copy of Mulan PSL v2 at: http://license.coscl.org.cn/MulanPSL2
|
|
237
|
+
{7}
|
|
238
|
+
{4}THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
|
239
|
+
{4}IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
|
240
|
+
{4}PURPOSE.
|
|
241
|
+
{4}See the Mulan PSL v2 for more details.
|
|
242
|
+
{7}
|
|
243
|
+
{4}Author: {1}
|
|
244
|
+
{4}Create: {2}
|
|
245
|
+
{4}Description: {3}
|
|
246
|
+
{6}'''
|
|
247
|
+
project_name = os.getenv('PROJECT_NAME')
|
|
248
|
+
if Utils.get_lua_codegen_version() >= 8 and project_name in Utils.OPEN_PROJECTS:
|
|
249
|
+
header = '''{5}Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
250
|
+
{4}openUBMC is licensed under Mulan PSL v2.
|
|
251
|
+
{4}You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
252
|
+
{4}You may obtain a copy of Mulan PSL v2 at:
|
|
253
|
+
{4} http://license.coscl.org.cn/MulanPSL2
|
|
254
|
+
{4}THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
|
255
|
+
{4}EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
|
256
|
+
{4}MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
|
257
|
+
{4}See the Mulan PSL v2 for more details.
|
|
258
|
+
{6}'''
|
|
259
|
+
return lambda lang: Utils.formatter(header, date, filename, lang, draft_info)
|
|
260
|
+
|
|
261
|
+
@staticmethod
|
|
262
|
+
def force_to_colon(path):
|
|
263
|
+
return path.replace("${", ":").replace("}", "")
|
|
264
|
+
|
|
265
|
+
@staticmethod
|
|
266
|
+
def check_db_open(name):
|
|
267
|
+
return 'persist' not in Utils.camel_to_snake(name)
|
|
268
|
+
|
|
269
|
+
@staticmethod
|
|
270
|
+
def check_model_need_mem_db(model_json: dict):
|
|
271
|
+
for class_data in model_json.values():
|
|
272
|
+
if "tableName" in class_data and class_data.get("tableLocation") != "Local":
|
|
273
|
+
return True
|
|
274
|
+
return False
|
|
275
|
+
|
|
276
|
+
@staticmethod
|
|
277
|
+
def check_need_mem_db(root: dict):
|
|
278
|
+
if Utils.get_lua_codegen_version() < 7:
|
|
279
|
+
return Utils.check_db_open(root['package'])
|
|
280
|
+
return root.get('need_mem_db', False)
|
|
281
|
+
|
|
282
|
+
@staticmethod
|
|
283
|
+
def check_need_local_db(root: dict):
|
|
284
|
+
return Utils.check_local_poweroff_db(root) or Utils.check_local_reset_db(root) \
|
|
285
|
+
or Utils.check_local_reset_db(root)
|
|
286
|
+
|
|
287
|
+
@staticmethod
|
|
288
|
+
def check_remote_per(root):
|
|
289
|
+
return root.get('options', {}).get('has_remote_per', False)
|
|
290
|
+
|
|
291
|
+
@staticmethod
|
|
292
|
+
def check_local_poweroff_db(root):
|
|
293
|
+
return 'options' in root and 'has_local_poweroff' in root['options'] and root['options']['has_local_poweroff']
|
|
294
|
+
|
|
295
|
+
@staticmethod
|
|
296
|
+
def check_local_reset_db(root):
|
|
297
|
+
return 'options' in root and 'has_local_reset' in root['options'] and root['options']['has_local_reset']
|
|
298
|
+
|
|
299
|
+
@staticmethod
|
|
300
|
+
def check_local_temporary_db(root):
|
|
301
|
+
return 'options' in root and 'has_local_temporary' in root['options'] and root['options']['has_local_temporary']
|
|
302
|
+
|
|
303
|
+
@staticmethod
|
|
304
|
+
def remove_duplicate(params):
|
|
305
|
+
result = []
|
|
306
|
+
for name in params:
|
|
307
|
+
if name not in result:
|
|
308
|
+
result.append(name)
|
|
309
|
+
return result
|
|
310
|
+
|
|
311
|
+
@staticmethod
|
|
312
|
+
def get_primal_path_params(path):
|
|
313
|
+
params = re.compile(
|
|
314
|
+
r':([a-zA-Z_][0-9a-zA-Z_]+)').findall(path)
|
|
315
|
+
return params
|
|
316
|
+
|
|
317
|
+
@staticmethod
|
|
318
|
+
def get_type_name(prop_type):
|
|
319
|
+
slices = prop_type.split(".")
|
|
320
|
+
full_intf_name = ".".join(slices[:-1])
|
|
321
|
+
return Utils.get_unique_intf_name(full_intf_name) + "." + slices[-1]
|
|
322
|
+
|
|
323
|
+
@staticmethod
|
|
324
|
+
def get_unique_intf_name(intf):
|
|
325
|
+
check_intfs = Path(__file__).parent.parent.joinpath("temp").joinpath("check_intfs.json")
|
|
326
|
+
with open(check_intfs, 'r') as check_intfs_fp:
|
|
327
|
+
intf_map = json.load(check_intfs_fp)
|
|
328
|
+
|
|
329
|
+
slices = intf.split('.')
|
|
330
|
+
if slices[-1] == "Default":
|
|
331
|
+
return slices[-2] + slices[-1]
|
|
332
|
+
return intf_map.get(intf, slices[-1])
|
|
333
|
+
|
|
334
|
+
@staticmethod
|
|
335
|
+
def get_files(path):
|
|
336
|
+
file_list = []
|
|
337
|
+
for file_name in os.listdir(path):
|
|
338
|
+
file_path = os.path.join(path, file_name)
|
|
339
|
+
if os.path.isdir(file_path):
|
|
340
|
+
file_list.extend(Utils.get_files(file_path))
|
|
341
|
+
else:
|
|
342
|
+
file_list.append(file_path)
|
|
343
|
+
return file_list
|
|
344
|
+
|
|
345
|
+
@staticmethod
|
|
346
|
+
def count(params, name):
|
|
347
|
+
return params.count(name)
|
|
348
|
+
|
|
349
|
+
@classmethod
|
|
350
|
+
def get_dir_name(cls, path):
|
|
351
|
+
path_list = path.split('/')
|
|
352
|
+
return path_list[len(path_list) - 2]
|
|
353
|
+
|
|
354
|
+
@classmethod
|
|
355
|
+
def format_string_val(cls, val):
|
|
356
|
+
if len(val) < 50:
|
|
357
|
+
return f'[=[{val}]=]'
|
|
358
|
+
chunks, chunk_size = len(val), 50
|
|
359
|
+
lines = []
|
|
360
|
+
for line in [val[i:i + chunk_size] for i in range(0, chunks, chunk_size)]:
|
|
361
|
+
lines.append(f'[=[{line}]=]')
|
|
362
|
+
return " .. ".join(lines)
|
|
363
|
+
|
|
364
|
+
def make_get_message(self, data_type):
|
|
365
|
+
return self.get_message(self.data, data_type)
|
|
366
|
+
|
|
367
|
+
def default_in_message(self, msg):
|
|
368
|
+
for prop in msg['properties']:
|
|
369
|
+
if self.check_is_message(self.data, prop['type']):
|
|
370
|
+
return self.default_in_message(self.make_get_message(prop['type']))
|
|
371
|
+
elif 'options' in prop and 'default' in prop['options']:
|
|
372
|
+
return 'true'
|
|
373
|
+
return 'false'
|
|
374
|
+
|
|
375
|
+
def with_default_new(self, p):
|
|
376
|
+
if self.check_is_message(self.data, p['type']):
|
|
377
|
+
if self.default_in_message(self.make_get_message(p['type'])) == 'true':
|
|
378
|
+
return f"{p.get('original_name', p['name'])} or {p['type']}.new()"
|
|
379
|
+
if 'options' in p and 'default' in p['options']:
|
|
380
|
+
return f"{p.get('original_name', p['name'])} or {self.to_lua_value(p['options']['default'])}"
|
|
381
|
+
else:
|
|
382
|
+
return p.get('original_name', p['name'])
|
|
383
|
+
elif 'options' in p and 'default' in p['options']:
|
|
384
|
+
default = p['options']['default']
|
|
385
|
+
if p["repeated"]:
|
|
386
|
+
result = f"{p.get('original_name', p['name'])} or {{"
|
|
387
|
+
for default_var in default:
|
|
388
|
+
result += f"{self.to_lua_value(default_var)},"
|
|
389
|
+
return result + "}"
|
|
390
|
+
else:
|
|
391
|
+
if p['type'] == 'bool' and default:
|
|
392
|
+
return f"{p.get('original_name', p['name'])} == nil and true or {p.get('original_name', p['name'])}"
|
|
393
|
+
else:
|
|
394
|
+
return f"{p.get('original_name', p['name'])} or {self.to_lua_value(default)}"
|
|
395
|
+
return p.get('original_name', p['name'])
|
|
396
|
+
|
|
397
|
+
def construct(self, msg):
|
|
398
|
+
return ",\n ".join([f"{p.get('original_name', p['name'])} = \
|
|
399
|
+
{self.with_default_new(p)}" for p in msg['properties']])
|
|
400
|
+
|
|
401
|
+
def format_value(self, val, prefix):
|
|
402
|
+
if val is None:
|
|
403
|
+
return 'nil'
|
|
404
|
+
elif isinstance(val, str):
|
|
405
|
+
return self.format_string_val(val)
|
|
406
|
+
elif isinstance(val, bool):
|
|
407
|
+
return 'true' if val else 'false'
|
|
408
|
+
elif isinstance(val, list):
|
|
409
|
+
result = []
|
|
410
|
+
for v in val:
|
|
411
|
+
result.append(self.format_value(v, prefix))
|
|
412
|
+
return '{%s}' % (','.join(result))
|
|
413
|
+
elif isinstance(val, dict):
|
|
414
|
+
result = []
|
|
415
|
+
for k, v in val.items():
|
|
416
|
+
result.append(f'{k} = {self.format_value(v, prefix + " ")}')
|
|
417
|
+
return "{\n%s%s\n%s}" % (prefix, f',\n{prefix}'.join(result), prefix)
|
|
418
|
+
else:
|
|
419
|
+
return f'{val}'
|
|
420
|
+
|
|
421
|
+
def load_types(self, name):
|
|
422
|
+
types = {}
|
|
423
|
+
self.add_types(types, self.data)
|
|
424
|
+
|
|
425
|
+
if 'imports' in self.data:
|
|
426
|
+
for (_, data) in self.data['imports'].items():
|
|
427
|
+
self.add_types(types, data)
|
|
428
|
+
|
|
429
|
+
return types.get(name)
|
|
430
|
+
|
|
431
|
+
def is_map_type(self, t):
|
|
432
|
+
if 'properties' not in t:
|
|
433
|
+
return False
|
|
434
|
+
return len(t['properties']) == 2 and self.get_msg_property(t, 'key') and self.get_msg_property(t, 'value')
|
|
435
|
+
|
|
436
|
+
def try_get_map_type(self, t):
|
|
437
|
+
ret = {}
|
|
438
|
+
res = re.match(r'^(.+)\.([^.]+Entry)$', t)
|
|
439
|
+
if not res:
|
|
440
|
+
return ret
|
|
441
|
+
msg_type = res.group(1)
|
|
442
|
+
prop_type = res.group(2)
|
|
443
|
+
msg = self.load_types(msg_type)
|
|
444
|
+
if 'nested_type' not in msg:
|
|
445
|
+
return ret
|
|
446
|
+
ret = self.do_find_type(msg['nested_type'], prop_type)
|
|
447
|
+
if not ret or not self.is_map_type(ret):
|
|
448
|
+
return ret
|
|
449
|
+
return ret
|
|
450
|
+
|
|
451
|
+
def do_type_to_lua(self, t, is_array):
|
|
452
|
+
if t.endswith('[]'):
|
|
453
|
+
is_array = True
|
|
454
|
+
t = t[:-2]
|
|
455
|
+
if t in self.TYPE_TO_LUA:
|
|
456
|
+
return self.maybe_array_type_to_lua(self.TYPE_TO_LUA[t], is_array)
|
|
457
|
+
tt = self.load_types(t)
|
|
458
|
+
if tt is None:
|
|
459
|
+
map_type = self.try_get_map_type(t)
|
|
460
|
+
if not map_type:
|
|
461
|
+
return self.maybe_array_type_to_lua(t, is_array)
|
|
462
|
+
key = self.get_msg_property(map_type, 'key')
|
|
463
|
+
value = self.get_msg_property(map_type, 'value')
|
|
464
|
+
key_type = self.do_type_to_lua(key['type'], key['repeated'])
|
|
465
|
+
value_type = self.do_type_to_lua(value['type'], value['repeated'])
|
|
466
|
+
return f'table<{key_type}, {value_type}>'
|
|
467
|
+
else:
|
|
468
|
+
return self.maybe_array_type_to_lua(f'{tt["package"]}.{tt["name"]}', is_array)
|
|
469
|
+
|
|
470
|
+
def do_type_to_dbus(self, t: str, is_array):
|
|
471
|
+
if t.endswith('[]'):
|
|
472
|
+
is_array = True
|
|
473
|
+
t = t[:-2]
|
|
474
|
+
if t in self.TYPE_TO_DBUS_MAP:
|
|
475
|
+
return self.maybe_array_type_to_dbus(self.TYPE_TO_DBUS_MAP[t], is_array)
|
|
476
|
+
tt = self.load_types(t)
|
|
477
|
+
if tt is None:
|
|
478
|
+
map_type = self.try_get_map_type(t)
|
|
479
|
+
if not map_type:
|
|
480
|
+
return t
|
|
481
|
+
key = self.get_msg_property(map_type, 'key')
|
|
482
|
+
value = self.get_msg_property(map_type, 'value')
|
|
483
|
+
key_type = self.do_type_to_dbus(key['type'], False)
|
|
484
|
+
value_type = self.do_type_to_dbus(value['type'], False)
|
|
485
|
+
return f'a{{{key_type}{value_type}}}'
|
|
486
|
+
elif tt["type"] == "Enum":
|
|
487
|
+
return self.maybe_array_type_to_dbus('i', is_array)
|
|
488
|
+
elif tt["type"] == "Dictionary":
|
|
489
|
+
map_config = tt.get("properties", [{}, {}])
|
|
490
|
+
key_type = self.do_type_to_dbus(map_config[0].get('type'), map_config[0].get('repeated'))
|
|
491
|
+
value_type = self.do_type_to_dbus(map_config[1].get('type'), map_config[1].get('repeated'))
|
|
492
|
+
return f'a{{{key_type}{value_type}}}'
|
|
493
|
+
elif tt['type'] == 'Message' and 'properties' in tt:
|
|
494
|
+
result = []
|
|
495
|
+
for p in tt['properties']:
|
|
496
|
+
result.append(self.do_type_to_dbus(p['type'], p['repeated']))
|
|
497
|
+
if 'options' in tt and 'flatten' in tt['options'] and tt['options']['flatten']:
|
|
498
|
+
return self.maybe_array_type_to_dbus(f'{"".join(result)}', is_array)
|
|
499
|
+
return self.maybe_array_type_to_dbus(f'({"".join(result)})', is_array)
|
|
500
|
+
else:
|
|
501
|
+
raise RuntimeError(f"类型 `{t}` 转换为 dbus 类型失败")
|
|
502
|
+
|
|
503
|
+
def do_types_to_dbus(self, msg):
|
|
504
|
+
types = ''
|
|
505
|
+
for p in msg['properties']:
|
|
506
|
+
types += self.do_type_to_dbus(p['type'], p['repeated'])
|
|
507
|
+
return types
|
|
508
|
+
|
|
509
|
+
def do_service_types_to_dbus(self, root, input_data_type):
|
|
510
|
+
message = self.get_message(root, input_data_type)
|
|
511
|
+
return self.do_types_to_dbus(message)
|
|
512
|
+
|
|
513
|
+
def do_find_type(self, root, data_type) -> dict:
|
|
514
|
+
ret = {}
|
|
515
|
+
for data in root:
|
|
516
|
+
if data['name'] == data_type:
|
|
517
|
+
ret = data
|
|
518
|
+
if 'nested_type' not in data.keys():
|
|
519
|
+
continue
|
|
520
|
+
nested_data = self.do_find_type(data['nested_type'], data_type)
|
|
521
|
+
if nested_data:
|
|
522
|
+
ret = nested_data
|
|
523
|
+
return ret
|
|
524
|
+
|
|
525
|
+
def is_oem_message(self, filename, data_type):
|
|
526
|
+
return self.check_is_message(self.data['imports'][filename], data_type)
|
|
527
|
+
|
|
528
|
+
def get_oem_message(self, filename, data_type):
|
|
529
|
+
return self.get_message(self.data['imports'][filename], data_type)
|
|
530
|
+
|
|
531
|
+
def get_message(self, root, input_data_type, level=0) -> dict:
|
|
532
|
+
data_type, pkg = self.get_message_type(input_data_type)
|
|
533
|
+
if not pkg:
|
|
534
|
+
msg = self.do_find_type(root['data'], data_type)
|
|
535
|
+
if msg:
|
|
536
|
+
return msg
|
|
537
|
+
else:
|
|
538
|
+
pkg = 'def_types'
|
|
539
|
+
|
|
540
|
+
if level > 0:
|
|
541
|
+
msg = self.get_message(root, pkg, level + 1)
|
|
542
|
+
if msg and 'nested_type' in msg:
|
|
543
|
+
return self.get_message({'data': msg.get('nested_type')}, data_type, level + 1)
|
|
544
|
+
elif pkg == root['package'] or pkg == 'defs':
|
|
545
|
+
return self.get_message(root, data_type, level + 1)
|
|
546
|
+
elif pkg in root['imports']:
|
|
547
|
+
return self.get_message(root['imports'][pkg], data_type, level + 1)
|
|
548
|
+
elif pkg == 'google':
|
|
549
|
+
return {
|
|
550
|
+
"package": "google",
|
|
551
|
+
"name": input_data_type,
|
|
552
|
+
"options": {},
|
|
553
|
+
"type": "Message",
|
|
554
|
+
"properties": [],
|
|
555
|
+
"nested_type": []
|
|
556
|
+
}
|
|
557
|
+
raise RuntimeError("无效消息: {}".format(data_type))
|
|
558
|
+
|
|
559
|
+
def get_root(self, root, input_data_type, level=0):
|
|
560
|
+
data_type, pkg = self.get_message_type(input_data_type)
|
|
561
|
+
if not pkg:
|
|
562
|
+
msg = self.do_find_type(root['data'], data_type)
|
|
563
|
+
if msg:
|
|
564
|
+
return root
|
|
565
|
+
elif level > 0:
|
|
566
|
+
msg = self.get_root(root, pkg, level + 1)
|
|
567
|
+
if msg and 'nested_type' in msg:
|
|
568
|
+
return self.get_root({'data': msg.get('nested_type')}, data_type, level + 1)
|
|
569
|
+
elif pkg == root['package']:
|
|
570
|
+
return self.get_root(root, data_type, level + 1)
|
|
571
|
+
elif pkg in root['imports']:
|
|
572
|
+
return self.get_root(root['imports'][pkg], data_type, level + 1)
|
|
573
|
+
elif pkg == 'google':
|
|
574
|
+
return {
|
|
575
|
+
"package": "google",
|
|
576
|
+
"name": input_data_type,
|
|
577
|
+
"options": {},
|
|
578
|
+
"type": "Message",
|
|
579
|
+
"properties": [],
|
|
580
|
+
"nested_type": []
|
|
581
|
+
}
|
|
582
|
+
raise RuntimeError("无效消息: {}".format(data_type))
|
|
583
|
+
|
|
584
|
+
def is_integer(self, i_type):
|
|
585
|
+
return i_type in self.INTEGER_TYPE
|
|
586
|
+
|
|
587
|
+
def check_is_enum(self, p):
|
|
588
|
+
try:
|
|
589
|
+
pp = self.get_message(self.data, p)
|
|
590
|
+
return pp.get('type') == 'Enum'
|
|
591
|
+
except RuntimeError:
|
|
592
|
+
return False
|
|
593
|
+
|
|
594
|
+
def check_is_message(self, root, p):
|
|
595
|
+
try:
|
|
596
|
+
pp = self.get_message(root, p)
|
|
597
|
+
return pp.get('type') == 'Message' and not self.is_map_type(pp)
|
|
598
|
+
except RuntimeError:
|
|
599
|
+
return False
|
|
600
|
+
|
|
601
|
+
def is_base_type(self, name):
|
|
602
|
+
return name in self.TYPE_TO_LUA.keys()
|
|
603
|
+
|
|
604
|
+
def resolve_duplicate(self, params):
|
|
605
|
+
parent_count = self.count(params, 'parent')
|
|
606
|
+
if parent_count == 0:
|
|
607
|
+
return params
|
|
608
|
+
|
|
609
|
+
group_list = [[] for _ in range(parent_count + 1)]
|
|
610
|
+
|
|
611
|
+
num = 0
|
|
612
|
+
for param in params:
|
|
613
|
+
if param == 'parent':
|
|
614
|
+
num += 1
|
|
615
|
+
continue
|
|
616
|
+
group_list[num].append(param)
|
|
617
|
+
|
|
618
|
+
result = []
|
|
619
|
+
duplicate_map = {}
|
|
620
|
+
for i in range(parent_count + 1):
|
|
621
|
+
set_flag = {}
|
|
622
|
+
for item in group_list[i]:
|
|
623
|
+
if self.count(params, item) > self.count(group_list[i], item):
|
|
624
|
+
duplicate_map[item] = duplicate_map.get(item, 0)
|
|
625
|
+
duplicate_map[item] += set_flag.get(item, 1)
|
|
626
|
+
set_flag[item] = 0
|
|
627
|
+
result.append(item + str(duplicate_map[item]))
|
|
628
|
+
else:
|
|
629
|
+
result.append(item)
|
|
630
|
+
if i < parent_count:
|
|
631
|
+
result.append("parent")
|
|
632
|
+
|
|
633
|
+
return result
|
|
634
|
+
|
|
635
|
+
def get_all_params(self, path):
|
|
636
|
+
params = re.compile(
|
|
637
|
+
r':([a-zA-Z_][0-9a-zA-Z_]+)').findall(path)
|
|
638
|
+
return self.resolve_duplicate(params)
|
|
639
|
+
|
|
640
|
+
def get_path_params(self, path):
|
|
641
|
+
path = self.force_to_colon(path)
|
|
642
|
+
params = re.compile(
|
|
643
|
+
r':([a-zA-Z_][0-9a-zA-Z_]+)').findall(path)
|
|
644
|
+
return self.remove_duplicate(params)
|
|
645
|
+
|
|
646
|
+
def deduplicate_path(self, path):
|
|
647
|
+
primal_params = self.get_primal_path_params(path)
|
|
648
|
+
if len(primal_params) == 0:
|
|
649
|
+
return path
|
|
650
|
+
|
|
651
|
+
result = ''
|
|
652
|
+
params = self.get_all_params(path)
|
|
653
|
+
params_len = len(primal_params)
|
|
654
|
+
for i in range(params_len):
|
|
655
|
+
string = path.partition(f':{primal_params[i]}')
|
|
656
|
+
result += string[0]
|
|
657
|
+
if params[i] != 'parent':
|
|
658
|
+
result += ':' + params[i]
|
|
659
|
+
path = string[2]
|
|
660
|
+
if path:
|
|
661
|
+
result += path
|
|
662
|
+
|
|
663
|
+
return result
|