修复Bytes文件生成
This commit is contained in:
parent
1c9c361f99
commit
56717ade89
@ -844,6 +844,7 @@ class IntegratedPipeline:
|
||||
success_count = 0
|
||||
failed_list = []
|
||||
success_list = []
|
||||
config_containers = {} # 保存每个配置的 container 对象 {struct_name: container}
|
||||
file_list = cfg.get('file_list', [])
|
||||
|
||||
self.log(f" 找到 {len(file_list)} 个配置项\n\n")
|
||||
@ -851,7 +852,7 @@ class IntegratedPipeline:
|
||||
# 注意:现在只生成 AllConfigs.bytes,不生成单个配置的 bytes 文件
|
||||
self.log(f" ℹ 新策略:只生成 AllConfigs.bytes(合并文件),跳过单个 bytes 文件生成\n\n")
|
||||
|
||||
# 收集所有成功处理的配置名称,用于生成 AllConfigs
|
||||
# 收集所有成功处理的配置对象,用于生成 AllConfigs
|
||||
for idx, config_item in enumerate(file_list, 1):
|
||||
in_file = config_item.get('in_file', '')
|
||||
out_file = config_item.get('out_file', '')
|
||||
@ -996,10 +997,11 @@ class IntegratedPipeline:
|
||||
|
||||
setattr(container, f"{struct_name.lower()}s", container_items)
|
||||
|
||||
# 不再生成单个 bytes 文件,只验证配置可以成功处理
|
||||
# 不再生成单个 bytes 文件,但保存 container 对象用于生成 AllConfigs
|
||||
self.log(f" [OK] {struct_name} 验证通过(数据行数: {len(data_rows)})\n")
|
||||
success_count += 1
|
||||
success_list.append(struct_name)
|
||||
config_containers[struct_name] = container # 保存 container 对象
|
||||
|
||||
# 原始:定期刷新UI
|
||||
if idx % 10 == 0 or idx == 1 or idx == len(file_list):
|
||||
@ -1025,7 +1027,7 @@ class IntegratedPipeline:
|
||||
# 生成 AllConfigs.bytes(唯一的 bytes 文件)
|
||||
self.log(f"\n生成 AllConfigs.bytes(合并所有配置)...\n")
|
||||
allconfigs_generated = False
|
||||
if self.generate_all_configs_bytes(success_list):
|
||||
if self.generate_all_configs_bytes(config_containers):
|
||||
self.log(f" [OK] AllConfigs.bytes 生成成功\n")
|
||||
allconfigs_generated = True
|
||||
else:
|
||||
@ -1394,8 +1396,11 @@ class IntegratedPipeline:
|
||||
# 默认为 string
|
||||
return ('string', '""')
|
||||
|
||||
def generate_all_configs_bytes(self, struct_names: List[str]) -> bool:
|
||||
"""生成 AllConfigs.bytes(合并所有配置)"""
|
||||
def generate_all_configs_bytes(self, config_data_map: Dict[str, Any]) -> bool:
|
||||
"""
|
||||
生成 AllConfigs.bytes(合并所有配置)
|
||||
参数 config_data_map: {struct_name: container_object} 的映射
|
||||
"""
|
||||
try:
|
||||
from thrift.protocol import TBinaryProtocol
|
||||
from thrift.transport import TTransport
|
||||
@ -1407,34 +1412,11 @@ class IntegratedPipeline:
|
||||
# 创建 AllConfigs 实例
|
||||
all_configs = AllConfigsClass()
|
||||
|
||||
# 读取每个配置的bytes文件并设置到AllConfigs
|
||||
for struct_name in struct_names:
|
||||
bytes_path = os.path.join(self.bytes_output_dir, f"{struct_name}.bytes")
|
||||
|
||||
if not os.path.exists(bytes_path):
|
||||
self.log(f" ⚠ {struct_name}.bytes 不存在,跳过\n")
|
||||
continue
|
||||
|
||||
# 直接使用传入的配置对象
|
||||
for struct_name, container in config_data_map.items():
|
||||
try:
|
||||
# 读取bytes文件
|
||||
with open(bytes_path, 'rb') as f:
|
||||
binary_data = f.read()
|
||||
|
||||
# 反序列化为对应的配置对象
|
||||
transport = TTransport.TMemoryBuffer(binary_data)
|
||||
protocol = TBinaryProtocol.TBinaryProtocol(transport)
|
||||
|
||||
# 动态导入模块并创建实例
|
||||
module_name = f"{struct_name}.ttypes"
|
||||
ttypes_module = importlib.import_module(module_name)
|
||||
container_class = getattr(ttypes_module, struct_name)
|
||||
|
||||
container = container_class()
|
||||
container.read(protocol)
|
||||
|
||||
# 设置到AllConfigs(字段名为PascalCase,与类型名相同)
|
||||
setattr(all_configs, struct_name, container)
|
||||
|
||||
self.log(f" [OK] 添加 {struct_name}\n")
|
||||
|
||||
except Exception as e:
|
||||
|
||||
Binary file not shown.
Loading…
Reference in New Issue
Block a user