暂存-安装脚本
This commit is contained in:
@@ -2,8 +2,12 @@ import os
|
||||
import subprocess
|
||||
import configparser
|
||||
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):
|
||||
self.name = "prusa_slicer"
|
||||
@@ -13,9 +17,18 @@ class PrusaSlicerEngine:
|
||||
|
||||
def _check_available(self):
|
||||
try:
|
||||
result = subprocess.run(["prusa-slicer", "--help"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
# 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
|
||||
if not prusa_bin:
|
||||
return False
|
||||
result = subprocess.run([prusa_bin, "--help"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
return b"Usage:" in result.stdout or b"Slic3r" in result.stdout or b"PrusaSlicer" in result.stdout or result.returncode == 0
|
||||
except (FileNotFoundError, OSError):
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
def add_ini_keys(self, config_path, target_section, all_configs):
|
||||
@@ -31,12 +44,33 @@ 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'
|
||||
|
||||
# Base command
|
||||
command = [
|
||||
"/home/lhye200/AIO_3D_Print_Exp/prusaslicer/prusa-slicer",
|
||||
"-g", stl_filepath,
|
||||
"--output", gcode_filepath
|
||||
]
|
||||
command = [prusa_bin, '-g', stl_filepath, '--output', gcode_filepath]
|
||||
|
||||
# Map quality, infill, supports to PrusaSlicer CLI arguments.
|
||||
# Example defaults, normally these would load from an .ini or be dynamically matched.
|
||||
|
||||
Reference in New Issue
Block a user