合并程序
This commit is contained in:
1 parent
cc15c76e62
commit
968189dee9
22 files changed
+518
-480
No files matched your search
@@ -0,0 +1,2 @@
|
||||
# auto_sliceing_operate package
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
from utils.import_all_file import modify_file_dialog_path_and_import_all
|
||||
from utils.click_soft_button import clickFileIMportShow, clickBegingSlice
|
||||
import time
|
||||
|
||||
from utils.exe_operate import start_exe, click_confirm, close
|
||||
|
||||
|
||||
|
||||
#"C:/test/10192_small_No4/data"
|
||||
def BeginSliceing(folderPath):
|
||||
# 打开3d切片软件
|
||||
start_exe()
|
||||
time.sleep(1)
|
||||
#点击确认按钮
|
||||
click_confirm()
|
||||
#先打开导入文件的弹框
|
||||
clickFileIMportShow()
|
||||
time.sleep(1)
|
||||
#在输入路径导入obj文件
|
||||
isSuccess = modify_file_dialog_path_and_import_all(folderPath)
|
||||
if not isSuccess:
|
||||
print("导入文件失败")
|
||||
exit()
|
||||
#点击开始切片
|
||||
time.sleep(5)
|
||||
clickBegingSlice()
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
from .utils.import_all_file import modify_file_dialog_path_and_import_all
|
||||
from .utils.click_soft_button import clickFileIMportShow, clickBegingSlice
|
||||
import time
|
||||
from .utils.oss_redis import redisClient
|
||||
from .utils.exe_operate import start_exe, click_confirm, close
|
||||
from .utils.logs import log
|
||||
import os
|
||||
from .utils.request import requestApiToUpdateSliceStatusComplate
|
||||
|
||||
#"C:/test/10192_small_No4/data"
|
||||
def BeginSliceing(batchId,machineId, folderPath):
|
||||
# 打开3d切片软件
|
||||
start_exe()
|
||||
time.sleep(1)
|
||||
#点击确认按钮
|
||||
click_confirm()
|
||||
#先打开导入文件的弹框
|
||||
clickFileIMportShow()
|
||||
time.sleep(1)
|
||||
#在输入路径导入obj文件
|
||||
isSuccess = modify_file_dialog_path_and_import_all(folderPath)
|
||||
if not isSuccess:
|
||||
print("导入文件失败")
|
||||
exit()
|
||||
#点击开始切片
|
||||
time.sleep(5)
|
||||
log("开始切片")
|
||||
clickBegingSlice()
|
||||
log("切片结束")
|
||||
time.sleep(5)
|
||||
#切片完成之后,将切片文件打包成zip文件,上传到OSS,并且请求api 更新批次状态为切片完成
|
||||
requestApiToUpdateSliceStatusComplate(batchId, 0)
|
||||
# sadd 插入对应的队列
|
||||
r = redisClient()
|
||||
r.sadd('pb:begin_print_machine_'+machineId, batchId)
|
||||
|
||||
def main(work_dir=None):
|
||||
r = redisClient()
|
||||
while True:
|
||||
|
||||
#判断队列连接是否正常,进行重连
|
||||
if not r.ping():
|
||||
log("队列连接异常,进行重连")
|
||||
r = redisClient()
|
||||
time.sleep(10)
|
||||
continue
|
||||
|
||||
|
||||
data = r.spop('pb:to_sliceing')
|
||||
if data is None:
|
||||
log("队列为空")
|
||||
time.sleep(10)
|
||||
continue
|
||||
data = data.decode('utf-8')
|
||||
# 判断是否是字符串
|
||||
if not isinstance(data, str):
|
||||
log("取出的数据不是字符串")
|
||||
time.sleep(10)
|
||||
continue
|
||||
folderPath = os.path.join(work_dir, data)
|
||||
# data 格式为 batchId_machineType_No machineId
|
||||
batchId = data.split('_')[0] #批次ID
|
||||
# machineType = data.split('_')[1] #机型类型
|
||||
machineId = data.split('_')[2].replace('No', '') #机器ID
|
||||
BeginSliceing(batchId,machineId,folderPath)
|
||||
time.sleep(10)
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
from .utils import miniIo as mio
|
||||
import zipfile,time
|
||||
import os
|
||||
from .utils.oss_redis import redisClient
|
||||
from .utils.logs import log
|
||||
|
||||
# 打印机旁边的电脑下载切片文件到本地
|
||||
# 解压压缩包,将数据移动到指定的目录
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
# 从 minio 服务上下载 zip 文件到指定目录和解压
|
||||
def downloadZip(ossZipPath, localZipPath):
|
||||
# 下载 zip 文件
|
||||
mio.download_file(ossZipPath, localZipPath)
|
||||
|
||||
|
||||
def unzip(localZipPath, localUnzipPath):
|
||||
# 解压 zip 文件
|
||||
with zipfile.ZipFile(localZipPath, 'r') as zip_ref:
|
||||
zip_ref.extractall(localUnzipPath)
|
||||
|
||||
# 解压完成后删除 zip 文件
|
||||
os.remove(localZipPath)
|
||||
|
||||
def getCurrentMachineId():
|
||||
# 获取当前电脑的id
|
||||
return "1"
|
||||
|
||||
|
||||
def main(work_dir=None):
|
||||
if work_dir is None:
|
||||
log("工作目录不能为空")
|
||||
exit(0)
|
||||
# redis 获取队列中的数据
|
||||
r = redisClient()
|
||||
machineId = getCurrentMachineId()
|
||||
if machineId is None:
|
||||
log("获取当前电脑id失败")
|
||||
exit(0)
|
||||
while True:
|
||||
data = r.lpop('pb:begin_print_machine_'+machineId)
|
||||
if data is None:
|
||||
log("队列为空")
|
||||
time.sleep(10)
|
||||
continue
|
||||
data = data.decode('utf-8')
|
||||
# 判断是否是数字
|
||||
if not data.isdigit():
|
||||
log("取出的数据不是数字")
|
||||
time.sleep(10)
|
||||
continue
|
||||
batchId = str(data)
|
||||
ossZipPath = f'data/slice/{batchId}.zip'
|
||||
localZipPath = os.path.join(work_dir,batchId, f'{batchId}.zip')
|
||||
# 判断目录是否存在,不存在就创建
|
||||
if not os.path.exists(os.path.join(work_dir,batchId)):
|
||||
os.makedirs(os.path.join(work_dir,batchId))
|
||||
else:
|
||||
# 删除目录下的所有文件
|
||||
for file in os.listdir(os.path.join(work_dir,batchId)):
|
||||
os.remove(os.path.join(work_dir,batchId, file))
|
||||
|
||||
# 下载 zip 文件
|
||||
downloadZip(ossZipPath, localZipPath)
|
||||
# 解压 zip 文件
|
||||
localUnzipPath = os.path.join(work_dir,batchId)
|
||||
unzip(localZipPath, localUnzipPath)
|
||||
# 触发打印处理
|
||||
@@ -0,0 +1,2 @@
|
||||
# utils package
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import requests
|
||||
from .logs import log
|
||||
|
||||
url = 'https://mp.api.suwa3d.com'
|
||||
|
||||
def requestApiToUpdateSliceStatusComplate(versionId, downloadCounts):
|
||||
api_url = f"{url}/api/printTypeSettingOrder/updateBatchSliceing?batch_id={versionId}&is_slice_complete=1&download_counts=" + str(downloadCounts)
|
||||
log(f'发起状态变更请求url={api_url}, versionId={versionId}')
|
||||
try:
|
||||
# 添加超时参数,防止请求时间过长
|
||||
res = requests.post(api_url, timeout=60) # 60秒超时
|
||||
if res.status_code != 200:
|
||||
log(f'状态变更请求失败, res={res.text}')
|
||||
return False
|
||||
log(f'状态变更请求成功, res={res.text}')
|
||||
#判断返回的code是否是1000
|
||||
if res.json()["code"] != 1000:
|
||||
log(f'状态变更请求失败, res={res.text}')
|
||||
return False
|
||||
log(f'状态变更请求成功, res={res.text}')
|
||||
return True
|
||||
except requests.exceptions.Timeout:
|
||||
log(f'状态变更请求超时, url={api_url}')
|
||||
return False
|
||||
except requests.exceptions.RequestException as e:
|
||||
log(f'状态变更请求异常, error={str(e)}')
|
||||
return False
|
||||
@@ -66,4 +66,4 @@ def zip_file(folderPath, outputZipPath=None):
|
||||
# zip_file(folderPath)
|
||||
|
||||
|
||||
zip_file("/Users/dcx/code/make2/script/batchPrint/1","1024.zip")
|
||||
# zip_file("/Users/dcx/code/make2/script/batchPrint/1","1024.zip")
|
||||
Reference in new issue
Block a user