openubmc-bingo 0.6.45__py3-none-any.whl → 0.6.99__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.
Files changed (96) hide show
  1. bmcgo/__init__.py +1 -1
  2. bmcgo/bmcgo.py +9 -3
  3. bmcgo/bmcgo_config.py +16 -0
  4. bmcgo/cli/cli.py +72 -21
  5. bmcgo/codegen/__init__.py +1 -1
  6. bmcgo/codegen/lua/codegen.py +2 -2
  7. bmcgo/codegen/lua/script/check_intfs.py +1 -0
  8. bmcgo/codegen/lua/script/dto/options.py +1 -0
  9. bmcgo/codegen/lua/script/gen_db_json.py +4 -3
  10. bmcgo/codegen/lua/script/gen_rpc_msg_json.py +78 -11
  11. bmcgo/codegen/lua/script/model_consistency_check.py +1 -1
  12. bmcgo/codegen/lua/script/render_utils/db_lua.py +5 -6
  13. bmcgo/codegen/lua/script/render_utils/model_lua.py +5 -1
  14. bmcgo/codegen/lua/script/template.py +5 -0
  15. bmcgo/codegen/lua/script/utils.py +50 -8
  16. bmcgo/codegen/lua/templates/apps/Makefile +2 -2
  17. bmcgo/codegen/lua/templates/apps/client.lua.mako +1 -1
  18. bmcgo/codegen/lua/templates/apps/model.lua.mako +4 -3
  19. bmcgo/codegen/lua/templates/apps/service.lua.mako +1 -1
  20. bmcgo/codegen/lua/templates/apps/utils/mdb_intf.lua.mako +4 -0
  21. bmcgo/codegen/lua/templates/new_app_v2/CMakeLists.txt.mako +26 -0
  22. bmcgo/codegen/lua/templates/new_app_v2/conanfile.py.mako +9 -0
  23. bmcgo/codegen/lua/v1/script/render_utils/db_lua.py +5 -6
  24. bmcgo/codegen/lua/v1/script/render_utils/model_lua.py +13 -1
  25. bmcgo/codegen/lua/v1/templates/apps/client.lua.mako +1 -1
  26. bmcgo/codegen/lua/v1/templates/apps/local_db.lua.mako +0 -4
  27. bmcgo/codegen/lua/v1/templates/apps/message.lua.mako +3 -0
  28. bmcgo/codegen/lua/v1/templates/apps/model.lua.mako +3 -0
  29. bmcgo/codegen/lua/v1/templates/apps/utils/mdb_intf.lua.mako +6 -4
  30. bmcgo/component/analysis/analysis.py +9 -4
  31. bmcgo/component/analysis/dep-rules.json +20 -8
  32. bmcgo/component/analysis/dep_node.py +2 -0
  33. bmcgo/component/analysis/intf_validation.py +8 -7
  34. bmcgo/component/analysis/sr_validation.py +5 -4
  35. bmcgo/component/busctl_log_parse/busctl_log_parser.py +809 -0
  36. bmcgo/component/busctl_log_parse/mock_data_save.py +170 -0
  37. bmcgo/component/busctl_log_parse/test_data_save.py +49 -0
  38. bmcgo/component/component_helper.py +29 -0
  39. bmcgo/component/coverage/incremental_cov.py +5 -0
  40. bmcgo/component/fixture/__init__.py +29 -0
  41. bmcgo/component/fixture/auto_case_generator.py +490 -0
  42. bmcgo/component/fixture/busctl_type_converter.py +1081 -0
  43. bmcgo/component/fixture/common_config.py +15 -0
  44. bmcgo/component/fixture/dbus_gateway.py +669 -0
  45. bmcgo/component/fixture/dbus_library.py +250 -0
  46. bmcgo/component/fixture/dbus_mock_utils.py +514 -0
  47. bmcgo/component/fixture/dbus_response_handler.py +138 -0
  48. bmcgo/component/fixture/dbus_signature.py +110 -0
  49. bmcgo/component/template_v2/conanbase.py.mako +1 -5
  50. bmcgo/component/test.py +69 -10
  51. bmcgo/error_analyzer/__init__.py +0 -0
  52. bmcgo/error_analyzer/case_matcher.py +114 -0
  53. bmcgo/error_analyzer/log_parser.py +128 -0
  54. bmcgo/error_analyzer/unified_error_analyzer.py +359 -0
  55. bmcgo/error_cases/cases.yml +59 -0
  56. bmcgo/error_cases/cases_template_valid.json +71 -0
  57. bmcgo/error_cases/conanfile.py +58 -0
  58. bmcgo/frame.py +0 -4
  59. bmcgo/functional/analysis.py +18 -12
  60. bmcgo/functional/bmc_studio_action.py +21 -10
  61. bmcgo/functional/check.py +86 -42
  62. bmcgo/functional/conan_index_build.py +1 -1
  63. bmcgo/functional/config.py +22 -18
  64. bmcgo/functional/csr_build.py +63 -34
  65. bmcgo/functional/deploy.py +4 -3
  66. bmcgo/functional/diff.py +51 -34
  67. bmcgo/functional/full_component.py +16 -5
  68. bmcgo/functional/hpm_signer.py +484 -0
  69. bmcgo/functional/new.py +8 -2
  70. bmcgo/functional/schema_valid.py +111 -15
  71. bmcgo/functional/upgrade.py +6 -6
  72. bmcgo/misc.py +1 -0
  73. bmcgo/tasks/task_build_conan.py +27 -6
  74. bmcgo/tasks/task_build_rootfs_img.py +120 -83
  75. bmcgo/tasks/task_buildgppbin.py +30 -13
  76. bmcgo/tasks/task_buildhpm_ext4.py +5 -3
  77. bmcgo/tasks/task_download_buildtools.py +20 -11
  78. bmcgo/tasks/task_download_dependency.py +29 -20
  79. bmcgo/tasks/task_hpm_envir_prepare.py +32 -53
  80. bmcgo/tasks/task_packet_to_supporte.py +12 -4
  81. bmcgo/tasks/task_prepare.py +1 -1
  82. bmcgo/tasks/task_sign_and_pack_hpm.py +15 -7
  83. bmcgo/utils/component_version_check.py +4 -4
  84. bmcgo/utils/config.py +3 -0
  85. bmcgo/utils/fetch_component_code.py +148 -17
  86. bmcgo/utils/install_manager.py +2 -2
  87. bmcgo/utils/installations/base_installer.py +10 -27
  88. bmcgo/utils/installations/install_plans/studio.yml +3 -0
  89. bmcgo/utils/mapping_config_patch.py +5 -4
  90. bmcgo/utils/tools.py +49 -7
  91. {openubmc_bingo-0.6.45.dist-info → openubmc_bingo-0.6.99.dist-info}/METADATA +1 -1
  92. {openubmc_bingo-0.6.45.dist-info → openubmc_bingo-0.6.99.dist-info}/RECORD +95 -74
  93. bmcgo/tasks/download_buildtools_hm.py +0 -124
  94. {openubmc_bingo-0.6.45.dist-info → openubmc_bingo-0.6.99.dist-info}/WHEEL +0 -0
  95. {openubmc_bingo-0.6.45.dist-info → openubmc_bingo-0.6.99.dist-info}/entry_points.txt +0 -0
  96. {openubmc_bingo-0.6.45.dist-info → openubmc_bingo-0.6.99.dist-info}/top_level.txt +0 -0
bmcgo/functional/check.py CHANGED
@@ -49,7 +49,6 @@ _PACKAGE_INFO_HELP = """
49
49
  b. 文本格式
50
50
  package/version@user/channel
51
51
  """
52
- MODEL_CHOICES = ["all", "mds", "resource_tree", "csr", "interface_mapping"]
53
52
 
54
53
 
55
54
  def if_available(bconfig: BmcgoConfig):
@@ -57,34 +56,21 @@ def if_available(bconfig: BmcgoConfig):
57
56
 
58
57
 
59
58
  class BmcgoCommand:
59
+ MODEL_CHOICES = ["all", "mds", "resource_tree", "csr", "interface_mapping"]
60
+ BOARD_NAME_DEFAULT = misc.boardname_default()
61
+
60
62
  def __init__(self, bconfig: BmcgoConfig, *args):
61
63
  self.bconfig = bconfig
62
- parser = argparse.ArgumentParser(prog=f"{misc.tool_name()} check", description="语法正确性与模型一致性检查", add_help=True,
63
- formatter_class=argparse.RawTextHelpFormatter)
64
- parser.add_argument("-b", "--board_name",
65
- help="指定单板获取配套全量源码,可选值为build/product目录下的单板名\n默认:" + misc.boardname_default(),
66
- default=misc.boardname_default())
67
- parser.add_argument("--stage", help="包类型,可选值为:rc(预发布包), stable(发布包)\n默认: stable", default="stable")
68
- parser.add_argument("-r", "--remote")
69
- parser.add_argument("-m", "--model", help=f"检查的模型,可选值为: {', '.join(MODEL_CHOICES)}\n默认: all",
70
- choices=MODEL_CHOICES, default="all")
64
+
65
+ parser = self._create_parser()
71
66
  parsed_args, _ = parser.parse_known_args(*args)
72
- self.board_name = parsed_args.board_name
73
- self.stage = parsed_args.stage
74
- self.remote = parsed_args.remote
75
- self.model = parsed_args.model
76
- self.community_issues = set()
77
- self.service_dict = {}
78
- self.packages = {}
79
- self.repo_brance = Repo(cwd).active_branch.name
80
- self.repo_name = "manifest"
81
- self.disabled = False
82
- self.studio_dir = "/usr/share/bmc_studio/server"
83
- self.studio_path = "/usr/share/bmc_studio/server/bmcstudio"
67
+ self._init_common_attributes(parsed_args)
68
+ self._init_specific_attributes(parsed_args)
69
+
84
70
  # 初始化fetch命令对象
85
71
  if self.bconfig.manifest:
86
72
  self.fetch_agent = FetchAgent(self.bconfig, *args)
87
-
73
+
88
74
  @staticmethod
89
75
  def check_overdue(issue: dict):
90
76
  data = issue.get("deadline")
@@ -97,7 +83,7 @@ class BmcgoCommand:
97
83
  except Exception as e:
98
84
  log.warning("日期 %s 解析失败:%s", data, e)
99
85
  return False
100
-
86
+
101
87
  @staticmethod
102
88
  def process_issues_group(issues, prefix, add_message=""):
103
89
  result = ""
@@ -111,9 +97,8 @@ class BmcgoCommand:
111
97
  if add_message:
112
98
  result = f"{result}\n{add_message}\n"
113
99
  return result
114
-
115
- @staticmethod
116
- def filter_output():
100
+
101
+ def filter_output(self):
117
102
  output_path = os.path.join(os.environ["HOME"], "bmc_studio", "var", "data", "cli_data", "issues.json")
118
103
  try:
119
104
  with open(output_path, "r") as output_fp:
@@ -124,6 +109,8 @@ class BmcgoCommand:
124
109
  ci_enabled_issues = []
125
110
  disabled_issues = []
126
111
  for item in items:
112
+ if not self._filter_issue(item):
113
+ continue
127
114
  rule = item.get("rule")
128
115
  filepath = item.get("filepath")
129
116
  ci_enabled = item.get("ciEnabled")
@@ -153,30 +140,27 @@ class BmcgoCommand:
153
140
  self.packages[comp_name] = package
154
141
 
155
142
  def run(self):
156
- service_path = os.path.join(cwd, "mds", "service.json")
157
- if self.bconfig.manifest is None:
158
- if not os.path.isfile(service_path):
159
- raise RuntimeError("mds/service.json 文件不存在")
160
- with open(service_path, "r") as service_fp:
161
- self.service_dict = json.load(service_fp)
162
- if "name" not in self.service_dict:
163
- raise RuntimeError("mds/service.json 文件中缺少 name 配置")
164
- self.repo_name = self.service_dict.get("name")
165
- self.find_component_packages()
143
+ self._check_repo_config()
144
+ self._before_run()
145
+
166
146
  if self.disabled:
167
147
  log.info("%s 仓库没有开启语法正确性和模型一致性检查", self.repo_name)
168
148
  return 0
149
+
169
150
  with tempfile.TemporaryDirectory(prefix="dependencies_repo_") as tempdir:
170
151
  if self.bconfig.manifest:
171
152
  self.fetch_agent.code_path = tempdir
172
153
  self.fetch_agent.run()
173
154
  elif self.packages:
174
155
  FetchComponentCode(self.packages, tempdir, self.remote, include_open_source=False).run()
175
- cmd = [self.studio_path, "check", "--repo", cwd, "--dependencies", tempdir, "--model", self.model]
176
- if self.bconfig.manifest:
177
- cmd.append("--manifest")
178
- cmd.append("true")
156
+ cmd = self._get_studio_command(tempdir)
157
+
158
+ # 额外加入仓颉runtime的依赖库
159
+ insert_path = '/usr/share/bmc_studio/server'
179
160
  os.chdir(self.studio_dir)
161
+ cur_path = os.environ.get('LD_LIBRARY_PATH', '')
162
+ new_path = f"{insert_path}:{cur_path}"
163
+ os.environ['LD_LIBRARY_PATH'] = new_path
180
164
  Helper.run(cmd, stdout=subprocess.DEVNULL)
181
165
  os.chdir(cwd)
182
166
  error, warning = self.filter_output()
@@ -186,4 +170,64 @@ class BmcgoCommand:
186
170
  return -1
187
171
  log.warning(warning)
188
172
  log.success("语法正确性和模型一致性检查通过\n")
189
- return 0
173
+ return 0
174
+
175
+ def _init_common_attributes(self, parsed_args):
176
+ self.board_name = parsed_args.board_name
177
+ self.stage = parsed_args.stage
178
+ self.remote = parsed_args.remote
179
+ self.model = parsed_args.model
180
+ self.community_issues = set()
181
+ self.service_dict = {}
182
+ self.packages = {}
183
+ self.repo_branch = Repo(cwd).active_branch.name
184
+ self.repo_name = "manifest"
185
+ self.disabled = False
186
+ self.studio_dir = "/usr/share/bmc_studio/server"
187
+ self.studio_path = "/usr/share/bmc_studio/server/bmcstudio"
188
+
189
+ def _init_specific_attributes(self, parsed_args):
190
+ """初始化子类特有属性,由子类自行实现"""
191
+ pass
192
+
193
+ def _check_repo_config(self):
194
+ service_path = os.path.join(cwd, "mds", "service.json")
195
+ if self.bconfig.manifest is None:
196
+ if not os.path.isfile(service_path):
197
+ raise RuntimeError("mds/service.json 文件不存在")
198
+ with open(service_path, "r") as service_fp:
199
+ self.service_dict = json.load(service_fp)
200
+ if "name" not in self.service_dict:
201
+ raise RuntimeError("mds/service.json 文件中缺少 name 配置")
202
+ self.repo_name = self.service_dict.get("name")
203
+ self.find_component_packages()
204
+
205
+
206
+ def _get_studio_command(self, tempdir: str):
207
+ cmd = [self.studio_path, "check", "--repo", cwd, "--dependencies", tempdir, "--model", self.model]
208
+ if self.bconfig.manifest:
209
+ cmd.extend(["--manifest", "true"])
210
+ cmd.extend(["--board", self.board_name])
211
+ return cmd
212
+
213
+ def _filter_issue(self, item):
214
+ """过滤,由子类实现"""
215
+ _ = self
216
+ return True
217
+
218
+ def _before_run(self):
219
+ """主流程中的钩子函数, 由子类实现"""
220
+ pass
221
+
222
+ def _create_parser(self):
223
+ """命令参数,子类可重写"""
224
+ parser = argparse.ArgumentParser(prog=f"{misc.tool_name()} check", description="语法正确性与模型一致性检查", add_help=True,
225
+ formatter_class=argparse.RawTextHelpFormatter)
226
+ parser.add_argument("-b", "--board_name",
227
+ help="指定单板获取配套全量源码,可选值为build/product目录下的单板名\n默认:" + self.BOARD_NAME_DEFAULT,
228
+ default=self.BOARD_NAME_DEFAULT)
229
+ parser.add_argument("--stage", help="包类型,可选值为:rc(预发布包), stable(发布包)\n默认: stable", default="stable")
230
+ parser.add_argument("-r", "--remote")
231
+ parser.add_argument("-m", "--model", help=f"检查的模型,可选值为: {', '.join(self.MODEL_CHOICES)}\n默认: all",
232
+ choices=self.MODEL_CHOICES, default="all")
233
+ return parser
@@ -234,7 +234,7 @@ class BmcgoCommand:
234
234
 
235
235
  dt_stat = os.environ.get("BMCGO_DT_RUN", "off")
236
236
  show_log = True if dt_stat == "off" else False
237
- pkg = self.name + "/" + self.version + "@" + self.user + "/" + self.channel
237
+ pkg = packake_name + "/" + self.version + "@" + self.user + "/" + self.channel
238
238
  append_cmd = f"-r {self.remote}" if self.remote else ""
239
239
  cmd = "conan create . {} -pr={} -pr:b profile.dt.ini {} {} -tf None {}".format(
240
240
  pkg, self.profile, setting, append_cmd, options
@@ -23,11 +23,12 @@ from bmcgo.bmcgo_config import BmcgoConfig
23
23
 
24
24
  tool = Tools("config")
25
25
  log = tool.log
26
+ TOOLNAME = misc.tool_name()
26
27
 
27
28
  command_info: misc.CommandInfo = misc.CommandInfo(
28
29
  group=misc.GRP_MISC,
29
30
  name="config",
30
- description=["bingo参数配置"],
31
+ description=[f"{TOOLNAME}参数配置"],
31
32
  hidden=False
32
33
  )
33
34
 
@@ -39,19 +40,19 @@ def if_available(bconfig: BmcgoConfig):
39
40
  _CONFIGS = {
40
41
  misc.ENV_CONST: {
41
42
  misc.HTTP_PROXY_CONST: {
42
- misc.DESCRIPTION: "bingo 使用的 http_proxy 环境变量",
43
+ misc.DESCRIPTION: f"{TOOLNAME} 使用的 http_proxy 环境变量",
43
44
  misc.PATTERN: r"^((https?://)?[a-zA-Z0-9.]+:[0-9]+)?$"
44
45
  },
45
46
  misc.HTTPS_PROXY_CONST: {
46
- misc.DESCRIPTION: "bingo 使用的 https_proxy 环境变量",
47
+ misc.DESCRIPTION: f"{TOOLNAME} 使用的 https_proxy 环境变量",
47
48
  misc.PATTERN: r"^((https?://)?[a-zA-Z0-9.]+:[0-9]+)?$"
48
49
  },
49
50
  misc.FTP_PROXY_CONST: {
50
- misc.DESCRIPTION: "bingo 使用的 ftp_proxy 环境变量",
51
+ misc.DESCRIPTION: f"{TOOLNAME} 使用的 ftp_proxy 环境变量",
51
52
  misc.PATTERN: r"^((https?://)?[a-zA-Z0-9.]+:[0-9]+)?$"
52
53
  },
53
54
  misc.NO_PROXY_CONST: {
54
- misc.DESCRIPTION: "bingo 使用的 no_proxy 环境变量"
55
+ misc.DESCRIPTION: f"{TOOLNAME} 使用的 no_proxy 环境变量"
55
56
  },
56
57
  misc.TIMESTAMP_SIGN_SERVER: {
57
58
  misc.DESCRIPTION: "用于 jar 文件签名的时间戳签名服务器环境变量",
@@ -64,6 +65,9 @@ _CONFIGS = {
64
65
  misc.JSON_CHECKER: {
65
66
  misc.DESCRIPTION: "检查 json 文件的工具"
66
67
  },
68
+ misc.HPM_SIGNER: {
69
+ misc.DESCRIPTION: "HPM 重签名工具"
70
+ },
67
71
  misc.CUSTOM_PLUGINS: {
68
72
  misc.DESCRIPTION: f"设置插件地址,默认 {Path(misc.DEFAULT_PLUGINS_PATH).resolve()}"
69
73
  }
@@ -98,27 +102,27 @@ _DESCRIPTION = f"""
98
102
  2. 全局配置文件: ~/.bmcgo/config
99
103
  3. 本地配置文件: .bmcgo/config
100
104
  {gen_conf_str()}
101
- - 通过 bingo config 设置的环境变量(env.x)会写入到环境变量配置文件中。
105
+ - 通过 {TOOLNAME} config 设置的环境变量(env.x)会写入到环境变量配置文件中。
102
106
  指令参考:
103
107
  1. 配置全局参数:
104
- bingo config env.{misc.HTTP_PROXY_CONST}=http://proxy.example.com:8080
108
+ {TOOLNAME} config env.{misc.HTTP_PROXY_CONST}=http://proxy.example.com:8080
105
109
  2. 配置本地参数:
106
- bingo config --local env.{misc.HTTP_PROXY_CONST}=http://proxy.example.com:8080
110
+ {TOOLNAME} config --local env.{misc.HTTP_PROXY_CONST}=http://proxy.example.com:8080
107
111
  3. 查看生效配置:
108
- bingo config -l
112
+ {TOOLNAME} config -l
109
113
  4. 取消全局参数配置:
110
- bingo config --unset env.{misc.HTTP_PROXY_CONST}
114
+ {TOOLNAME} config --unset env.{misc.HTTP_PROXY_CONST}
111
115
  5. 取消本地参数配置:
112
- bingo config --local --unset env.{misc.HTTP_PROXY_CONST}
116
+ {TOOLNAME} config --local --unset env.{misc.HTTP_PROXY_CONST}
113
117
  6. 设置时间戳签名服务器:
114
- bingo config env.{misc.TIMESTAMP_SIGN_SERVER}=http://url.example.com
118
+ {TOOLNAME} config env.{misc.TIMESTAMP_SIGN_SERVER}=http://url.example.com
115
119
  7. 设置 JarSigner HTTP 代理主机:
116
- bingo config env.{misc.JARSIGNER_HTTP_PROXY}=http://proxy.example.com:8080
120
+ {TOOLNAME} config env.{misc.JARSIGNER_HTTP_PROXY}=http://proxy.example.com:8080
117
121
  8. 设置部署配置:
118
- 格式: bingo config deploy-<host>.<port|username|password>=<value>. host 既可以是主机名也可以是域名或 IP
119
- bingo config deploy-192.168.1.1.port=443
120
- bingo config deploy-192.168.1.1.username=UserName
121
- bingo config deploy-192.168.1.1.password=Password
122
+ 格式: {TOOLNAME} config deploy-<host>.<port|username|password>=<value>. host 既可以是主机名也可以是域名或 IP
123
+ {TOOLNAME} config deploy-192.168.1.1.port=443
124
+ {TOOLNAME} config deploy-192.168.1.1.username=UserName
125
+ {TOOLNAME} config deploy-192.168.1.1.password=Password
122
126
  """
123
127
 
124
128
 
@@ -134,7 +138,7 @@ def save_config_file(config, config_path):
134
138
  class BmcgoCommand:
135
139
  def __init__(self, bconfig: BmcgoConfig, *args):
136
140
  self.parser = argparse.ArgumentParser(
137
- prog="bingo参数配置",
141
+ prog=f"{TOOLNAME}参数配置",
138
142
  description=_DESCRIPTION,
139
143
  add_help=True,
140
144
  formatter_class=argparse.RawTextHelpFormatter
@@ -160,8 +160,36 @@ command_info: CommandInfo = CommandInfo(
160
160
  class BmcgoCommand:
161
161
  def __init__(self, bconfig: BmcgoConfig, *args):
162
162
  self.bconfig = bconfig
163
+ parser = self.get_arg_parser()
164
+ parsed_args, _ = parser.parse_known_args(*args)
165
+ self.csr_path = os.path.realpath(parsed_args.path)
166
+ self.single = parsed_args.single
167
+ self.oem_path = parsed_args.oem
168
+ self.output_path = os.path.realpath(parsed_args.output_path)
169
+ self.json = parsed_args.json
170
+ self.bin = parsed_args.bin
171
+ self.hpm = parsed_args.hpm
172
+ self.all = parsed_args.all
173
+ self.tar = parsed_args.tar
174
+ self.frud = parsed_args.frud
175
+ self.max_size_map = parsed_args.max_config
176
+ self.uid = parsed_args.uid
177
+ # 保留原始参数集,用于重写初始化函数扩展参数解析
178
+ self.parsed_args = parsed_args
179
+ self.work_dir = None
180
+ self.target_dir = None
181
+ self.eeprom_sign_strategy = None
182
+ self.hpm_sign_strategy = None
183
+ self.tmp_dir = None
184
+ self.merger = Merger(self.output_path)
185
+
186
+ @staticmethod
187
+ def get_arg_parser():
188
+ '''
189
+ 参数解析类扩展点,可重写此方法扩展自定义参数
190
+ '''
163
191
  parser = argparse.ArgumentParser(
164
- prog="bingo build_csr",
192
+ prog=f"{misc.tool_name()} build_csr",
165
193
  description="csr出包,支持单个CSR和批量CSR出包",
166
194
  add_help=True,
167
195
  formatter_class=argparse.RawTextHelpFormatter,
@@ -189,25 +217,7 @@ class BmcgoCommand:
189
217
  help="eeprom大小限制的json配置文件路径,无配置时默认限制为32k",
190
218
  default=EEPROM_SIZE_LIMIT_CONFIG
191
219
  )
192
- parsed_args, _ = parser.parse_known_args(*args)
193
- self.csr_path = os.path.realpath(parsed_args.path)
194
- self.single = parsed_args.single
195
- self.oem_path = parsed_args.oem
196
- self.output_path = os.path.realpath(parsed_args.output_path)
197
- self.json = parsed_args.json
198
- self.bin = parsed_args.bin
199
- self.hpm = parsed_args.hpm
200
- self.all = parsed_args.all
201
- self.tar = parsed_args.tar
202
- self.frud = parsed_args.frud
203
- self.max_size_map = parsed_args.max_config
204
- self.uid = parsed_args.uid
205
- self.work_dir = None
206
- self.target_dir = None
207
- self.eeprom_sign_strategy = None
208
- self.hpm_sign_strategy = None
209
- self.tmp_dir = None
210
- self.merger = Merger(self.output_path)
220
+ return parser
211
221
 
212
222
  @staticmethod
213
223
  def get_oem_data(dir_path: str, comp_name: str):
@@ -269,7 +279,7 @@ class BmcgoCommand:
269
279
  self.get_hpm_sign_strategy()
270
280
 
271
281
  def make_sr_binary(self, options: SrMakeOptions, hpm_temp_dir: str, max_size: int):
272
- eeprom_build_controller = EepromBuild(self.bconfig, options, self.work_dir, self.eeprom_sign_strategy)
282
+ eeprom_build_controller = self._get_eeprom_builder(options)
273
283
  eeprom_data = eeprom_build_controller.build_eeprom()
274
284
  if len(eeprom_data) > max_size * 1024 - 40:
275
285
  raise errors.BmcGoException(f"Eeprom二进制文件大小超过限制: {options.comp_name}")
@@ -293,6 +303,8 @@ class BmcgoCommand:
293
303
  with open(binary_files[0], 'wb') as f:
294
304
  f.write(eeprom_data)
295
305
  for binary_file in binary_files[1:]:
306
+ if binary_file == binary_files[0]:
307
+ continue
296
308
  shutil.copy(binary_files[0], binary_file)
297
309
 
298
310
  def run(self):
@@ -325,12 +337,11 @@ class BmcgoCommand:
325
337
  hpm_file = os.path.join(self.target_dir, f"{sr_make_options_list[0].comp_name}.hpm")
326
338
  else:
327
339
  hpm_file = os.path.join(self.target_dir, f"CSR-{get_timestamp()}.hpm")
328
- params = (self.bconfig, hpm_file, self.work_dir, self.hpm_sign_strategy)
329
- hpm_package = HpmBuild(*params)
340
+ hpm_package = self._get_hpm_builder(hpm_file)
330
341
  log.info("开始执行hpm包构建任务...")
331
342
  hpm_package.run()
332
343
  if self.single or self.frud or self.tar:
333
- output_file = os.path.join(self.output_path, f"bingo-{get_timestamp()}.tar.gz")
344
+ output_file = os.path.join(self.output_path, f"{misc.tool_name()}-{get_timestamp()}.tar.gz")
334
345
  tar_command = ['tar', '-czf', output_file, "-C", self.target_dir, "."]
335
346
  try:
336
347
  result = subprocess.run(tar_command, check=True)
@@ -340,12 +351,11 @@ class BmcgoCommand:
340
351
  else:
341
352
  output_hpm_file = os.path.join(self.output_path, os.path.basename(hpm_file))
342
353
  shutil.copy(hpm_file, output_hpm_file)
354
+ log.info(f"成功创建hpm包{os.path.basename(output_hpm_file)}")
343
355
  log.info("构建成功!")
344
356
  finally:
345
- if os.path.exists(self.work_dir):
346
- shutil.rmtree(self.work_dir)
347
- if os.path.exists(self.tmp_dir):
348
- shutil.rmtree(self.tmp_dir)
357
+ shutil.rmtree(self.work_dir, ignore_errors=True)
358
+ shutil.rmtree(self.tmp_dir, ignore_errors=True)
349
359
 
350
360
  def check_args(self):
351
361
  has_single_need_arg = self.bin or self.json or self.hpm or self.all
@@ -442,6 +452,19 @@ class BmcgoCommand:
442
452
  else:
443
453
  return False
444
454
 
455
+ def _get_hpm_builder(self, hpm_file: str):
456
+ '''
457
+ Hpm包构造器扩展点
458
+ '''
459
+ params = (self.bconfig, hpm_file, self.work_dir, self.hpm_sign_strategy)
460
+ return HpmBuild(*params)
461
+
462
+ def _get_eeprom_builder(self, option: SrMakeOptions):
463
+ '''
464
+ Eeprom内容构造器扩展点
465
+ '''
466
+ return EepromBuild(self.bconfig, option, self.work_dir, self.eeprom_sign_strategy)
467
+
445
468
 
446
469
  class EepromBuild:
447
470
  def __init__(self, bconfig, options, work_dir, strategy):
@@ -623,7 +646,7 @@ class EepromBuild:
623
646
  # 创建数字签名域数据
624
647
  def sign_eeprom(self, un_sign_data: bytearray):
625
648
  if self.strategy == SignatureTypeEnum.DEFAULT:
626
- return self.get_eeprom_default_sign()
649
+ return self._get_eeprom_default_sign(un_sign_data)
627
650
  elif not (self.strategy == SignatureTypeEnum.SERVER_SIGN or
628
651
  self.strategy == SignatureTypeEnum.SELF_SIGN):
629
652
  raise errors.BmcGoException("Invalid signing strategy.")
@@ -642,9 +665,6 @@ class EepromBuild:
642
665
  if os.path.exists(tmp_sign_path):
643
666
  shutil.rmtree(tmp_sign_path)
644
667
  return self.build_sign(sign_data)
645
-
646
- def get_eeprom_default_sign(self):
647
- return bytearray(self.sign_len)
648
668
 
649
669
  def get_eeprom_self_sign(self, un_sign_data):
650
670
  signing_key = self.load_key()
@@ -765,6 +785,9 @@ class EepromBuild:
765
785
  # 12. CRC32 校验和(4字节)
766
786
  eeprom_header_buf.put_uint32(self.get_crc32_check_sum(eeprom_header_buf.array()))
767
787
  return eeprom_header_buf.array()
788
+
789
+ def _get_eeprom_default_sign(self, _):
790
+ return bytearray(self.sign_len)
768
791
 
769
792
 
770
793
  class EepromHeader:
@@ -814,6 +837,7 @@ class HpmBuild:
814
837
 
815
838
  @staticmethod
816
839
  def sign_hpm_default():
840
+ log.info("未配置签名策略,跳过hpm包签名...")
817
841
  cms_file = os.path.realpath("image.filelist.cms")
818
842
  tool.pipe_command([f"echo 'cms placeholder'"], out_file=cms_file)
819
843
  crl_file = os.path.realpath("crldata.crl")
@@ -852,14 +876,13 @@ class HpmBuild:
852
876
  # 对hpm包进行签名
853
877
  def sign_hpm(self):
854
878
  if self.strategy == SignatureTypeEnum.DEFAULT:
855
- log.info("未配置签名策略,跳过hpm包签名...")
856
879
  self.sign_hpm_default()
857
880
  elif self.strategy == SignatureTypeEnum.SELF_SIGN or\
858
881
  self.strategy == SignatureTypeEnum.SERVER_SIGN:
859
882
  # 生成.filelist文件
860
883
  tool.run_command(f"cms_sign_hpm.sh 1 {self.hpm_name}", command_echo=False)
861
884
  shutil.copy("devkit.filelist", "image.filelist")
862
- SignGenerator(self.bconfig, self.strategy, "image.filelist").sign_generate()
885
+ self._get_generator().sign_generate()
863
886
  else:
864
887
  raise errors.BmcGoException("Invalid signing strategy.")
865
888
 
@@ -879,6 +902,12 @@ class HpmBuild:
879
902
  self.sign_hpm()
880
903
  self.rebuild_hpm()
881
904
 
905
+ def _get_generator(self):
906
+ '''
907
+ 签名工具扩展点
908
+ '''
909
+ return SignGenerator(self.bconfig, self.strategy, "image.filelist")
910
+
882
911
 
883
912
  class SignGenerator:
884
913
  def __init__(self, bconfig: BmcgoConfig, sign_strategy: str, unsigned_file: str):
@@ -185,7 +185,8 @@ class UpgradeTask(Process):
185
185
  class BmcgoCommand:
186
186
  def __init__(self, bconfig: BmcgoConfig, *args):
187
187
  self.bconfig = bconfig
188
- parser = argparse.ArgumentParser(prog="bingo deploy", description="BMC产品包部署升级,待部署主机配置由bmcgo config命令管理",
188
+ self.config_name = ".openUBMC_config.yml"
189
+ parser = argparse.ArgumentParser(prog="bingo deploy", description="BMC产品包部署升级,待部署主机配置由bingo config命令管理",
189
190
  add_help=True, formatter_class=argparse.RawTextHelpFormatter)
190
191
  parser.add_argument("-f", "--filename", help="待部署的文件", required=True)
191
192
  parsed_args = parser.parse_args(*args)
@@ -230,9 +231,9 @@ class BmcgoCommand:
230
231
  def _read_yml_hosts(self):
231
232
  tasks: list[UpgradeTask] = []
232
233
  cur_dir = os.getcwd()
233
- log.info("从当前路径开始向上递归查找.openUBMC_config.yml文件")
234
+ log.info(f"从当前路径开始向上递归查找 {self.config_name} 文件")
234
235
  while cur_dir != "/":
235
- cfg_file = os.path.join(cur_dir, ".openUBMC_config.yml")
236
+ cfg_file = os.path.join(cur_dir, self.config_name)
236
237
  if not os.path.isfile(cfg_file):
237
238
  cur_dir = os.path.dirname(cur_dir)
238
239
  continue