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