Pylint cleanup (#74)

* Misc fixes

* Misc cleanup

* Add all_versions to blender_downloader.py

* More cleanup

* Fix issue with status not reporting engine info

* Misc fixes

* Misc cleanup

* Add all_versions to blender_downloader.py

* More cleanup

* Fix issue with status not reporting engine info
This commit is contained in:
2024-01-28 10:30:57 -06:00
committed by GitHub
parent d673d7d4bf
commit 9757ba9276
14 changed files with 79 additions and 57 deletions
+27 -2
View File
@@ -1,5 +1,6 @@
import logging
import re
import threading
import requests
@@ -15,6 +16,7 @@ supported_formats = ['.zip', '.tar.xz', '.dmg']
class BlenderDownloader(EngineDownloader):
engine = Blender
@staticmethod
@@ -79,6 +81,31 @@ class BlenderDownloader(EngineDownloader):
return lts_versions
@classmethod
def all_versions(cls, system_os=None, cpu=None):
majors = cls.__get_major_versions()
all_versions = []
threads = []
results = [[] for _ in majors]
def thread_function(major_version, index, system_os, cpu):
results[index] = cls.__get_minor_versions(major_version, system_os, cpu)
for i, m in enumerate(majors):
thread = threading.Thread(target=thread_function, args=(m, i, system_os, cpu))
threads.append(thread)
thread.start()
# Wait for all threads to complete
for thread in threads:
thread.join()
# Extend all_versions with the results from each thread
for result in results:
all_versions.extend(result)
return all_versions
@classmethod
def find_most_recent_version(cls, system_os=None, cpu=None, lts_only=False):
try:
@@ -108,8 +135,6 @@ class BlenderDownloader(EngineDownloader):
major_version = '.'.join(version.split('.')[:2])
minor_versions = [x for x in cls.__get_minor_versions(major_version, system_os, cpu) if
x['version'] == version]
# we get the URL instead of calculating it ourselves. May change this
cls.download_and_extract_app(remote_url=minor_versions[0]['url'], download_location=download_location,
timeout=timeout)
except IndexError:
+1 -2
View File
@@ -12,8 +12,7 @@ class BlenderRenderWorker(BaseRenderWorker):
engine = Blender
def __init__(self, input_path, output_path, engine_path, args=None, parent=None, name=None):
super(BlenderRenderWorker, self).__init__(input_path=input_path, output_path=output_path,
engine_path=engine_path, args=args, parent=parent, name=name)
super(BlenderRenderWorker, self).__init__(input_path=input_path, output_path=output_path, engine_path=engine_path, args=args, parent=parent, name=name)
# Args
self.blender_engine = self.args.get('engine', 'BLENDER_EEVEE').upper()
+2 -2
View File
@@ -157,14 +157,14 @@ class BaseRenderWorker(Base):
if not os.path.exists(self.input_path):
self.status = RenderStatus.ERROR
msg = 'Cannot find input path: {}'.format(self.input_path)
msg = f'Cannot find input path: {self.input_path}'
logger.error(msg)
self.errors.append(msg)
return
if not os.path.exists(self.renderer_path):
self.status = RenderStatus.ERROR
msg = 'Cannot find render engine path for {}'.format(self.engine.name())
msg = f'Cannot find render engine path for {self.engine.name()}'
logger.error(msg)
self.errors.append(msg)
return
+1 -1
View File
@@ -239,7 +239,7 @@ class EngineManager:
@classmethod
def engine_for_project_path(cls, path):
name, extension = os.path.splitext(path)
_, extension = os.path.splitext(path)
extension = extension.lower().strip('.')
for engine in cls.supported_engines():
if extension in engine.supported_extensions():
+4 -4
View File
@@ -90,7 +90,7 @@ class FFMPEGDownloader(EngineDownloader):
return releases
@classmethod
def __all_versions(cls, system_os=None, cpu=None):
def all_versions(cls, system_os=None, cpu=None):
system_os = system_os or current_system_os()
cpu = cpu or current_system_cpu()
versions_per_os = {'linux': cls.__get_linux_versions, 'macos': cls.__get_macos_versions,
@@ -131,14 +131,14 @@ class FFMPEGDownloader(EngineDownloader):
try:
system_os = system_os or current_system_os()
cpu = cpu or current_system_cpu()
return cls.__all_versions(system_os, cpu)[0]
return cls.all_versions(system_os, cpu)[0]
except (IndexError, requests.exceptions.RequestException):
logger.error(f"Cannot get most recent version of ffmpeg")
return {}
@classmethod
def version_is_available_to_download(cls, version, system_os=None, cpu=None):
for ver in cls.__all_versions(system_os, cpu):
for ver in cls.all_versions(system_os, cpu):
if ver['version'] == version:
return ver
return None
@@ -149,7 +149,7 @@ class FFMPEGDownloader(EngineDownloader):
cpu = cpu or current_system_cpu()
# Verify requested version is available
found_version = [item for item in cls.__all_versions(system_os, cpu) if item['version'] == version]
found_version = [item for item in cls.all_versions(system_os, cpu) if item['version'] == version]
if not found_version:
logger.error(f"Cannot find FFMPEG version {version} for {system_os} and {cpu}")
return
+7 -6
View File
@@ -25,7 +25,7 @@ class FFMPEG(BaseRenderEngine):
def supported_extensions(cls):
help_text = (subprocess.check_output([cls().renderer_path(), '-h', 'full'], stderr=subprocess.STDOUT)
.decode('utf-8'))
found = re.findall('extensions that .* is allowed to access \(default "(.*)"', help_text)
found = re.findall(r'extensions that .* is allowed to access \(default "(.*)"', help_text)
found_extensions = set()
for match in found:
found_extensions.update(match.split(','))
@@ -36,7 +36,7 @@ class FFMPEG(BaseRenderEngine):
try:
ver_out = subprocess.check_output([self.renderer_path(), '-version'],
timeout=SUBPROCESS_TIMEOUT).decode('utf-8')
match = re.match(".*version\s*([\w.*]+)\W*", ver_out)
match = re.match(r".*version\s*([\w.*]+)\W*", ver_out)
if match:
version = match.groups()[0]
except Exception as e:
@@ -50,8 +50,8 @@ class FFMPEG(BaseRenderEngine):
'ffprobe', '-v', 'quiet', '-print_format', 'json',
'-show_streams', '-select_streams', 'v', project_path
]
result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
video_info = json.loads(result.stdout)
output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, text=True)
video_info = json.loads(output)
# Extract the necessary information
video_stream = video_info['streams'][0]
@@ -94,7 +94,7 @@ class FFMPEG(BaseRenderEngine):
try:
formats_raw = subprocess.check_output([self.renderer_path(), '-formats'], stderr=subprocess.DEVNULL,
timeout=SUBPROCESS_TIMEOUT).decode('utf-8')
pattern = '(?P<type>[DE]{1,2})\s+(?P<id>\S{2,})\s+(?P<name>.*)'
pattern = r'(?P<type>[DE]{1,2})\s+(?P<id>\S{2,})\s+(?P<name>.*)'
all_formats = [m.groupdict() for m in re.finditer(pattern, formats_raw)]
return all_formats
except Exception as e:
@@ -124,6 +124,7 @@ class FFMPEG(BaseRenderEngine):
if match:
frame_number = int(match[-1])
return frame_number
return -1
def get_arguments(self):
help_text = (subprocess.check_output([self.renderer_path(), '-h', 'long'], stderr=subprocess.STDOUT)
@@ -154,4 +155,4 @@ class FFMPEG(BaseRenderEngine):
if __name__ == "__main__":
print(FFMPEG().supported_extensions())
print(FFMPEG().get_all_formats())