Browse Source

jiaobe

master
dongchangxi 4 weeks ago
parent
commit
77f9bc8948
  1. 16
      script/factory_sliceing/download_print_out.py
  2. 75
      script/factory_sliceing/type_setting_order.py

16
script/factory_sliceing/download_print_out.py

@ -198,7 +198,12 @@ def read_pids_from_json(pid_file): @@ -198,7 +198,12 @@ def read_pids_from_json(pid_file):
# 检查JSON文件是否存在
if not os.path.exists(json_path):
print(f"错误: JSON文件不存在 - {json_path}")
return [], {}
return [], {}, ''
# 检查是否是文件而不是目录
if not os.path.isfile(json_path):
print(f"错误: 路径是目录而不是文件 - {json_path}")
return [], {}, ''
# 读取JSON文件
try:
@ -206,12 +211,17 @@ def read_pids_from_json(pid_file): @@ -206,12 +211,17 @@ def read_pids_from_json(pid_file):
data = json.load(f)
except Exception as e:
print(f"读取JSON文件失败: {e}")
return [], {}
return [], {}, ''
list_model_info = []
summary = data.get('summary')
print("summary=", summary)
selected_machine = summary['selected_machine']
# 安全获取 selected_machine
if isinstance(summary, dict):
selected_machine = summary.get('selected_machine', '')
else:
# 如果 summary 不是字典,尝试从根级别获取
selected_machine = data.get('selected_machine', '')
print("selected_machine=", selected_machine)
# 处理每个模型
for model in data.get('models', []):

75
script/factory_sliceing/type_setting_order.py

@ -82,32 +82,60 @@ def step1(versionId): @@ -82,32 +82,60 @@ def step1(versionId):
if not ossClient().object_exists(jsonFilePath):
return False
#下载文件到项目所在目录
dirNow = os.path.join(currentDir, 'batchPrint', versionId, 'json')
if not os.path.exists(dirNow):
os.makedirs(dirNow)
localFilePath = os.path.join(dirNow, f'{versionId}.json')
# 先下载JSON文件到临时位置,读取 selected_machine 值
tempDir = os.path.join(currentDir, 'batchPrint', 'temp', versionId)
if not os.path.exists(tempDir):
os.makedirs(tempDir)
localFilePath = os.path.join(tempDir, f'{versionId}.json')
ossClient().get_object_to_file(jsonFilePath, localFilePath)
#判断 json 文件里的 selected_machine 值是否是大机型
with open(localFilePath, 'r', encoding='utf-8') as f:
jsonData = json.load(f)
selectedMachine = jsonData.get('selected_machine')
# 修复:正确获取嵌套的 selected_machine 值
summary = jsonData.get('summary', {})
if isinstance(summary, str):
# 如果 summary 是字符串,可能是旧格式,尝试直接获取
selectedMachine = jsonData.get('selected_machine', '')
else:
selectedMachine = summary.get('selected_machine', '') if isinstance(summary, dict) else ''
dirNewName = ""
# 根据机型类型确定新的目录名,直接创建 batchPrint/10010_big 或 batchPrint/10010_small
batchPrintDir = os.path.join(currentDir, 'batchPrint')
if selectedMachine == '大机型':
#修改 dirNow 目录里的 versionId 命名为 versionId_big
dirNewName = os.path.join(dirNow, versionId + '_big')
os.rename(os.path.join(dirNow, versionId), dirNewName)
dirNewName = os.path.join(batchPrintDir, versionId + '_big')
else:
#修改 dirNow 目录里的 versionId 命名为 versionId_small
dirNewName = versionId + '_small'
os.rename(os.path.join(dirNow, versionId), dirNewName)
dirNewName = os.path.join(batchPrintDir, versionId + '_small')
# 如果新目录不存在,创建它
if not os.path.exists(dirNewName):
os.makedirs(dirNewName)
# 创建json子目录
jsonSubDir = os.path.join(dirNewName, 'json')
if not os.path.exists(jsonSubDir):
os.makedirs(jsonSubDir)
# 移动JSON文件到新目录
newJsonPath = os.path.join(jsonSubDir, f'{versionId}.json')
if os.path.exists(localFilePath):
if os.path.exists(newJsonPath):
os.remove(newJsonPath)
shutil.move(localFilePath, newJsonPath)
# 下载JPG文件(如果存在)
if ossClient().object_exists(jpgFilePath):
localJpgFilePath = os.path.join(dirNewName,"json", f'{versionId}.jpg')
localJpgFilePath = os.path.join(jsonSubDir, f'{versionId}.jpg')
ossClient().get_object_to_file(jpgFilePath, localJpgFilePath)
# 清理临时目录
try:
if os.path.exists(tempDir):
shutil.rmtree(tempDir)
except:
pass
return dirNewName
#根据下载下来的JSON文件传递,调用其它参数,进行处理
@ -158,11 +186,11 @@ def main(work_dir=None): @@ -158,11 +186,11 @@ def main(work_dir=None):
versionId = str(data)
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} 正在处理版次ID={versionId}')
#执行前,先删除指定目录下的所有文件
objFilePath = os.path.join(currentDir, 'batchPrint', versionId, 'data')
#判断目录是否存在,存在就直接删除
if os.path.exists(objFilePath):
shutil.rmtree(objFilePath)
#执行前,先删除可能存在的旧数据目录(包括 _big 和 _small)
for suffix in ['_big', '_small']:
objFilePath = os.path.join(currentDir, 'batchPrint', versionId + suffix, 'data')
if os.path.exists(objFilePath):
shutil.rmtree(objFilePath)
res = step1(versionId)
if res == False:
@ -170,11 +198,16 @@ def main(work_dir=None): @@ -170,11 +198,16 @@ def main(work_dir=None):
time.sleep(10)
continue
jsonFilePath = os.path.join(res, 'json', f'{versionId}.json')
step2(res,res, versionId)
# 确保 jsonFilePath 是文件而不是目录
if not os.path.isfile(jsonFilePath):
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} JSON文件不存在: {jsonFilePath},等待10秒')
time.sleep(10)
continue
step2(jsonFilePath, res, versionId)
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} 数据处理完成,等待10秒')
#判断下载的obj文件数量和json里的是否一致,排除arrange文件夹
objFilePath = os.path.join(currentDir, 'batchPrint', versionId, 'data')
objFilePath = os.path.join(res, 'data')
objCounts = 0
for file in os.listdir(objFilePath):
if file == 'arrange':

Loading…
Cancel
Save