mirror of
https://github.com/blw1138/Zordon.git
synced 2025-12-17 08:48:13 +00:00
Bugfix: Filter out corrupt engines by default (#94)
* Add main.spec * Fix issue where fetching supported extensions would crash with no default installation * Engines return version as 'error' if cannot determine version * EngineManager will now filter out corrupted engine installs by default
This commit is contained in:
@@ -27,7 +27,7 @@ class EngineManager:
|
||||
return obj
|
||||
|
||||
@classmethod
|
||||
def get_engines(cls, filter_name=None):
|
||||
def get_engines(cls, filter_name=None, include_corrupt=False):
|
||||
|
||||
if not cls.engines_path:
|
||||
raise FileNotFoundError("Engine path is not set")
|
||||
@@ -49,10 +49,8 @@ class EngineManager:
|
||||
# Initialize binary_name with engine name
|
||||
binary_name = result_dict['engine'].lower()
|
||||
# Determine the correct binary name based on the engine and system_os
|
||||
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)
|
||||
break
|
||||
eng = cls.engine_with_name(result_dict['engine'])
|
||||
binary_name = eng.binary_names.get(result_dict['system_os'], binary_name)
|
||||
|
||||
# Find the path to the binary file
|
||||
path = next(
|
||||
@@ -60,8 +58,16 @@ class EngineManager:
|
||||
os.walk(system_safe_path(os.path.join(cls.engines_path, directory))) if binary_name in files),
|
||||
None
|
||||
)
|
||||
|
||||
result_dict['path'] = path
|
||||
|
||||
# fetch version number from binary - helps detect corrupted downloads
|
||||
binary_version = eng(path).version()
|
||||
if not binary_version:
|
||||
logger.warning(f"Possible corrupt {eng.name()} {result_dict['version']} install detected: {path}")
|
||||
if not include_corrupt:
|
||||
continue
|
||||
result_dict['version'] = binary_version or 'error'
|
||||
|
||||
# Add the result dictionary to results if it matches the filter_name or if no filter is applied
|
||||
if not filter_name or filter_name == result_dict['engine']:
|
||||
results.append(result_dict)
|
||||
@@ -69,10 +75,14 @@ class EngineManager:
|
||||
logger.warning(f"Cannot find local engines download directory: {e}")
|
||||
|
||||
# add system installs to this list - use bg thread because it can be slow
|
||||
def fetch_engine_details(eng):
|
||||
def fetch_engine_details(eng, include_corrupt=False):
|
||||
version = eng().version()
|
||||
if not version and not include_corrupt:
|
||||
return
|
||||
|
||||
return {
|
||||
'engine': eng.name(),
|
||||
'version': eng().version(),
|
||||
'version': version or 'error',
|
||||
'system_os': current_system_os(),
|
||||
'cpu': current_system_cpu(),
|
||||
'path': eng.default_renderer_path(),
|
||||
@@ -81,7 +91,7 @@ class EngineManager:
|
||||
|
||||
with concurrent.futures.ThreadPoolExecutor() as executor:
|
||||
futures = {
|
||||
executor.submit(fetch_engine_details, eng): eng.name()
|
||||
executor.submit(fetch_engine_details, eng, include_corrupt): eng.name()
|
||||
for eng in cls.supported_engines()
|
||||
if eng.default_renderer_path() and (not filter_name or filter_name == eng.name())
|
||||
}
|
||||
@@ -94,8 +104,8 @@ class EngineManager:
|
||||
return results
|
||||
|
||||
@classmethod
|
||||
def all_versions_for_engine(cls, engine_name):
|
||||
versions = cls.get_engines(filter_name=engine_name)
|
||||
def all_versions_for_engine(cls, engine_name, include_corrupt=False):
|
||||
versions = cls.get_engines(filter_name=engine_name, include_corrupt=include_corrupt)
|
||||
sorted_versions = sorted(versions, key=lambda x: x['version'], reverse=True)
|
||||
return sorted_versions
|
||||
|
||||
|
||||
Reference in New Issue
Block a user