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.
70 lines
2.1 KiB
70 lines
2.1 KiB
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) |
|
# 触发打印处理
|
|
|