Platform independent searching for binaries in engine directory

This commit is contained in:
2023-10-21 16:58:14 -07:00
parent a220858dec
commit aa484f21a4
3 changed files with 28 additions and 9 deletions

View File

@@ -13,6 +13,7 @@ class Blender(BaseRenderEngine):
install_paths = ['/Applications/Blender.app/Contents/MacOS/Blender'] install_paths = ['/Applications/Blender.app/Contents/MacOS/Blender']
supported_extensions = ['.blend'] supported_extensions = ['.blend']
binary_names = {'linux': 'blender', 'windows': 'blender.exe', 'macos': 'Blender.app'}
def version(self): def version(self):
version = None version = None

View File

@@ -4,6 +4,7 @@ import platform
import shutil import shutil
from .downloaders.blender_downloader import BlenderDownloader from .downloaders.blender_downloader import BlenderDownloader
from .downloaders.ffmpeg_downloader import FFMPEGDownloader from .downloaders.ffmpeg_downloader import FFMPEGDownloader
from ..utilities.misc_helper import system_safe_path
try: try:
from .blender_engine import Blender from .blender_engine import Blender
@@ -37,14 +38,25 @@ class EngineManager:
# Split the input string by dashes to get segments # Split the input string by dashes to get segments
segments = directory.split('-') segments = directory.split('-')
# Define the keys for each word
keys = ["engine", "version", "system_os", "cpu"]
# Create a dictionary with named keys # Create a dictionary with named keys
executable_names = {'linux': 'blender', 'windows': 'blender.exe', 'macos': 'Blender.app'} keys = ["engine", "version", "system_os", "cpu"]
result_dict = {keys[i]: segments[i] for i in range(min(len(keys), len(segments)))} result_dict = {keys[i]: segments[i] for i in range(min(len(keys), len(segments)))}
result_dict['path'] = os.path.join(cls.engines_path, directory, executable_names.get(result_dict['system_os'], 'unknown'))
result_dict['type'] = 'managed' result_dict['type'] = 'managed'
# Figure out the binary name for the path
binary_name = result_dict['engine'].lower()
for eng in cls.supported_engines():
if eng.name().lower() == result_dict['engine']:
binary_name = eng.binary_names.get(result_dict['system_os'], binary_name)
# Find path to binary
path = None
for root, _, files in os.walk(system_safe_path(os.path.join(cls.engines_path, directory))):
if binary_name in files:
path = os.path.join(root, binary_name)
break
result_dict['path'] = path
results.append(result_dict) results.append(result_dict)
except FileNotFoundError: except FileNotFoundError:
logger.warning("Cannot find local engines download directory") logger.warning("Cannot find local engines download directory")
@@ -113,11 +125,15 @@ class EngineManager:
return return
# Get the appropriate downloader class based on the engine type # Get the appropriate downloader class based on the engine type
downloader = downloader_classes[engine] downloader_classes[engine].download_engine(version, download_location=cls.engines_path,
if downloader.download_engine(version, download_location=cls.engines_path, system_os=system_os, cpu=cpu): system_os=system_os, cpu=cpu)
return cls.has_engine_version(engine, version, system_os, cpu)
else: # Check that engine was properly downloaded
found_engine = cls.has_engine_version(engine, version, system_os, cpu)
if not found_engine:
logger.error(f"Error downloading {engine}") logger.error(f"Error downloading {engine}")
return found_engine
@classmethod @classmethod
def delete_engine_download(cls, engine, version, system_os=None, cpu=None): def delete_engine_download(cls, engine, version, system_os=None, cpu=None):

View File

@@ -7,6 +7,8 @@ import re
class FFMPEG(BaseRenderEngine): class FFMPEG(BaseRenderEngine):
binary_names = {'linux': 'ffmpeg', 'windows': 'ffmpeg.exe', 'macos': 'ffmpeg'}
def version(self): def version(self):
version = None version = None
try: try: