You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
2.4 KiB
78 lines
2.4 KiB
from auto_sliceing_operate.utils import miniIo as mio |
|
import zipfile,time |
|
import os |
|
from auto_sliceing_operate.utils.oss_redis import redisClient |
|
from auto_sliceing_operate.utils.logs import log |
|
from utils.config import cfg |
|
# 打印机旁边的电脑下载切片文件到本地 |
|
# 解压压缩包,将数据移动到指定的目录 |
|
# |
|
# |
|
# |
|
|
|
# 从 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 |
|
machineId = cfg('machine.id', None) |
|
if machineId is None: |
|
log("获取当前电脑id失败") |
|
exit(0) |
|
return machineId |
|
|
|
def main(work_dir=None): |
|
|
|
downloadPath = cfg('machine.download_path', None) |
|
if downloadPath is None: |
|
log("工作目录不能为空") |
|
exit(0) |
|
if not os.path.exists(downloadPath): |
|
os.makedirs(downloadPath) |
|
|
|
|
|
r = redisClient() |
|
machineId = getCurrentMachineId() |
|
if machineId is None: |
|
log("获取当前电脑id失败") |
|
exit(0) |
|
|
|
while True: |
|
data = r.spop('pb:begin_print_machine_'+machineId) |
|
if data is None: |
|
log("队列为空") |
|
time.sleep(10) |
|
continue |
|
data = data.decode('utf-8') |
|
# 判断是否是数字 |
|
if data.isdigit(): |
|
log("取出的数据是数字") |
|
time.sleep(10) |
|
continue |
|
# batchId = str(data) |
|
ossZipPath = f'slice/complate/{data}/data.snslc' |
|
localPath = os.path.join(downloadPath,data, f'data.snslc') |
|
# 判断目录是否存在,不存在就创建 |
|
if not os.path.exists(os.path.join(downloadPath)): |
|
os.makedirs(os.path.join(downloadPath)) |
|
else: |
|
# 删除目录下指定文件,如果存在 |
|
if os.path.exists(os.path.join(downloadPath,data, f'data.snslc')): |
|
os.remove(os.path.join(downloadPath,data, f'data.snslc')) |
|
# 下载 zip 文件 |
|
downloadZip(ossZipPath, localPath) |
|
# # 解压 zip 文件 |
|
# localUnzipPath = os.path.join(work_dir,batchId) |
|
# unzip(localZipPath, localUnzipPath) |
|
# # 触发打印处理
|
|
|