暂存-说明文档(部分)
This commit is contained in:
@@ -8,7 +8,7 @@ def get_all_engines():
|
||||
PrusaSlicerEngine()
|
||||
]
|
||||
|
||||
def get_slicer_engine(engine_name="prusa", print_config_folder=None):
|
||||
def get_slicer_engine(engine_name="prusa", print_config_folder=None, config_slice_bin_path=None):
|
||||
"""
|
||||
Factory function to retrieve the requested slicing engine instance.
|
||||
Valid names: 'cura', 'prusa_slicer'
|
||||
@@ -18,7 +18,7 @@ def get_slicer_engine(engine_name="prusa", print_config_folder=None):
|
||||
if engine_name in ['cura', 'cura_engine', 'curaengine']:
|
||||
return CuraEngine(print_config_folder)
|
||||
elif engine_name in ['prusa', 'prusa_slicer', 'prusaslicer']:
|
||||
return PrusaSlicerEngine(print_config_folder)
|
||||
return PrusaSlicerEngine(print_config_folder, config_slice_bin_path)
|
||||
else:
|
||||
# Default fallback
|
||||
return PrusaSlicerEngine(print_config_folder)
|
||||
return PrusaSlicerEngine(print_config_folder, config_slice_bin_path)
|
||||
|
||||
@@ -20,8 +20,6 @@ class CuraEngine:
|
||||
return result.returncode == 0 or b"Usage:" in result.stdout or b"Usage:" in result.stderr
|
||||
except (FileNotFoundError, OSError):
|
||||
return False
|
||||
self.display_name = "UltiMaker Cura"
|
||||
self.is_available = self._check_available()
|
||||
|
||||
|
||||
def slice(self, app, stl_filepath, gcode_filepath, **kwargs):
|
||||
|
||||
@@ -5,25 +5,19 @@ import uuid
|
||||
import shutil
|
||||
from app.models import SystemConfig
|
||||
|
||||
# Default PrusaSlicer AppImage (aarch64) download URL
|
||||
PRUSA_DOWNLOAD_URL = "https://github.com/davidk/PrusaSlicer-ARM.AppImage/releases/download/version_2.9.4/PrusaSlicer-2.9.4-aarch64-full.AppImage"
|
||||
|
||||
class PrusaSlicerEngine:
|
||||
def __init__(self, print_config_folder=None):
|
||||
def __init__(self, print_config_folder=None, config_slice_bin_path=None):
|
||||
self.name = "prusa_slicer"
|
||||
self.display_name = "PrusaSlicer"
|
||||
self.config_slice_bin_path = config_slice_bin_path
|
||||
self.is_available = self._check_available()
|
||||
self.print_config_folder = os.path.join(print_config_folder, 'prusa_slicer') if print_config_folder else None
|
||||
|
||||
def _check_available(self):
|
||||
try:
|
||||
# Prefer explicit environment variable, then PATH, then a bundled AppImage under the repo
|
||||
prusa_bin = os.environ.get('PRUSA_SLICER_BIN') or shutil.which('prusa-slicer') or shutil.which('prusa-slicer.exe')
|
||||
if not prusa_bin:
|
||||
repo_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..'))
|
||||
local_appimage = os.path.join(repo_root, 'prusaslicer', os.path.basename(PRUSA_DOWNLOAD_URL))
|
||||
if os.path.isfile(local_appimage) and os.access(local_appimage, os.X_OK):
|
||||
prusa_bin = local_appimage
|
||||
prusa_bin = self.config_slice_bin_path or shutil.which('prusa-slicer') or shutil.which('prusa-slicer.exe')
|
||||
if not prusa_bin:
|
||||
return False
|
||||
result = subprocess.run([prusa_bin, "--help"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
@@ -44,30 +38,7 @@ class PrusaSlicerEngine:
|
||||
Slices via prusa-slicer CLI mapping standard kwargs to PRUSA parameters where possible.
|
||||
"""
|
||||
try:
|
||||
# Determine prusa-slicer binary location (env -> PATH -> bundled appimage in repo)
|
||||
repo_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..'))
|
||||
prusa_env = os.environ.get('PRUSA_SLICER_BIN')
|
||||
candidates = []
|
||||
if prusa_env:
|
||||
candidates.append(prusa_env)
|
||||
which_bin = shutil.which('prusa-slicer') or shutil.which('prusa-slicer.exe')
|
||||
if which_bin:
|
||||
candidates.append(which_bin)
|
||||
candidates.extend([
|
||||
os.path.join(repo_root, 'prusaslicer', 'prusa-slicer'),
|
||||
os.path.join(repo_root, 'prusaslicer', os.path.basename(PRUSA_DOWNLOAD_URL)),
|
||||
os.path.join(repo_root, os.path.basename(PRUSA_DOWNLOAD_URL))
|
||||
])
|
||||
|
||||
prusa_bin = None
|
||||
for c in candidates:
|
||||
if c and os.path.isfile(c) and os.access(c, os.X_OK):
|
||||
prusa_bin = c
|
||||
break
|
||||
|
||||
if not prusa_bin:
|
||||
# fallback to plain name so subprocess will try PATH and give a clear error
|
||||
prusa_bin = 'prusa-slicer'
|
||||
prusa_bin = self.config_slice_bin_path or shutil.which('prusa-slicer') or shutil.which('prusa-slicer.exe')
|
||||
|
||||
# Base command
|
||||
command = [prusa_bin, '-g', stl_filepath, '--output', gcode_filepath]
|
||||
|
||||
Reference in New Issue
Block a user