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,47 @@
|
|
|
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 typing import Dict
|
|
14
|
+
|
|
15
|
+
from dto.url_route import Url
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class KeplerAbstract:
|
|
19
|
+
def __init__(self, url_path: str, interface: str, file_path: str, package: str, name: str):
|
|
20
|
+
self.url = Url(url_path)
|
|
21
|
+
self.interface = interface
|
|
22
|
+
self.file_path = file_path
|
|
23
|
+
self.package: str = package
|
|
24
|
+
self.name: str = name
|
|
25
|
+
|
|
26
|
+
@classmethod
|
|
27
|
+
def from_json(cls, data: dict):
|
|
28
|
+
return KeplerAbstract(data.get("path"), data.get("interface"), data.get("file_path"),
|
|
29
|
+
data.get("package"), data.get("name"))
|
|
30
|
+
|
|
31
|
+
def to_json(self):
|
|
32
|
+
return {"path": self.url.url, "interface": self.interface, "file_path": self.file_path,
|
|
33
|
+
"package": self.package, "name": self.name}
|
|
34
|
+
|
|
35
|
+
def class_type(self):
|
|
36
|
+
return f"{self.package}.{self.name}"
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class KeplerAbstractMgr:
|
|
40
|
+
def __init__(self):
|
|
41
|
+
self.url_abstract_map: Dict[str, KeplerAbstract] = {}
|
|
42
|
+
|
|
43
|
+
def add(self, kepler_abstract: KeplerAbstract):
|
|
44
|
+
self.url_abstract_map.setdefault(kepler_abstract.url.url_feature, kepler_abstract)
|
|
45
|
+
|
|
46
|
+
def get(self, url_feature: str) -> KeplerAbstract:
|
|
47
|
+
return self.url_abstract_map.get(url_feature)
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# coding=utf-8
|
|
3
|
+
# Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
4
|
+
# openUBMC is licensed under Mulan PSL v2.
|
|
5
|
+
# You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
6
|
+
# You may obtain a copy of Mulan PSL v2 at:
|
|
7
|
+
# http://license.coscl.org.cn/MulanPSL2
|
|
8
|
+
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
|
9
|
+
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
|
10
|
+
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
|
11
|
+
# See the Mulan PSL v2 for more details.
|
|
12
|
+
|
|
13
|
+
import os
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class Options:
|
|
17
|
+
def __init__(self, options):
|
|
18
|
+
self.source_file_path: str = options.source_file_path
|
|
19
|
+
self.template_name: str = options.template_name
|
|
20
|
+
self.output_file_path: str = options.output_file_path
|
|
21
|
+
self.enable_auto_merge: bool = options.enable_auto_merge
|
|
22
|
+
self.project_name = options.project_name
|
|
23
|
+
self.version = options.version
|
|
24
|
+
self.proto_root_path = os.path.normpath(options.proto_root_path)
|
|
25
|
+
self.proto_json_root_path = os.path.normpath(
|
|
26
|
+
options.proto_json_root_path)
|
|
27
|
+
self.kepler_root_path = os.path.join(
|
|
28
|
+
options.proto_json_root_path, "mdb", "bmc", "kepler")
|
|
29
|
+
self.formatter = options.formatter
|
|
30
|
+
|
|
31
|
+
@staticmethod
|
|
32
|
+
def from_parse_args_result(options):
|
|
33
|
+
return Options(options)
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
|
|
14
|
+
class PrintSimple:
|
|
15
|
+
def __str__(self):
|
|
16
|
+
return "%s" % self.__dict__
|
|
17
|
+
|
|
18
|
+
def __repr__(self):
|
|
19
|
+
return "%s(%s)" % (self.__class__, self.__dict__)
|
|
@@ -0,0 +1,241 @@
|
|
|
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 enum
|
|
14
|
+
from typing import Dict, List
|
|
15
|
+
|
|
16
|
+
from dto.print_simple import PrintSimple
|
|
17
|
+
from dto.url_route import UrlRoute, UrlRouteDict
|
|
18
|
+
|
|
19
|
+
ALLOW_BASIC_TYPES = {"bool", "string", "int32", "uint32", "int64", "uint64", "float", "double", "bytes"}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def join_father_options(data: dict, father_options: dict):
|
|
23
|
+
if not father_options:
|
|
24
|
+
return
|
|
25
|
+
data.setdefault("options", {})
|
|
26
|
+
for key in father_options.keys():
|
|
27
|
+
data["options"].setdefault(key, father_options.get(key))
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class Mapping(PrintSimple):
|
|
31
|
+
def __init__(self, inner_attr_name: str = "", to_inner_func: str = "", from_inner_func: str = "",
|
|
32
|
+
auto_enable: bool = True):
|
|
33
|
+
self.inner_attr_name: str = inner_attr_name
|
|
34
|
+
self.to_inner_func: str = to_inner_func
|
|
35
|
+
self.from_inner_func: str = from_inner_func
|
|
36
|
+
self.auto_enable: bool = auto_enable
|
|
37
|
+
|
|
38
|
+
@classmethod
|
|
39
|
+
def from_proto_json(cls, data: Dict[str, str]):
|
|
40
|
+
ret = cls()
|
|
41
|
+
ret.inner_attr_name = data.get("v_attr")
|
|
42
|
+
ret.to_inner_func = data.get("cvt_to_inner")
|
|
43
|
+
ret.from_inner_func = data.get("cvt_to_out")
|
|
44
|
+
ret.auto_enable = data.get("auto_map") in [True, 1, "true", "TRUE", "Y", "YES"]
|
|
45
|
+
return ret
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class Converter(PrintSimple):
|
|
49
|
+
def __init__(self, raw_convert: str):
|
|
50
|
+
self._raw_convert: str = raw_convert
|
|
51
|
+
self.use_self: bool = False
|
|
52
|
+
self.cvt_fun: str = None
|
|
53
|
+
if raw_convert:
|
|
54
|
+
self.cvt_fun: str = raw_convert.split("@")[0]
|
|
55
|
+
if raw_convert.find("@self") >= 0:
|
|
56
|
+
self.use_self = True
|
|
57
|
+
|
|
58
|
+
def valid(self) -> bool:
|
|
59
|
+
return self.cvt_fun not in ["", None]
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class Property(PrintSimple):
|
|
63
|
+
def __init__(self, attr_name: str, attr_type: str, route: UrlRoute, mapping: Mapping, out_attr_name: str = None,
|
|
64
|
+
dft_value: str = None, read_only: bool = False, repeated: bool = False, attr_to_view: Converter = "",
|
|
65
|
+
attr_from_view: Converter = ""):
|
|
66
|
+
self.attr_name: str = attr_name
|
|
67
|
+
self.attr_type: str = attr_type
|
|
68
|
+
self.url_route: UrlRoute = route
|
|
69
|
+
self.mapping: Mapping = mapping
|
|
70
|
+
self.out_attr_name: str = out_attr_name
|
|
71
|
+
if not self.out_attr_name:
|
|
72
|
+
self.out_attr_name: str = self.attr_name
|
|
73
|
+
self.dft_value: str = dft_value
|
|
74
|
+
if not self.mapping.inner_attr_name:
|
|
75
|
+
self.mapping.inner_attr_name = self.attr_name
|
|
76
|
+
self.read_only: bool = read_only
|
|
77
|
+
self.repeated: bool = repeated
|
|
78
|
+
self.attr_to_view: Converter = attr_to_view
|
|
79
|
+
self.attr_from_view: Converter = attr_from_view
|
|
80
|
+
|
|
81
|
+
@classmethod
|
|
82
|
+
def from_proto_json(cls, data: dict, father_options: dict = None):
|
|
83
|
+
options = data.get("options")
|
|
84
|
+
if options is None:
|
|
85
|
+
options = {}
|
|
86
|
+
join_father_options(data, father_options)
|
|
87
|
+
return cls(
|
|
88
|
+
attr_name=data.get("name"),
|
|
89
|
+
attr_type=data.get("type"),
|
|
90
|
+
route=UrlRoute(options),
|
|
91
|
+
mapping=Mapping.from_proto_json(options),
|
|
92
|
+
out_attr_name=options.get("rename"),
|
|
93
|
+
dft_value=options.get("default"),
|
|
94
|
+
read_only=options.get("read_only"),
|
|
95
|
+
repeated=data.get("repeated"),
|
|
96
|
+
attr_to_view=Converter(options.get("attr_to_view")),
|
|
97
|
+
attr_from_view=Converter(options.get("attr_from_view"))
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
def complex_type(self, msg_mgr) -> bool:
|
|
101
|
+
if self.attr_type in ALLOW_BASIC_TYPES:
|
|
102
|
+
return False
|
|
103
|
+
msg = msg_mgr.messages.get(self.attr_type)
|
|
104
|
+
if msg is None:
|
|
105
|
+
return False
|
|
106
|
+
return not msg.msg_type.basic_attr()
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
class Value(PrintSimple):
|
|
111
|
+
def __init__(self, name: str, value: int):
|
|
112
|
+
self.name: str = name
|
|
113
|
+
self.value: int = value
|
|
114
|
+
|
|
115
|
+
@classmethod
|
|
116
|
+
def from_proto_json(cls, data: dict):
|
|
117
|
+
return cls(name=data.get("name"), value=data.get("value"))
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
class ServiceType(enum.Enum):
|
|
121
|
+
DATA = ("_Data", "_data")
|
|
122
|
+
GET = ("Get", "get")
|
|
123
|
+
PUT = ("Put", "put")
|
|
124
|
+
PATCH = ("Patch", "patch")
|
|
125
|
+
POST = ("Post", "post")
|
|
126
|
+
DELETE = ("Delete", "delete")
|
|
127
|
+
|
|
128
|
+
def __init__(self, http_name: str, code_name: str):
|
|
129
|
+
self.http_name: str = http_name
|
|
130
|
+
self.code_name: str = code_name
|
|
131
|
+
|
|
132
|
+
@classmethod
|
|
133
|
+
def from_json(cls, data: dict):
|
|
134
|
+
for service_type in cls:
|
|
135
|
+
if service_type.http_name == data.get("name"):
|
|
136
|
+
return service_type
|
|
137
|
+
return cls.DATA
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
REQ_BODY_VAR_NAME = "Body"
|
|
141
|
+
REQ_RESPONSE_VAR_NAME = "Response"
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
class MessageType(enum.Enum):
|
|
145
|
+
ENUM = "Enum"
|
|
146
|
+
MESSAGE = "Message"
|
|
147
|
+
INTERFACE = "Interface"
|
|
148
|
+
|
|
149
|
+
@classmethod
|
|
150
|
+
def from_json(cls, data: dict):
|
|
151
|
+
service_type = ServiceType.from_json(data)
|
|
152
|
+
if service_type != ServiceType.DATA:
|
|
153
|
+
return cls.INTERFACE
|
|
154
|
+
for msg_type in cls:
|
|
155
|
+
if msg_type.value == data.get("type"):
|
|
156
|
+
return msg_type
|
|
157
|
+
return cls.MESSAGE
|
|
158
|
+
|
|
159
|
+
def basic_attr(self) -> bool:
|
|
160
|
+
return self == MessageType.ENUM
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
class MessageSchema(PrintSimple):
|
|
164
|
+
def __init__(self):
|
|
165
|
+
self.package: str = ""
|
|
166
|
+
self.name: str = ""
|
|
167
|
+
self.url_route: UrlRoute = UrlRoute({})
|
|
168
|
+
self.auth_enable: bool = False
|
|
169
|
+
self.msg_type: MessageType = MessageType.MESSAGE
|
|
170
|
+
self.service_type: ServiceType = ServiceType.DATA
|
|
171
|
+
self.properties: List[Property] = []
|
|
172
|
+
self.values: List[Property] = []
|
|
173
|
+
|
|
174
|
+
@classmethod
|
|
175
|
+
def from_proto_json(cls, data: dict, father: str = "", father_options: dict = None):
|
|
176
|
+
ret = cls()
|
|
177
|
+
options = data.get("options")
|
|
178
|
+
if options is None:
|
|
179
|
+
options = {}
|
|
180
|
+
join_father_options(data, father_options)
|
|
181
|
+
if not father:
|
|
182
|
+
ret.package = data.get("package")
|
|
183
|
+
else:
|
|
184
|
+
ret.package = father
|
|
185
|
+
ret.name = data.get("name")
|
|
186
|
+
ret.url_route = UrlRoute(options)
|
|
187
|
+
if options.get("auth"):
|
|
188
|
+
ret.auth_enable = options.get("auth")
|
|
189
|
+
properties = data.get("properties")
|
|
190
|
+
if properties is None:
|
|
191
|
+
properties = []
|
|
192
|
+
ret.properties = [Property.from_proto_json(pt, data.get("options")) for pt in properties if pt.get("name")]
|
|
193
|
+
values = data.get("values")
|
|
194
|
+
if values is None:
|
|
195
|
+
values = []
|
|
196
|
+
ret.values = [Value.from_proto_json(value) for value in values]
|
|
197
|
+
ret.msg_type = MessageType.from_json(data)
|
|
198
|
+
ret.service_type = ServiceType.from_json(data)
|
|
199
|
+
return ret
|
|
200
|
+
|
|
201
|
+
def class_type(self):
|
|
202
|
+
return f"{self.package}.{self.name}"
|
|
203
|
+
|
|
204
|
+
def class_var_name(self):
|
|
205
|
+
return self.class_type().lower().replace(".", "_")
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
class MessageSchemaMgr(PrintSimple):
|
|
209
|
+
def __init__(self):
|
|
210
|
+
self.messages: Dict[str, MessageSchema] = {}
|
|
211
|
+
self._msg_route_map: Dict[str, UrlRouteDict] = {}
|
|
212
|
+
|
|
213
|
+
def append(self, msg: MessageSchema):
|
|
214
|
+
self.messages.setdefault(msg.class_type(), msg)
|
|
215
|
+
|
|
216
|
+
def related_objects(self, msg: MessageSchema) -> UrlRouteDict:
|
|
217
|
+
if self._msg_route_map.get(msg.class_type()):
|
|
218
|
+
return self._msg_route_map.get(msg.class_type())
|
|
219
|
+
route_dict = self._calc_related_url_route(msg)
|
|
220
|
+
self._msg_route_map.setdefault(msg.class_type(), route_dict)
|
|
221
|
+
return route_dict
|
|
222
|
+
|
|
223
|
+
def _calc_related_url_route(self, msg: MessageSchema):
|
|
224
|
+
route_dict = UrlRouteDict()
|
|
225
|
+
if not msg:
|
|
226
|
+
return route_dict
|
|
227
|
+
if msg.msg_type.basic_attr():
|
|
228
|
+
return route_dict
|
|
229
|
+
for pt in msg.properties:
|
|
230
|
+
route_dict.add_url(pt.url_route, msg.url_route)
|
|
231
|
+
if pt.attr_type not in ALLOW_BASIC_TYPES:
|
|
232
|
+
sub_msg = self.messages.get(pt.attr_type)
|
|
233
|
+
if sub_msg:
|
|
234
|
+
route_dict.extend(self.related_objects(sub_msg))
|
|
235
|
+
return route_dict
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
class FatherFields:
|
|
239
|
+
def __init__(self):
|
|
240
|
+
self.father_options: dict = {}
|
|
241
|
+
self.father: str = ""
|
|
@@ -0,0 +1,195 @@
|
|
|
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 typing import Dict, List, Optional
|
|
14
|
+
|
|
15
|
+
from dto.exception import UrlParseException
|
|
16
|
+
from dto.print_simple import PrintSimple
|
|
17
|
+
|
|
18
|
+
GET_URL_SEG_FUNC = "GetUrl" # 传入URL路径和参数位置,获取参数值的函数, 如: GetUrl(path, id)
|
|
19
|
+
REQ_PARAMS = "req.params"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class Variable(PrintSimple):
|
|
23
|
+
def __init__(self, name: str, segment_pos: int, order: int):
|
|
24
|
+
self.name: str = name
|
|
25
|
+
self.segment_pos: int = segment_pos
|
|
26
|
+
self.order: int = order
|
|
27
|
+
|
|
28
|
+
def to_param_name(self):
|
|
29
|
+
return self.name.lower().replace(":", "")
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class Url(PrintSimple):
|
|
33
|
+
def __init__(self, url: str):
|
|
34
|
+
self.url = url
|
|
35
|
+
self.segments: List[str] = []
|
|
36
|
+
if self.url:
|
|
37
|
+
self.segments: List[str] = url.split("/")
|
|
38
|
+
self.variable_list: List[Variable] = []
|
|
39
|
+
self.url_feature: str = ""
|
|
40
|
+
self._parse_url_variable_id(url)
|
|
41
|
+
|
|
42
|
+
def __eq__(self, other) -> bool:
|
|
43
|
+
return self.url == other.url
|
|
44
|
+
|
|
45
|
+
def relative_json_path(self):
|
|
46
|
+
return "/".join([seg for seg in self.segments if seg.find(":") < 0]) + ".proto.json"
|
|
47
|
+
|
|
48
|
+
def find_variable_by_name(self, mapping_name: str) -> Optional[Variable]:
|
|
49
|
+
ret = None
|
|
50
|
+
for variable in self.variable_list:
|
|
51
|
+
if variable.name == mapping_name:
|
|
52
|
+
return variable
|
|
53
|
+
return ret
|
|
54
|
+
|
|
55
|
+
def find_variable_by_variable(self, outer_var: Variable) -> Optional[Variable]:
|
|
56
|
+
var = None
|
|
57
|
+
var = self.find_variable_by_name(outer_var.name)
|
|
58
|
+
if var:
|
|
59
|
+
return var
|
|
60
|
+
for variable in self.variable_list:
|
|
61
|
+
if variable.order == outer_var.order:
|
|
62
|
+
return variable
|
|
63
|
+
return var
|
|
64
|
+
|
|
65
|
+
def find(self, outer_var: Variable, mapping_name: str = None) -> Optional[Variable]:
|
|
66
|
+
var = self.find_variable_by_name(mapping_name)
|
|
67
|
+
if var:
|
|
68
|
+
return var
|
|
69
|
+
return self.find_variable_by_variable(outer_var)
|
|
70
|
+
|
|
71
|
+
def _parse_url_variable_id(self, url):
|
|
72
|
+
self.url_feature = ""
|
|
73
|
+
if url is None:
|
|
74
|
+
return
|
|
75
|
+
seg_list = []
|
|
76
|
+
pos = 0
|
|
77
|
+
for name in self.segments:
|
|
78
|
+
if name.startswith(":"):
|
|
79
|
+
self.variable_list.append(Variable(name, pos, len(self.variable_list)))
|
|
80
|
+
seg_list.append(":id")
|
|
81
|
+
else:
|
|
82
|
+
seg_list.append(name)
|
|
83
|
+
pos += 1
|
|
84
|
+
self.url_feature = "/".join(seg_list)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
class UrlRoute(PrintSimple):
|
|
88
|
+
def __init__(self, options: Dict[str, str]):
|
|
89
|
+
if options.get("url"):
|
|
90
|
+
self.outer = Url(options.get("url"))
|
|
91
|
+
else:
|
|
92
|
+
self.outer = Url(options.get("path"))
|
|
93
|
+
self.inner = Url(options.get("inner_url"))
|
|
94
|
+
self.interface: str = options.get("interface")
|
|
95
|
+
self.outer_variable_mapping: Dict[str, str] = {}
|
|
96
|
+
self.inner_variable_mapping: Dict[str, str] = {}
|
|
97
|
+
variable_mapping = options.get("variable_mapping")
|
|
98
|
+
self._parse_variable_mapping(variable_mapping)
|
|
99
|
+
|
|
100
|
+
def __eq__(self, other):
|
|
101
|
+
return self.outer == other.outer and self.inner == other.inner and \
|
|
102
|
+
self.inner_variable_mapping == other.inner_variable_mapping and \
|
|
103
|
+
self.outer_variable_mapping == other.outer_variable_mapping
|
|
104
|
+
|
|
105
|
+
@staticmethod
|
|
106
|
+
def _check_variable_exists(mapping: str, url: Url, variable_id: str):
|
|
107
|
+
if url.url is None:
|
|
108
|
+
return
|
|
109
|
+
if not url.find_variable_by_name(variable_id):
|
|
110
|
+
raise UrlParseException(f"{mapping} 错误, {variable_id} 不在 {url.url} 中")
|
|
111
|
+
|
|
112
|
+
@staticmethod
|
|
113
|
+
def _merge_code(ret_list, join_tag=".."):
|
|
114
|
+
ret = ""
|
|
115
|
+
for i, _ in enumerate(ret_list):
|
|
116
|
+
if i != 0:
|
|
117
|
+
ret += join_tag
|
|
118
|
+
if ret_list[i].find(REQ_PARAMS) >= 0: # 该段是变量场景
|
|
119
|
+
ret += ret_list[i]
|
|
120
|
+
if i < len(ret_list) - 1 and ret_list[i + 1].find(REQ_PARAMS) >= 0: # 紧跟着的也是变量
|
|
121
|
+
ret += join_tag + '"/"'
|
|
122
|
+
continue
|
|
123
|
+
if len(ret_list) > 1 + i:
|
|
124
|
+
ret += f'"{ret_list[i]}/"'
|
|
125
|
+
else:
|
|
126
|
+
if i > 0:
|
|
127
|
+
ret += f'"/{ret_list[i]}"'
|
|
128
|
+
else:
|
|
129
|
+
ret += f'"{ret_list[i]}"'
|
|
130
|
+
return ret
|
|
131
|
+
|
|
132
|
+
def valid(self) -> bool:
|
|
133
|
+
return self.inner.url not in [None, ""] and self.outer.url not in [None, ""]
|
|
134
|
+
|
|
135
|
+
def merge_options(self, options: dict) -> bool:
|
|
136
|
+
if self.outer.url != options.get("url") or self.inner.url != options.get("inner_url"):
|
|
137
|
+
self.outer = Url(options.get("url"))
|
|
138
|
+
self.inner = Url(options.get("inner_url"))
|
|
139
|
+
return True
|
|
140
|
+
return False
|
|
141
|
+
|
|
142
|
+
def inner_url_code(self, join_tag="..") -> str:
|
|
143
|
+
ret_list = []
|
|
144
|
+
start_pos = 0
|
|
145
|
+
for variable in self.inner.variable_list:
|
|
146
|
+
buff = "/".join(self.inner.segments[start_pos:variable.segment_pos])
|
|
147
|
+
if buff:
|
|
148
|
+
ret_list.append(f'{buff}')
|
|
149
|
+
out_var = self.outer.find(variable, self.inner_variable_mapping.get(variable.name))
|
|
150
|
+
if out_var is None:
|
|
151
|
+
raise UrlParseException(f"没有匹配到变量: {variable}")
|
|
152
|
+
ret_list.append(f"{REQ_PARAMS}.{out_var.to_param_name()}")
|
|
153
|
+
start_pos = variable.segment_pos + 1
|
|
154
|
+
buff = "/".join(self.inner.segments[start_pos:])
|
|
155
|
+
if buff:
|
|
156
|
+
ret_list.append(f'{buff}')
|
|
157
|
+
return self._merge_code(ret_list, join_tag)
|
|
158
|
+
|
|
159
|
+
def _parse_variable_mapping(self, variable_mapping):
|
|
160
|
+
if len(self.inner.variable_list) > len(self.outer.variable_list):
|
|
161
|
+
raise UrlParseException("内部地址变量数量 %s > 外部地址变量 %s." % (
|
|
162
|
+
len(self.inner.variable_list), len(self.outer.variable_list)))
|
|
163
|
+
if variable_mapping is not None:
|
|
164
|
+
self._parse_user_define_mapping(variable_mapping)
|
|
165
|
+
|
|
166
|
+
def _parse_user_define_mapping(self, variable_mapping):
|
|
167
|
+
for kv in variable_mapping.split():
|
|
168
|
+
if kv.find("=") <= 0:
|
|
169
|
+
continue
|
|
170
|
+
outer_variable_id = kv.split("=")[0].strip() # 前面有find判断, 这里是=前面部分
|
|
171
|
+
inner_variable_id = kv.split("=")[1].strip() # 前面有find判断, 这里是=后面部分
|
|
172
|
+
self._check_variable_exists(kv, self.outer, outer_variable_id)
|
|
173
|
+
self._check_variable_exists(kv, self.inner, inner_variable_id)
|
|
174
|
+
self.outer_variable_mapping[outer_variable_id] = inner_variable_id
|
|
175
|
+
self.inner_variable_mapping[inner_variable_id] = outer_variable_id
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
class UrlRouteDict:
|
|
179
|
+
def __init__(self):
|
|
180
|
+
self.url_dict: Dict[str, Url] = {} # kepler 访问代码 --> Url的映射
|
|
181
|
+
|
|
182
|
+
def add_url(self, attr_route: UrlRoute, class_route: UrlRoute):
|
|
183
|
+
if attr_route.valid():
|
|
184
|
+
if class_route.valid():
|
|
185
|
+
if attr_route == class_route:
|
|
186
|
+
self.url_dict.setdefault(class_route.inner_url_code(), class_route.inner)
|
|
187
|
+
return
|
|
188
|
+
self.url_dict.setdefault(attr_route.inner_url_code(), attr_route.inner)
|
|
189
|
+
else:
|
|
190
|
+
if class_route.valid():
|
|
191
|
+
self.url_dict.setdefault(class_route.inner_url_code(), class_route.inner)
|
|
192
|
+
|
|
193
|
+
def extend(self, other):
|
|
194
|
+
for key in other.url_dict.keys():
|
|
195
|
+
self.url_dict.setdefault(key, other.url_dict.get(key))
|