|
|
@@ -53,20 +53,25 @@ async def handlerCutOut(
|
|
|
)
|
|
|
await manager.send_personal_message(data, websocket)
|
|
|
|
|
|
-def handlerFolderDelete(limit_path,goods_art_no_arrays,is_write_txt_log):
|
|
|
+def handlerFolderDelete(limit_path, goods_art_no_arrays, is_write_txt_log):
|
|
|
check_path(limit_path)
|
|
|
move_folder_array = check_move_goods_art_no_folder(
|
|
|
- "output", goods_art_no_arrays, limit_path
|
|
|
- )
|
|
|
+ "output", goods_art_no_arrays, limit_path
|
|
|
+ )
|
|
|
+
|
|
|
for goods_art_revice in goods_art_no_arrays:
|
|
|
- cutout_goods = f"{limit_path}/{goods_art_revice}"
|
|
|
- if os.path.exists(cutout_goods):
|
|
|
- # 寻找当前被扣图的货号在现有目录中是否存在,如果存在先删除
|
|
|
- # 重新执行抠图操作
|
|
|
- try:
|
|
|
- shutil.rmtree(cutout_goods, onerror=settings.handle_remove_readonly)
|
|
|
- del move_folder_array[goods_art_revice]
|
|
|
- except PermissionError as e:
|
|
|
+ cutout_goods = f"{limit_path}/{goods_art_revice}"
|
|
|
+ if os.path.exists(cutout_goods):
|
|
|
+ # 尝试多次删除,增加成功率
|
|
|
+ retry_count = 3
|
|
|
+ while retry_count > 0:
|
|
|
+ try:
|
|
|
+ shutil.rmtree(cutout_goods, onerror=settings.handle_remove_readonly)
|
|
|
+ del move_folder_array[goods_art_revice]
|
|
|
+ break
|
|
|
+ except PermissionError as e:
|
|
|
+ retry_count -= 1
|
|
|
+ if retry_count == 0:
|
|
|
logger.info(f"抠图前目录删除出现问题:{str(e)};{goods_art_revice};{cutout_goods}")
|
|
|
if is_write_txt_log:
|
|
|
error_file_path = f"{cutout_goods}/异常说明-出现目录丢失或缺少图片请点开查看原因.txt"
|
|
|
@@ -78,18 +83,21 @@ def handlerFolderDelete(limit_path,goods_art_no_arrays,is_write_txt_log):
|
|
|
f.write(f"请关闭可能正在使用此目录的程序后,为当前货号点击重拍后重试\n")
|
|
|
else:
|
|
|
raise UnicornException(f"目录检查出现问题:{str(e)},请关闭错误提示中的被占用文件")
|
|
|
- except Exception as e:
|
|
|
- logger.info(f"抠图前目录删除出现问题:{str(e)};{goods_art_revice};{cutout_goods}")
|
|
|
- if is_write_txt_log:
|
|
|
- error_file_path = f"{cutout_goods}/异常说明-出现目录丢失或缺少图片请点开查看原因.txt"
|
|
|
- with open(error_file_path, 'w', encoding='utf-8') as f:
|
|
|
- f.write("目录删除失败\n")
|
|
|
- f.write(f"原因: {str(e)}\n")
|
|
|
- f.write(f"时间: {time.strftime('%Y-%m-%d %H:%M:%S')}\n")
|
|
|
- f.write(f"请检查目录状态后,为当前货号点击重拍后重试\n")
|
|
|
- else:
|
|
|
- raise UnicornException(f"目录检查出现问题:{str(e)},请关闭错误提示中的被占用文件")
|
|
|
- return move_folder_array
|
|
|
+ else:
|
|
|
+ time.sleep(0.5) # 等待0.5秒后重试
|
|
|
+ except Exception as e:
|
|
|
+ logger.info(f"抠图前目录删除出现问题:{str(e)};{goods_art_revice};{cutout_goods}")
|
|
|
+ if is_write_txt_log:
|
|
|
+ error_file_path = f"{cutout_goods}/异常说明-出现目录丢失或缺少图片请点开查看原因.txt"
|
|
|
+ with open(error_file_path, 'w', encoding='utf-8') as f:
|
|
|
+ f.write("目录删除失败\n")
|
|
|
+ f.write(f"原因: {str(e)}\n")
|
|
|
+ f.write(f"时间: {time.strftime('%Y-%m-%d %H:%M:%S')}\n")
|
|
|
+ f.write(f"请检查目录状态后,为当前货号点击重拍后重试\n")
|
|
|
+ else:
|
|
|
+ raise UnicornException(f"目录检查出现问题:{str(e)},请关闭错误提示中的被占用文件")
|
|
|
+
|
|
|
+ return move_folder_array
|
|
|
# socket消息发送逻辑处理方法
|
|
|
async def handlerSend(
|
|
|
manager: ConnectionManager,
|