x
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
"""
|
"""
|
||||||
import asyncio
|
import asyncio
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@@ -80,8 +81,8 @@ class GeometryVerificationService:
|
|||||||
try:
|
try:
|
||||||
result = subprocess.run(['which', cmd_name], capture_output=True, text=True)
|
result = subprocess.run(['which', cmd_name], capture_output=True, text=True)
|
||||||
if result.returncode == 0 and result.stdout.strip():
|
if result.returncode == 0 and result.stdout.strip():
|
||||||
# 使用绝对路径,添加 -c 参数使用命令行模式(无图形界面)
|
# FreeCAD 1.0 直接执行脚本,不需要 -c 参数
|
||||||
cmd = [cmd_name, '-c', str(self.verification_script), str(Path(stp_path_str).absolute())]
|
cmd = [cmd_name, str(self.verification_script), str(Path(stp_path_str).absolute())]
|
||||||
logger.info(f"找到 FreeCAD 命令: {cmd_name}")
|
logger.info(f"找到 FreeCAD 命令: {cmd_name}")
|
||||||
break
|
break
|
||||||
except:
|
except:
|
||||||
@@ -91,8 +92,8 @@ class GeometryVerificationService:
|
|||||||
if not cmd:
|
if not cmd:
|
||||||
for cmd_path in ['/usr/local/bin/freecad', '/usr/bin/freecad', '/usr/local/bin/freecadcmd', '/usr/bin/freecadcmd', '/snap/bin/freecad.cmd']:
|
for cmd_path in ['/usr/local/bin/freecad', '/usr/bin/freecad', '/usr/local/bin/freecadcmd', '/usr/bin/freecadcmd', '/snap/bin/freecad.cmd']:
|
||||||
if Path(cmd_path).exists():
|
if Path(cmd_path).exists():
|
||||||
# 添加 -c 参数使用命令行模式(无图形界面)
|
# FreeCAD 1.0 直接执行脚本,不需要 -c 参数
|
||||||
cmd = [cmd_path, '-c', str(self.verification_script), str(Path(stp_path_str).absolute())]
|
cmd = [cmd_path, str(self.verification_script), str(Path(stp_path_str).absolute())]
|
||||||
logger.info(f"找到 FreeCAD 命令路径: {cmd_path}")
|
logger.info(f"找到 FreeCAD 命令路径: {cmd_path}")
|
||||||
break
|
break
|
||||||
|
|
||||||
@@ -132,12 +133,18 @@ class GeometryVerificationService:
|
|||||||
stp_abs_path = Path(stp_path_str).absolute()
|
stp_abs_path = Path(stp_path_str).absolute()
|
||||||
stp_dir = stp_abs_path.parent
|
stp_dir = stp_abs_path.parent
|
||||||
|
|
||||||
|
# 设置环境变量禁用图形界面
|
||||||
|
env = os.environ.copy()
|
||||||
|
env['QT_QPA_PLATFORM'] = 'offscreen'
|
||||||
|
env['DISPLAY'] = ''
|
||||||
|
|
||||||
# 异步运行子进程
|
# 异步运行子进程
|
||||||
process = await asyncio.create_subprocess_exec(
|
process = await asyncio.create_subprocess_exec(
|
||||||
*cmd,
|
*cmd,
|
||||||
stdout=asyncio.subprocess.PIPE,
|
stdout=asyncio.subprocess.PIPE,
|
||||||
stderr=asyncio.subprocess.PIPE,
|
stderr=asyncio.subprocess.PIPE,
|
||||||
cwd=str(stp_dir) # 在 STP 文件所在目录运行
|
cwd=str(stp_dir), # 在 STP 文件所在目录运行
|
||||||
|
env=env
|
||||||
)
|
)
|
||||||
|
|
||||||
# 增加超时时间到 300 秒(5分钟)
|
# 增加超时时间到 300 秒(5分钟)
|
||||||
|
|||||||
Reference in New Issue
Block a user