1#!/usr/bin/env python 2# -*- coding: utf-8 -*- 3 4# Copyright (c) 2023 Huawei Device Co., Ltd. 5# 6# HDF is dual licensed: you can use it either under the terms of 7# the GPL, or the BSD license, at your option. 8# See the LICENSE file in the root of this repository for complete details. 9 10 11import json 12import os 13import re 14import shutil 15import string 16 17import hdf_tool_settings 18import hdf_utils 19from command_line.hdf_command_error_code import CommandErrorCode 20from command_line.hdf_command_handler_base import HdfCommandHandlerBase 21from command_line.operate_group_passwd import OperateGroupPasswd 22from hdf_tool_exception import HdfToolException 23 24 25class HdiAddHandler(HdfCommandHandlerBase): 26 def __init__(self, args): 27 super(HdiAddHandler, self).__init__() 28 self.handlers = { 29 'interface': self._add_interface_handler, 30 'peripheral': self._add_peripheral_handler, 31 'unittest': self.create_unittest, 32 } 33 self.parser.add_argument("--action_type", 34 help=' '.join(self.handlers.keys()), 35 required=True) 36 self.parser.add_argument("--root_dir", required=True) 37 self.parser.add_argument("--vendor_name") 38 self.parser.add_argument("--interface_name") 39 self.parser.add_argument("--peripheral_name") 40 self.parser.add_argument("--board_name") 41 self.parser.add_argument("--version_number", type=float, default=1.0) 42 self.args = self.parser.parse_args(args) 43 self.set_config = hdf_tool_settings.HdfToolSettings() 44 self.result_json = { 45 "create_file": [], 46 "config": [] 47 } 48 self.space_num = 8 49 50 def _hdi_config_operation(self, opt_type, config_path): 51 file_config = hdf_utils.read_file(config_path) 52 file_json_type = json.loads(file_config) 53 for info in file_json_type['subsystems']: 54 if info.get("subsystem") == "hdf": 55 key_list_name = [] 56 for key_name in info.get("components"): 57 key_list_name.append(key_name.get('component')) 58 if self.args.interface_name: 59 component_name = 'drivers_%s_%s' % \ 60 (opt_type, self.args.interface_name) 61 elif self.args.peripheral_name: 62 component_name = 'drivers_%s_%s' % \ 63 (opt_type, self.args.peripheral_name) 64 else: 65 component_name = "" 66 if opt_type == "interface" and \ 67 component_name not in key_list_name: 68 interface_dict = { 69 'component': component_name, 70 'features': []} 71 info.get("components").append(interface_dict) 72 elif opt_type == "peripheral" and \ 73 component_name not in key_list_name: 74 peripheral_dict = { 75 'component': component_name, 76 'features': []} 77 info.get("components").append(peripheral_dict) 78 else: 79 pass 80 hdf_utils.write_file(config_path, 81 json.dumps(file_json_type, indent=4)) 82 return config_path 83 84 def get_template_file_folder(self, temp_folder_name): 85 template_folder_path = self.set_config.get_template_path() 86 pre_path = self.set_config.get_drivers_path_framework() 87 tempath_path = os.path.join(self.args.root_dir, 88 pre_path, template_folder_path) 89 hdi_template_path = "" 90 for pre_root, folders, _ in os.walk(tempath_path): 91 for folder_name in folders: 92 if folder_name.startswith("hdi"): 93 hdi_template_path = os.path.join( 94 pre_root, folder_name, temp_folder_name) 95 return hdi_template_path 96 97 def _check_arg(self, temp_type): 98 if temp_type == "interface": 99 self.check_arg_raise_if_not_exist('root_dir') 100 self.check_arg_raise_if_not_exist('interface_name') 101 self.check_arg_raise_if_not_exist('board_name') 102 self.check_arg_raise_if_not_exist('version_number') 103 interface_name = self.args.interface_name 104 root = self.args.root_dir 105 version = "v" + str(self.args.version_number).replace(".", "_") 106 interface_converter = hdf_utils.WordsConverter(interface_name) 107 return root, version, interface_converter, interface_name 108 elif temp_type == "peripheral": 109 self.check_arg_raise_if_not_exist('root_dir') 110 self.check_arg_raise_if_not_exist('vendor_name') 111 self.check_arg_raise_if_not_exist('peripheral_name') 112 self.check_arg_raise_if_not_exist('board_name') 113 self.check_arg_raise_if_not_exist('version_number') 114 version = "v" + str(self.args.version_number).replace(".", "_") 115 peripheral_name = self.args.peripheral_name 116 root = self.args.root_dir 117 vendor = self.args.vendor_name 118 board = self.args.board_name 119 peripheral_converter = hdf_utils.WordsConverter(peripheral_name) 120 return root, version, peripheral_converter, peripheral_name, board, vendor 121 elif temp_type == "unittest": 122 self.check_arg_raise_if_not_exist('root_dir') 123 self.check_arg_raise_if_not_exist('peripheral_name') 124 self.check_arg_raise_if_not_exist('board_name') 125 self.check_arg_raise_if_not_exist('version_number') 126 peripheral_name = self.args.peripheral_name 127 root = self.args.root_dir 128 peripheral_converter = hdf_utils.WordsConverter(peripheral_name) 129 replace_data = { 130 "peripheral_name": peripheral_converter.lower_case(), 131 "peripheral_name_capital_letters": peripheral_converter.upper_camel_case(), 132 "peripheral_name_upper": peripheral_converter.upper_case(), 133 } 134 return peripheral_name, root, peripheral_converter, replace_data 135 136 def _add_interface_handler(self): 137 root, version, interface_converter, interface_name = \ 138 self._check_arg(temp_type="interface") 139 hdi_template_path = self.get_template_file_folder( 140 temp_folder_name="interface") 141 interface_path = self.set_config.get_drivers_path_interface() 142 interface_folder_path = os.path.join( 143 self.args.root_dir, interface_path, self.args.interface_name) 144 if os.path.exists(interface_folder_path): 145 raise HdfToolException( 146 '"%s" is path exist' % interface_folder_path, 147 CommandErrorCode.TARGET_NOT_EXIST) 148 os.makedirs(interface_folder_path) 149 inter_name_version = os.path.join(interface_folder_path, version) 150 os.makedirs(inter_name_version) 151 replace_data = { 152 "interface_name": interface_converter.lower_case(), 153 "interface_name_capital_letters": interface_converter.upper_camel_case(), 154 "interface_name_upper": interface_converter.upper_case(), 155 } 156 for file in os.listdir(hdi_template_path): 157 file_src = file 158 if file.startswith("I"): 159 file = file.replace("interface", 160 interface_converter.upper_camel_case()) 161 file = '.'.join(file.split('.')[0].split('_')) 162 else: 163 file = '.'.join(file.split('.')[0].split('_')) 164 src_path = os.path.join(hdi_template_path, file_src) 165 if file.endswith("json"): 166 dst_path = os.path.join(interface_folder_path, file) 167 if not os.path.exists(dst_path): 168 file_info = self.template_replace(src_path, replace_data) 169 self._write_file(dst_path, file_info) 170 else: 171 dst_path = os.path.join(inter_name_version, file) 172 if not os.path.exists(dst_path): 173 file_info = self.template_replace(src_path, replace_data) 174 self._write_file(dst_path, file_info) 175 create_file_path = self.format_file_path(dst_path, root) 176 self.result_json["create_file"].append(create_file_path) 177 hdi_dict = self.set_config.get_hdi_config() 178 path_test = hdi_dict.get("interface", "") 179 operation_file = os.path.join(root, path_test.strip("/")) 180 re_config_path = self._hdi_config_operation( 181 opt_type="interface", config_path=operation_file) 182 config_file_path = self.format_file_path(re_config_path, root) 183 self.result_json["config"].append(config_file_path) 184 self.format_result_json( 185 hdi_dict, create_type="interface", target_name=interface_name) 186 return json.dumps(self.result_json, indent=4) 187 188 def _add_peripheral_handler(self): 189 root, version, peripheral_converter, peripheral_name, board, vendor = \ 190 self._check_arg(temp_type="peripheral") 191 replace_data = { 192 "peripheral_name": peripheral_converter.lower_case(), 193 "peripheral_name_capital_letters": peripheral_converter.upper_camel_case(), 194 "peripheral_name_upper": peripheral_converter.upper_case(), 195 } 196 pre_path = self.set_config.get_drivers_path_peripheral() 197 hdi_config_arg = self.set_config.get_hdi_config() 198 folder_name = hdi_config_arg["peripheral_folder"]["hdi_path"] 199 peripheral_folder = os.path.join(root, pre_path, peripheral_name) 200 hid_service_folder = os.path.join(peripheral_folder, folder_name) 201 out_path = hdi_config_arg["output_path"].format( 202 product=board, interface_name=peripheral_name) 203 full_out_path = os.path.join(root, out_path) 204 if not os.path.exists(full_out_path): 205 raise HdfToolException(msg="interface file does not compile", 206 error_code=CommandErrorCode.INTERFACE_ERROR) 207 if not os.path.exists(peripheral_folder): 208 os.makedirs(peripheral_folder) 209 if not os.path.exists(hid_service_folder): 210 os.makedirs(hid_service_folder) 211 # Copy the file to the current location 212 if os.path.exists(full_out_path): 213 for file_name_template in hdi_config_arg["move_list"]: 214 file_name = file_name_template.format( 215 interface_name=peripheral_name) 216 target_file_path = os.path.join( 217 root, out_path, version, file_name) 218 dst_file_path = os.path.join( 219 root, hid_service_folder, file_name) 220 if os.path.exists(target_file_path) and \ 221 not os.path.exists(dst_file_path): 222 shutil.copyfile(target_file_path, dst_file_path) 223 temp_create = self.format_file_path(dst_file_path, root) 224 self.result_json["create_file"].append(temp_create) 225 self._option_peripheral_config( 226 board, root, replace_data, hid_service_folder, peripheral_folder, vendor) 227 path_test = hdi_config_arg.get("peripheral", "") 228 operation_file = os.path.join(root, path_test.strip("/")) 229 self._hdi_config_operation(opt_type="peripheral", config_path=operation_file) 230 self.format_result_json(hdi_config_arg, create_type="peripheral", 231 target_name=peripheral_name) 232 return json.dumps(self.result_json, indent=4) 233 234 def _option_peripheral_config( 235 self, board, root, replace_data, hid_service_folder, 236 peripheral_folder, vendor): 237 hdi_template_path = self.get_template_file_folder( 238 temp_folder_name="peripheral") 239 file_list = os.listdir(hdi_template_path) 240 for template_file_name in file_list: 241 folder_file_path = os.path.join(hdi_template_path, template_file_name) 242 if os.path.isdir(folder_file_path): 243 self._hdi_server_config( 244 folder_file_path, board, root, replace_data, vendor) 245 continue 246 src_path = os.path.join(hdi_template_path, template_file_name) 247 if template_file_name.endswith("hdi"): 248 target_location = os.path.join(root, hid_service_folder) 249 target_file_name = template_file_name.split( 250 ".")[0].replace("_", ".") 251 target_file_path = os.path.join( 252 target_location, str(target_file_name)) 253 else: 254 target_file_name = template_file_name.split( 255 ".")[0].replace("_", ".") 256 target_file_path = os.path.join( 257 peripheral_folder, target_file_name) 258 if not os.path.exists(target_file_path): 259 file_info = self.template_replace(src_path, replace_data) 260 self._write_file(target_file_path, file_info) 261 temp_config = self.format_file_path(target_file_path, root) 262 self.result_json["create_file"].append(temp_config) 263 264 def _hdi_server_config(self, config_path, board_name, 265 root_path, replace_data, vendor): 266 template_list = os.listdir(config_path) 267 temp_hcs_path = os.path.join(config_path, template_list[0]) 268 for file_name in template_list: 269 if "hcs" in file_name: 270 hcs_file_name_temp = file_name.split(".")[0].replace("_", ".") 271 snake_case = re.sub( 272 r"(?P<key>[A-Z])", 273 r"_\g<key>", 274 hcs_file_name_temp) 275 hcs_name = snake_case.lower().strip('_') 276 277 board_type = "%s_user" % board_name 278 board_parent_path_temp = hdf_tool_settings.HdfToolSettings(). \ 279 get_board_parent_path(board_type) 280 board_parent_path = board_parent_path_temp.format(vendor=vendor) 281 hcs_file_parent = os.path.join(root_path, board_parent_path) 282 if os.path.exists(hcs_file_parent): 283 hcs_target_file = os.path.join( 284 root_path, board_parent_path, hcs_name) 285 else: 286 raise HdfToolException( 287 'hcs config path %s not exist' % hcs_file_parent) 288 lines = list(map( 289 lambda x: " " * self.space_num + x, 290 hdf_utils.read_file_lines(temp_hcs_path))) 291 old_lines_temp = hdf_utils.read_file_lines(hcs_target_file) 292 old_lines = list(filter(lambda x: x != "\n", old_lines_temp)) 293 status = False 294 for line in old_lines: 295 str_line = string.Template(lines[0]).substitute(replace_data) 296 if line.split("::")[0].strip() == str_line.split("::")[0].strip(): 297 status = True 298 if not status: 299 new_data = old_lines[:-2] + lines + old_lines[-2:] 300 for index, _ in enumerate(new_data): 301 new_data[index] = string.Template(new_data[index]).\ 302 substitute(replace_data) 303 hdf_utils.write_file_lines(hcs_target_file, new_data) 304 temp_config = self.format_file_path(hcs_target_file, root_path) 305 self.result_json["config"].append(temp_config) 306 self.config_group_passwd(root_path, replace_data) 307 308 def config_group_passwd(self, root_path, replace_data): 309 hdi_config = hdf_tool_settings.HdfToolSettings() 310 group_passwd = OperateGroupPasswd(tool_settings=hdi_config, root_path=root_path) 311 # group 312 peripheral_name = replace_data.get("peripheral_name") 313 group_file_path = group_passwd.operate_group(name=peripheral_name) 314 temp_config = self.format_file_path(group_file_path, root_path) 315 self.result_json["config"].append(temp_config) 316 # passwd 317 passwd_file_path = group_passwd.operate_passwd(name=peripheral_name) 318 temp_config = self.format_file_path(passwd_file_path, root_path) 319 self.result_json["config"].append(temp_config) 320 self.config_selinux(root_path, replace_data) 321 322 def config_selinux(self, root_path, replace_data): 323 hdi_config = hdf_tool_settings.HdiToolConfig() 324 # selinux --- type.te 325 pre_path, selinux_type_info = hdi_config.get_hdi_selinux_type() 326 temp_type_path = self._selinux_file_fill( 327 pre_path, selinux_temp=selinux_type_info, 328 root_path=root_path, replace_data=replace_data 329 ) 330 temp_config = self.format_file_path(temp_type_path, root_path) 331 self.result_json["config"].append(temp_config) 332 333 # selinux --- hdf_service.te 334 pre_path, selinux_hdf_service_info = hdi_config.get_hdi_selinux_hdf_service() 335 temp_hdf_service_path = self._selinux_file_fill( 336 pre_path, selinux_temp=selinux_hdf_service_info, 337 root_path=root_path, replace_data=replace_data 338 ) 339 temp_config = self.format_file_path(temp_hdf_service_path, root_path) 340 self.result_json["config"].append(temp_config) 341 342 # selinux --- hdf_service_contexts 343 pre_path, selinux_hdf_service_contexts_info = \ 344 hdi_config.get_hdi_selinux_hdf_service_contexts() 345 temp_service_contexts_path = self._selinux_file_fill( 346 pre_path, selinux_temp=selinux_hdf_service_contexts_info, 347 root_path=root_path, replace_data=replace_data, align=True 348 ) 349 temp_config = self.format_file_path(temp_service_contexts_path, root_path) 350 self.result_json["config"].append(temp_config) 351 352 # selinux --- hdf_host.te 353 pre_path, selinux_hdf_host = hdi_config.get_hdi_selinux_hdf_host() 354 temp_host_path = self._selinux_file_fill( 355 pre_path, selinux_temp=selinux_hdf_host, 356 root_path=root_path, replace_data=replace_data 357 ) 358 temp_config = self.format_file_path(temp_host_path, root_path) 359 self.result_json["config"].append(temp_config) 360 361 # selinux --- peripheral config 362 pre_path, selinux_peripheral_host = hdi_config.get_selinux_peripheral_hdf_host() 363 self._selinux_peripheral_config( 364 pre_path, selinux_temp=selinux_peripheral_host, 365 root_path=root_path, replace_data=replace_data 366 ) 367 368 def _selinux_peripheral_config(self, pre_path, selinux_temp, 369 root_path, replace_data): 370 peripheral_config_path = os.path.join(root_path, pre_path, selinux_temp["path"]) 371 temp_peripheral_path = string.Template( 372 peripheral_config_path).safe_substitute(replace_data) 373 if not os.path.exists(temp_peripheral_path): 374 os.makedirs(temp_peripheral_path) 375 config_list = selinux_temp.get('peripheral_file_list') 376 for key_name in list(config_list.keys()): 377 file_name = config_list.get(key_name) 378 temp_file_name = string.Template(file_name).safe_substitute(replace_data) 379 file_info = "".join(selinux_temp.get(key_name)) 380 temp_file_info = string.Template(file_info).safe_substitute(replace_data) 381 file_path = os.path.join(temp_peripheral_path, temp_file_name) 382 config_info = hdf_tool_settings.HdfToolSettings().get_file_config_info() 383 write_fd = os.open(file_path, config_info["flags"], config_info["modes"]) 384 with os.fdopen(write_fd, "wb") as f_write: 385 f_write.write(temp_file_info.encode("utf-8")) 386 temp_create = self.format_file_path(file_path, root_path) 387 self.result_json["create_file"].append(temp_create) 388 389 def create_unittest(self): 390 peripheral_name, root, peripheral_converter, replace_data =\ 391 self._check_arg(temp_type="unittest") 392 pre_path = self.set_config.get_drivers_path_peripheral() 393 peripheral_folder = os.path.join(root, pre_path, peripheral_name) 394 hdi_config_arg = self.set_config.get_hdi_config() 395 folder_name = hdi_config_arg["peripheral_folder"]["unittest_path"] 396 unittest_folder = os.path.join(peripheral_folder, folder_name) 397 if not os.path.exists(unittest_folder): 398 os.makedirs(unittest_folder) 399 unittest_template_path = self.get_template_file_folder( 400 temp_folder_name="unittest") 401 for template_file in os.listdir(unittest_template_path): 402 template_file_src = template_file 403 template_file = template_file.replace( 404 "name", peripheral_converter.lower_case()) 405 template_file = '.'.join(template_file.split('.')[0].rsplit('_', 1)) 406 src_path = os.path.join(unittest_template_path, template_file_src) 407 if template_file.endswith("gn"): 408 unittest_folder_upper_level = re.split(r'\w+$', unittest_folder)[0] 409 dst_path = os.path.join(unittest_folder_upper_level, template_file) 410 if not os.path.exists(dst_path): 411 file_info = self.template_replace(src_path, replace_data) 412 self._write_file(dst_path, file_info) 413 else: 414 dst_path = os.path.join(unittest_folder, template_file) 415 if not os.path.exists(dst_path): 416 file_info = self.template_replace(src_path, replace_data) 417 self._write_file(dst_path, file_info) 418 temp_create = self.format_file_path(dst_path, root) 419 self.result_json["create_file"].append(temp_create) 420 # add bundle.json test 421 for file_name in os.listdir(peripheral_folder): 422 if file_name.endswith(".json"): 423 config_json_path = os.path.join(peripheral_folder, file_name) 424 file_info_str = hdf_utils.read_file(config_json_path) 425 file_info_json = json.loads(file_info_str) 426 pre_dict = file_info_json['component']["build"] 427 temp_str = pre_dict[list(pre_dict.keys())[0]][0].split(":")[0] 428 result_test_str = "/".join([temp_str, "test:{peripheral_name}_unittest". 429 format(peripheral_name=peripheral_name)]) 430 if result_test_str not in pre_dict[list(pre_dict.keys())[1]]: 431 pre_dict[list(pre_dict.keys())[1]].append(result_test_str) 432 hdf_utils.write_file(config_json_path, 433 content=json.dumps(file_info_json, indent=4)) 434 temp_create = self.format_file_path(config_json_path, root) 435 self.result_json["config"].append(temp_create) 436 self.format_result_json(hdi_config_arg, create_type="unittest", 437 target_name=peripheral_name) 438 return json.dumps(self.result_json, indent=4) 439 440 def _selinux_file_fill(self, pre_path, selinux_temp, 441 root_path, replace_data, align=False): 442 temp_file_name = selinux_temp["file_name"] 443 target_config_file_path = os.path.join( 444 root_path, pre_path, selinux_temp["path"], temp_file_name) 445 if not os.path.exists(target_config_file_path): 446 raise HdfToolException( 447 'file: %s not exist' % 448 target_config_file_path, CommandErrorCode.TARGET_NOT_EXIST) 449 temp_lines = self.read_lines_binary(path=target_config_file_path) 450 if isinstance(selinux_temp["info_temp"], str): 451 if align: 452 temp_new_line = string.Template( 453 selinux_temp["info_temp"]).safe_substitute(replace_data) 454 temp_line = temp_new_line.split(" ") 455 space_num = selinux_temp["space_len"] - len(temp_line[0]) 456 new_line = (" " * space_num).join(temp_line) 457 else: 458 new_line = string.Template( 459 selinux_temp["info_temp"]).safe_substitute(replace_data) 460 temp_replace_list = [new_line.encode('utf-8')] 461 elif isinstance(selinux_temp["info_temp"], list): 462 hdf_host_pid_list = self.count_hdf_host_pid(temp_lines) 463 replace_data.update({ 464 "pid_num": OperateGroupPasswd.generate_id(max(hdf_host_pid_list)) 465 }) 466 temp_replace_list = [] 467 splice_str = "" 468 for temp_line in selinux_temp["info_temp"]: 469 splice_str += temp_line 470 temp_replace_list.append( 471 string.Template(temp_line).safe_substitute( 472 replace_data).encode('utf-8')) 473 temp_replace_list = temp_replace_list[2:] 474 new_line = string.Template(splice_str).safe_substitute(replace_data) 475 else: 476 temp_replace_list = [] 477 new_line = "" 478 if not set(temp_replace_list) < set(temp_lines): 479 new_line_temp = new_line.encode('utf-8') 480 temp_lines.append(new_line_temp) 481 self.writer_lines_binary(target_config_file_path, temp_lines) 482 return target_config_file_path 483 484 def template_replace(self, src_path, replace_data): 485 file_info = hdf_utils.read_file(src_path) 486 str_header = string.Template(file_info) 487 res_info = str_header.substitute(replace_data) 488 return res_info 489 490 def _write_file(self, dst_path, file_info): 491 hdf_utils.write_file(dst_path, content=file_info) 492 493 def count_hdf_host_pid(self, temp_lines): 494 hdf_host_pid_list = [] 495 for line in temp_lines: 496 line = line.strip().decode("utf-8") 497 pid_re_result = re.search(r"pid=\d+", line) 498 if pid_re_result: 499 pid_num = int(pid_re_result.group().split("=")[-1]) 500 if pid_num not in hdf_host_pid_list: 501 hdf_host_pid_list.append(pid_num) 502 return hdf_host_pid_list 503 504 def format_file_path(self, file_path, parent_root): 505 file_path_temp = file_path.lstrip(parent_root) 506 temp_path_list = file_path_temp.split(os.path.sep) 507 temp_path = "/".join(temp_path_list) 508 return temp_path 509 510 def format_result_json(self, config_dict, create_type, target_name): 511 out_config_name = config_dict.get("out_config_name") 512 if not out_config_name: 513 out_config_name = "create_idl_hdi.config" 514 config_parent = self.set_config.get_hdi_file_path() 515 out_config_path = os.path.join(config_parent, out_config_name) 516 if not os.path.exists(out_config_path): 517 raise HdfToolException( 518 '"%s" is path exist' % 519 out_config_path, CommandErrorCode.TARGET_NOT_EXIST) 520 read_file_info = hdf_utils.read_file(out_config_path) 521 read_file_json = json.loads(read_file_info) 522 temp_dict = { 523 target_name: self.result_json 524 } 525 if create_type == "interface": 526 create_interface_info = read_file_json.get("interface") 527 if create_interface_info and not create_interface_info.get(target_name, False): 528 create_interface_info.update(temp_dict) 529 else: 530 read_file_json["interface"] = temp_dict 531 elif create_type == "peripheral": 532 create_interface_info = read_file_json.get("peripheral") 533 if create_interface_info and not create_interface_info.get(target_name, False): 534 create_interface_info.update(temp_dict) 535 else: 536 read_file_json["peripheral"] = temp_dict 537 elif create_type == "unittest": 538 create_interface_info = read_file_json.get("unittest") 539 if create_interface_info and not create_interface_info.get(target_name, False): 540 create_interface_info.update(temp_dict) 541 else: 542 read_file_json["unittest"] = temp_dict 543 hdf_utils.write_file(out_config_path, json.dumps(read_file_json, indent=4)) 544 545 def read_lines_binary(self, path): 546 with open(path, "rb") as f_read: 547 read_lines = f_read.readlines() 548 return read_lines 549 550 def writer_lines_binary(self, file_path, content): 551 with open(file_path, 'wb') as file_write: 552 file_write.writelines(content) 553