mirror of
https://github.com/blw1138/Zordon.git
synced 2026-02-05 13:46:10 +00:00
Compare commits
42 Commits
feature/84
...
6bfa5629d5
| Author | SHA1 | Date | |
|---|---|---|---|
| 6bfa5629d5 | |||
|
|
05cd0470dd | ||
|
|
7827f73530 | ||
| 562cb23da3 | |||
|
|
6b68d42b93 | ||
|
|
cdf4b2bbe1 | ||
|
|
dc8f4d3e2a | ||
| 2548280dcc | |||
|
|
98ab837057 | ||
|
|
3fda87935e | ||
|
|
e35a5a689c | ||
| dea7574888 | |||
| a19db9fcf7 | |||
| 80b0adb2ad | |||
| 18873cec6f | |||
| af6d6e1525 | |||
| 8bbf19cb30 | |||
| 6bdb488ce1 | |||
| e792698480 | |||
|
|
751d74ced3 | ||
| e8a4692e0f | |||
| 49ae5a55d9 | |||
|
|
d04d14446b | ||
| 81e79a1996 | |||
|
|
d30978bef0 | ||
| e2333c4451 | |||
| 94a40c46dc | |||
|
|
8104bd4e86 | ||
|
|
33adcac592 | ||
|
|
d38e10ae9f | ||
|
|
19b01446ea | ||
| e757506787 | |||
| f9b51886ab | |||
| 3b33649f2d | |||
| 51a5a63944 | |||
| 3600eeb21b | |||
| 6afb6e65a6 | |||
|
|
90d5e9b7af | ||
| 4df41a2079 | |||
| 1cdb7810bf | |||
|
|
21011e47ca | ||
|
|
86977b9d6d |
38
.github/workflows/create-executables.yml
vendored
Normal file
38
.github/workflows/create-executables.yml
vendored
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
name: Create Executables
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
release:
|
||||||
|
- types: [created]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
pyinstaller-build-windows:
|
||||||
|
runs-on: windows-latest
|
||||||
|
steps:
|
||||||
|
- name: Create Executables (Windows)
|
||||||
|
uses: sayyid5416/pyinstaller@v1
|
||||||
|
with:
|
||||||
|
python_ver: '3.11'
|
||||||
|
spec: 'main.spec'
|
||||||
|
requirements: 'requirements.txt'
|
||||||
|
upload_exe_with_name: 'Zordon'
|
||||||
|
pyinstaller-build-linux:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Create Executables (Linux)
|
||||||
|
uses: sayyid5416/pyinstaller@v1
|
||||||
|
with:
|
||||||
|
python_ver: '3.11'
|
||||||
|
spec: 'main.spec'
|
||||||
|
requirements: 'requirements.txt'
|
||||||
|
upload_exe_with_name: 'Zordon'
|
||||||
|
pyinstaller-build-macos:
|
||||||
|
runs-on: macos-latest
|
||||||
|
steps:
|
||||||
|
- name: Create Executables (macOS)
|
||||||
|
uses: sayyid5416/pyinstaller@v1
|
||||||
|
with:
|
||||||
|
python_ver: '3.11'
|
||||||
|
spec: 'main.spec'
|
||||||
|
requirements: 'requirements.txt'
|
||||||
|
upload_exe_with_name: 'Zordon'
|
||||||
23
.github/workflows/pylint.yml
vendored
23
.github/workflows/pylint.yml
vendored
@@ -1,23 +0,0 @@
|
|||||||
name: Pylint
|
|
||||||
|
|
||||||
on: [push]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
python-version: ["3.10", "3.11", "3.12"]
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
- name: Set up Python ${{ matrix.python-version }}
|
|
||||||
uses: actions/setup-python@v3
|
|
||||||
with:
|
|
||||||
python-version: ${{ matrix.python-version }}
|
|
||||||
- name: Install dependencies
|
|
||||||
run: |
|
|
||||||
python -m pip install --upgrade pip
|
|
||||||
pip install pylint
|
|
||||||
- name: Analysing the code with pylint
|
|
||||||
run: |
|
|
||||||
pylint $(git ls-files '*.py')
|
|
||||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -6,3 +6,6 @@
|
|||||||
/dist/
|
/dist/
|
||||||
/build/
|
/build/
|
||||||
/.github/
|
/.github/
|
||||||
|
*.idea
|
||||||
|
.DS_Store
|
||||||
|
venv/
|
||||||
|
|||||||
44
README.md
44
README.md
@@ -1,14 +1,46 @@
|
|||||||
# 🎬 Zordon - Render Management Tools
|

|
||||||
|
|
||||||
Welcome to Zordon! It's a local network render farm manager, aiming to streamline and simplify the rendering process across multiple home computers.
|
---
|
||||||
|
|
||||||
## 📦 Installation
|
# Zordon
|
||||||
|
|
||||||
Install the necessary dependencies: `pip3 install -r requirements.txt`
|
A lightweight, zero-install, distributed rendering and management tool designed to streamline and optimize rendering workflows across multiple machines
|
||||||
|
|
||||||
## 🎨 Supported Renderers
|
## What is Zordon?
|
||||||
|
|
||||||
Zordon currently supports the following renderers:
|
Zordon is tool designed for small render farms, such as those used in home studios or small businesses, to efficiently manage and run render jobs for Blender, FFMPEG, and other video renderers. It simplifies the process of distributing rendering tasks across multiple available machines, optimizing the rendering workflow for artists, animators, and video professionals.
|
||||||
|
|
||||||
|
|
||||||
|
Notice: This should be considered a beta and is meant for casual / hobbiest use. Do not use in mission critical environments!
|
||||||
|
|
||||||
|
## Supported Renderers
|
||||||
|
|
||||||
|
Zordon supports or plans to support the following renderers:
|
||||||
|
|
||||||
- **Blender**
|
- **Blender**
|
||||||
- **FFMPEG**
|
- **FFMPEG**
|
||||||
|
- **Adobe After Effects** ([coming soon](https://github.com/blw1138/Zordon/issues/84))
|
||||||
|
- **Cinema 4D** ([planned](https://github.com/blw1138/Zordon/issues/105))
|
||||||
|
- **Autodesk Maya** ([planned](https://github.com/blw1138/Zordon/issues/106))
|
||||||
|
|
||||||
|
## System Requirements
|
||||||
|
|
||||||
|
- Windows 10 or later
|
||||||
|
- macOS Ventura (13.0) or later
|
||||||
|
- Linux (Supported versions TBD)
|
||||||
|
|
||||||
|
## Build using Pyinstaller
|
||||||
|
|
||||||
|
Zordon is regularly tested with Python 3.11 and later. It's packaged and distributed with pyinstaller. It is supported on Windows, macOS and Linux.
|
||||||
|
|
||||||
|
```
|
||||||
|
git clone https://github.com/blw1138/Zordon.git
|
||||||
|
pip3 install -r requirements.txt
|
||||||
|
pip3 install pyinstaller
|
||||||
|
pip3 install pyinstaller_versionfile
|
||||||
|
pyinstaller main.spec
|
||||||
|
```
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
Zordon is licensed under the MIT License. See the [LICENSE](LICENSE.txt) file for more details.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ update_engines_on_launch: true
|
|||||||
max_content_path: 100000000
|
max_content_path: 100000000
|
||||||
server_log_level: info
|
server_log_level: info
|
||||||
log_buffer_length: 250
|
log_buffer_length: 250
|
||||||
subjob_connection_timeout: 120
|
worker_process_timeout: 120
|
||||||
flask_log_level: error
|
flask_log_level: error
|
||||||
flask_debug_enable: false
|
flask_debug_enable: false
|
||||||
queue_eval_seconds: 1
|
queue_eval_seconds: 1
|
||||||
|
|||||||
BIN
docs/screenshot.png
Normal file
BIN
docs/screenshot.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 838 KiB |
121
main.spec
Normal file
121
main.spec
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
# -*- mode: python ; coding: utf-8 -*-
|
||||||
|
from PyInstaller.utils.hooks import collect_all
|
||||||
|
|
||||||
|
# - get version from version file
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import platform
|
||||||
|
src_path = os.path.abspath("src")
|
||||||
|
sys.path.insert(0, src_path)
|
||||||
|
from version import APP_NAME, APP_VERSION, APP_AUTHOR
|
||||||
|
sys.path.insert(0, os.path.abspath('.'))
|
||||||
|
|
||||||
|
datas = [('resources', 'resources'), ('src/engines/blender/scripts/', 'src/engines/blender/scripts')]
|
||||||
|
binaries = []
|
||||||
|
hiddenimports = ['zeroconf']
|
||||||
|
tmp_ret = collect_all('zeroconf')
|
||||||
|
datas += tmp_ret[0]; binaries += tmp_ret[1]; hiddenimports += tmp_ret[2]
|
||||||
|
|
||||||
|
|
||||||
|
a = Analysis(
|
||||||
|
['main.py'],
|
||||||
|
pathex=[],
|
||||||
|
binaries=binaries,
|
||||||
|
datas=datas,
|
||||||
|
hiddenimports=hiddenimports,
|
||||||
|
hookspath=[],
|
||||||
|
hooksconfig={},
|
||||||
|
runtime_hooks=[],
|
||||||
|
excludes=[],
|
||||||
|
noarchive=False,
|
||||||
|
optimize=1, # fyi: optim level 2 breaks on windows
|
||||||
|
)
|
||||||
|
pyz = PYZ(a.pure)
|
||||||
|
|
||||||
|
if platform.system() == 'Darwin': # macOS
|
||||||
|
|
||||||
|
exe = EXE(
|
||||||
|
pyz,
|
||||||
|
a.scripts,
|
||||||
|
[],
|
||||||
|
exclude_binaries=True,
|
||||||
|
name=APP_NAME,
|
||||||
|
debug=False,
|
||||||
|
bootloader_ignore_signals=False,
|
||||||
|
strip=True,
|
||||||
|
upx=True,
|
||||||
|
console=False,
|
||||||
|
disable_windowed_traceback=False,
|
||||||
|
argv_emulation=False,
|
||||||
|
target_arch=None,
|
||||||
|
codesign_identity=None,
|
||||||
|
entitlements_file=None,
|
||||||
|
)
|
||||||
|
app = BUNDLE(
|
||||||
|
exe,
|
||||||
|
a.binaries,
|
||||||
|
a.datas,
|
||||||
|
strip=True,
|
||||||
|
name=f'{APP_NAME}.app',
|
||||||
|
icon='resources/Server.png',
|
||||||
|
bundle_identifier=None,
|
||||||
|
version=APP_VERSION
|
||||||
|
)
|
||||||
|
|
||||||
|
elif platform.system() == 'Windows':
|
||||||
|
|
||||||
|
import pyinstaller_versionfile
|
||||||
|
import tempfile
|
||||||
|
|
||||||
|
version_file_path = os.path.join(tempfile.gettempdir(), 'versionfile.txt')
|
||||||
|
|
||||||
|
pyinstaller_versionfile.create_versionfile(
|
||||||
|
output_file=version_file_path,
|
||||||
|
version=APP_VERSION,
|
||||||
|
company_name=APP_AUTHOR,
|
||||||
|
file_description=APP_NAME,
|
||||||
|
internal_name=APP_NAME,
|
||||||
|
legal_copyright=f"© {APP_AUTHOR}",
|
||||||
|
original_filename=f"{APP_NAME}.exe",
|
||||||
|
product_name=APP_NAME
|
||||||
|
)
|
||||||
|
|
||||||
|
exe = EXE(
|
||||||
|
pyz,
|
||||||
|
a.scripts,
|
||||||
|
a.binaries,
|
||||||
|
a.datas,
|
||||||
|
[],
|
||||||
|
name=APP_NAME,
|
||||||
|
debug=False,
|
||||||
|
bootloader_ignore_signals=False,
|
||||||
|
strip=True,
|
||||||
|
upx=True,
|
||||||
|
console=False,
|
||||||
|
disable_windowed_traceback=False,
|
||||||
|
argv_emulation=False,
|
||||||
|
target_arch=None,
|
||||||
|
codesign_identity=None,
|
||||||
|
entitlements_file=None,
|
||||||
|
version=version_file_path
|
||||||
|
)
|
||||||
|
|
||||||
|
else: # linux
|
||||||
|
exe = EXE(
|
||||||
|
pyz,
|
||||||
|
a.scripts,
|
||||||
|
a.binaries,
|
||||||
|
a.datas,
|
||||||
|
[],
|
||||||
|
name=APP_NAME,
|
||||||
|
debug=False,
|
||||||
|
bootloader_ignore_signals=False,
|
||||||
|
strip=True,
|
||||||
|
upx=True,
|
||||||
|
console=False,
|
||||||
|
disable_windowed_traceback=False,
|
||||||
|
argv_emulation=False,
|
||||||
|
target_arch=None,
|
||||||
|
codesign_identity=None,
|
||||||
|
entitlements_file=None
|
||||||
|
)
|
||||||
@@ -34,4 +34,8 @@ kiwisolver>=1.4.5
|
|||||||
attrs>=23.2.0
|
attrs>=23.2.0
|
||||||
lxml>=5.1.0
|
lxml>=5.1.0
|
||||||
click>=8.1.7
|
click>=8.1.7
|
||||||
requests_toolbelt>=1.0.0
|
requests_toolbelt>=1.0.0
|
||||||
|
pyinstaller_versionfile>=2.1.1
|
||||||
|
py-cpuinfo~=9.0.0
|
||||||
|
requests-toolbelt~=1.0.0
|
||||||
|
ifaddr~=0.2.0
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
from src.api.api_server import start_server
|
from src.init import run
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
start_server()
|
run(server_only=True)
|
||||||
|
|||||||
22
setup.py
22
setup.py
@@ -1,22 +0,0 @@
|
|||||||
"""
|
|
||||||
This is a setup.py script generated by py2applet
|
|
||||||
|
|
||||||
Usage:
|
|
||||||
python setup.py py2app
|
|
||||||
"""
|
|
||||||
import glob
|
|
||||||
|
|
||||||
from setuptools import setup
|
|
||||||
|
|
||||||
APP = ['main.py']
|
|
||||||
DATA_FILES = [('config', glob.glob('config/*.*')),
|
|
||||||
('resources', glob.glob('resources/*.*'))]
|
|
||||||
OPTIONS = {}
|
|
||||||
|
|
||||||
setup(
|
|
||||||
app=APP,
|
|
||||||
data_files=DATA_FILES,
|
|
||||||
options={'py2app': OPTIONS},
|
|
||||||
setup_requires=['py2app'],
|
|
||||||
name='Zordon'
|
|
||||||
)
|
|
||||||
@@ -49,12 +49,11 @@ def handle_uploaded_project_files(request, jobs_list, upload_directory):
|
|||||||
raise ValueError(f"Error downloading file from URL: {project_url}")
|
raise ValueError(f"Error downloading file from URL: {project_url}")
|
||||||
elif local_path and os.path.exists(local_path):
|
elif local_path and os.path.exists(local_path):
|
||||||
referred_name = os.path.basename(local_path)
|
referred_name = os.path.basename(local_path)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise ValueError("Cannot find any valid project paths")
|
raise ValueError("Cannot find any valid project paths")
|
||||||
|
|
||||||
# Prepare the local filepath
|
# Prepare the local filepath
|
||||||
cleaned_path_name = os.path.splitext(referred_name)[0].replace(' ', '_')
|
cleaned_path_name = jobs_list[0].get('name', os.path.splitext(referred_name)[0]).replace(' ', '-')
|
||||||
job_dir = os.path.join(upload_directory, '-'.join(
|
job_dir = os.path.join(upload_directory, '-'.join(
|
||||||
[datetime.now().strftime("%Y.%m.%d_%H.%M.%S"), renderer, cleaned_path_name]))
|
[datetime.now().strftime("%Y.%m.%d_%H.%M.%S"), renderer, cleaned_path_name]))
|
||||||
os.makedirs(job_dir, exist_ok=True)
|
os.makedirs(job_dir, exist_ok=True)
|
||||||
|
|||||||
@@ -2,138 +2,98 @@
|
|||||||
import concurrent.futures
|
import concurrent.futures
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import multiprocessing
|
|
||||||
import os
|
import os
|
||||||
import pathlib
|
import pathlib
|
||||||
import shutil
|
import shutil
|
||||||
import socket
|
import socket
|
||||||
import ssl
|
import ssl
|
||||||
import tempfile
|
import tempfile
|
||||||
import threading
|
|
||||||
import time
|
import time
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from zipfile import ZipFile
|
|
||||||
|
|
||||||
|
import cpuinfo
|
||||||
import psutil
|
import psutil
|
||||||
import yaml
|
import yaml
|
||||||
from flask import Flask, request, send_file, after_this_request, Response, redirect, url_for, abort
|
from flask import Flask, request, send_file, after_this_request, Response, redirect, url_for
|
||||||
|
from sqlalchemy.orm.exc import DetachedInstanceError
|
||||||
|
|
||||||
from src.api.add_job_helpers import handle_uploaded_project_files, process_zipped_project
|
from src.api.add_job_helpers import handle_uploaded_project_files, process_zipped_project
|
||||||
from src.api.serverproxy_manager import ServerProxyManager
|
from src.api.preview_manager import PreviewManager
|
||||||
from src.distributed_job_manager import DistributedJobManager
|
from src.distributed_job_manager import DistributedJobManager
|
||||||
from src.engines.core.base_worker import string_to_status, RenderStatus
|
|
||||||
from src.engines.engine_manager import EngineManager
|
from src.engines.engine_manager import EngineManager
|
||||||
from src.render_queue import RenderQueue, JobNotFoundError
|
from src.render_queue import RenderQueue, JobNotFoundError
|
||||||
from src.utilities.config import Config
|
from src.utilities.config import Config
|
||||||
from src.utilities.misc_helper import system_safe_path, current_system_os, current_system_cpu, \
|
from src.utilities.misc_helper import system_safe_path, current_system_os, current_system_cpu, \
|
||||||
current_system_os_version, num_to_alphanumeric
|
current_system_os_version, num_to_alphanumeric, get_gpu_info
|
||||||
from src.utilities.server_helper import generate_thumbnail_for_job
|
from src.utilities.status_utils import string_to_status
|
||||||
from src.utilities.zeroconf_server import ZeroconfServer
|
from src.version import APP_VERSION
|
||||||
from src.utilities.benchmark import cpu_benchmark, disk_io_benchmark
|
|
||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
server = Flask(__name__)
|
server = Flask(__name__)
|
||||||
ssl._create_default_https_context = ssl._create_unverified_context # disable SSL for downloads
|
ssl._create_default_https_context = ssl._create_unverified_context # disable SSL for downloads
|
||||||
|
|
||||||
categories = [RenderStatus.RUNNING, RenderStatus.ERROR, RenderStatus.NOT_STARTED, RenderStatus.SCHEDULED,
|
API_VERSION = "1"
|
||||||
RenderStatus.COMPLETED, RenderStatus.CANCELLED]
|
|
||||||
|
def start_server(hostname=None):
|
||||||
|
|
||||||
|
# get hostname
|
||||||
|
if not hostname:
|
||||||
|
local_hostname = socket.gethostname()
|
||||||
|
hostname = local_hostname + (".local" if not local_hostname.endswith(".local") else "")
|
||||||
|
|
||||||
|
# load flask settings
|
||||||
|
server.config['HOSTNAME'] = hostname
|
||||||
|
server.config['PORT'] = int(Config.port_number)
|
||||||
|
server.config['UPLOAD_FOLDER'] = system_safe_path(os.path.expanduser(Config.upload_folder))
|
||||||
|
server.config['MAX_CONTENT_PATH'] = Config.max_content_path
|
||||||
|
server.config['enable_split_jobs'] = Config.enable_split_jobs
|
||||||
|
|
||||||
|
# disable most Flask logging
|
||||||
|
flask_log = logging.getLogger('werkzeug')
|
||||||
|
flask_log.setLevel(Config.flask_log_level.upper())
|
||||||
|
|
||||||
|
logger.debug('Starting API server')
|
||||||
|
try:
|
||||||
|
server.run(host=hostname, port=server.config['PORT'], debug=Config.flask_debug_enable, use_reloader=False,
|
||||||
|
threaded=True)
|
||||||
|
finally:
|
||||||
|
logger.debug('Stopping API server')
|
||||||
|
|
||||||
|
|
||||||
def sorted_jobs(all_jobs, sort_by_date=True):
|
# --------------------------------------------
|
||||||
if not sort_by_date:
|
# Get All Jobs
|
||||||
sorted_job_list = []
|
# --------------------------------------------
|
||||||
if all_jobs:
|
|
||||||
for status_category in categories:
|
|
||||||
found_jobs = [x for x in all_jobs if x.status == status_category.value]
|
|
||||||
if found_jobs:
|
|
||||||
sorted_found_jobs = sorted(found_jobs, key=lambda d: d.date_created, reverse=True)
|
|
||||||
sorted_job_list.extend(sorted_found_jobs)
|
|
||||||
else:
|
|
||||||
sorted_job_list = sorted(all_jobs, key=lambda d: d.date_created, reverse=True)
|
|
||||||
return sorted_job_list
|
|
||||||
|
|
||||||
|
|
||||||
@server.get('/api/jobs')
|
@server.get('/api/jobs')
|
||||||
def jobs_json():
|
def jobs_json():
|
||||||
try:
|
"""Retrieves all jobs from the render queue in JSON format.
|
||||||
all_jobs = [x.json() for x in RenderQueue.all_jobs()]
|
|
||||||
job_cache_int = int(json.dumps(all_jobs).__hash__())
|
This endpoint fetches all jobs currently in the render queue, converts them to JSON format,
|
||||||
job_cache_token = num_to_alphanumeric(job_cache_int)
|
and returns them along with a cache token that represents the current state of the job list.
|
||||||
return {'jobs': all_jobs, 'token': job_cache_token}
|
|
||||||
except Exception as e:
|
Returns:
|
||||||
logger.exception(f"Exception fetching jobs_json: {e}")
|
dict: A dictionary containing:
|
||||||
return {}, 500
|
- 'jobs' (list[dict]): A list of job dictionaries, each representing a job in the queue.
|
||||||
|
- 'token' (str): A cache token generated from the hash of the job list.
|
||||||
|
"""
|
||||||
|
all_jobs = [x.json() for x in RenderQueue.all_jobs()]
|
||||||
|
job_cache_int = int(json.dumps(all_jobs).__hash__())
|
||||||
|
job_cache_token = num_to_alphanumeric(job_cache_int)
|
||||||
|
return {'jobs': all_jobs, 'token': job_cache_token}
|
||||||
|
|
||||||
|
|
||||||
@server.get('/api/jobs_long_poll')
|
@server.get('/api/jobs_long_poll')
|
||||||
def long_polling_jobs():
|
def long_polling_jobs():
|
||||||
try:
|
hash_token = request.args.get('token', None)
|
||||||
hash_token = request.args.get('token', None)
|
start_time = time.time()
|
||||||
start_time = time.time()
|
while True:
|
||||||
while True:
|
all_jobs = jobs_json()
|
||||||
all_jobs = jobs_json()
|
if all_jobs['token'] != hash_token:
|
||||||
if all_jobs['token'] != hash_token:
|
return all_jobs
|
||||||
return all_jobs
|
# Break after 30 seconds to avoid gateway timeout
|
||||||
# Break after 30 seconds to avoid gateway timeout
|
if time.time() - start_time > 30:
|
||||||
if time.time() - start_time > 30:
|
return {}, 204
|
||||||
return {}, 204
|
time.sleep(1)
|
||||||
time.sleep(1)
|
|
||||||
except Exception as e:
|
|
||||||
logger.exception(f"Exception fetching long_polling_jobs: {e}")
|
|
||||||
return {}, 500
|
|
||||||
|
|
||||||
|
|
||||||
@server.route('/api/job/<job_id>/thumbnail')
|
|
||||||
def job_thumbnail(job_id):
|
|
||||||
big_thumb = request.args.get('size', False) == "big"
|
|
||||||
video_ok = request.args.get('video_ok', False)
|
|
||||||
found_job = RenderQueue.job_with_id(job_id, none_ok=True)
|
|
||||||
if found_job:
|
|
||||||
|
|
||||||
os.makedirs(server.config['THUMBS_FOLDER'], exist_ok=True)
|
|
||||||
thumb_video_path = os.path.join(server.config['THUMBS_FOLDER'], found_job.id + '.mp4')
|
|
||||||
thumb_image_path = os.path.join(server.config['THUMBS_FOLDER'], found_job.id + '.jpg')
|
|
||||||
big_video_path = os.path.join(server.config['THUMBS_FOLDER'], found_job.id + '_big.mp4')
|
|
||||||
big_image_path = os.path.join(server.config['THUMBS_FOLDER'], found_job.id + '_big.jpg')
|
|
||||||
|
|
||||||
# generate regular thumb if it doesn't exist
|
|
||||||
if not os.path.exists(thumb_video_path) and not os.path.exists(thumb_video_path + '_IN-PROGRESS') and \
|
|
||||||
found_job.status not in [RenderStatus.CANCELLED, RenderStatus.ERROR]:
|
|
||||||
generate_thumbnail_for_job(found_job, thumb_video_path, thumb_image_path, max_width=240)
|
|
||||||
|
|
||||||
# generate big thumb if it doesn't exist
|
|
||||||
if not os.path.exists(big_video_path) and not os.path.exists(big_image_path + '_IN-PROGRESS') and \
|
|
||||||
found_job.status not in [RenderStatus.CANCELLED, RenderStatus.ERROR]:
|
|
||||||
generate_thumbnail_for_job(found_job, big_video_path, big_image_path, max_width=800)
|
|
||||||
|
|
||||||
# generated videos
|
|
||||||
if video_ok:
|
|
||||||
if big_thumb and os.path.exists(big_video_path) and not os.path.exists(
|
|
||||||
big_video_path + '_IN-PROGRESS'):
|
|
||||||
return send_file(big_video_path, mimetype="video/mp4")
|
|
||||||
elif os.path.exists(thumb_video_path) and not os.path.exists(thumb_video_path + '_IN-PROGRESS'):
|
|
||||||
return send_file(thumb_video_path, mimetype="video/mp4")
|
|
||||||
|
|
||||||
# Generated thumbs
|
|
||||||
if big_thumb and os.path.exists(big_image_path):
|
|
||||||
return send_file(big_image_path, mimetype='image/jpeg')
|
|
||||||
elif os.path.exists(thumb_image_path):
|
|
||||||
return send_file(thumb_image_path, mimetype='image/jpeg')
|
|
||||||
|
|
||||||
return found_job.status.value, 200
|
|
||||||
return found_job.status.value, 404
|
|
||||||
|
|
||||||
|
|
||||||
# Get job file routing
|
|
||||||
@server.route('/api/job/<job_id>/file/<filename>', methods=['GET'])
|
|
||||||
def get_job_file(job_id, filename):
|
|
||||||
found_job = RenderQueue.job_with_id(job_id)
|
|
||||||
try:
|
|
||||||
for full_path in found_job.file_list():
|
|
||||||
if filename in full_path:
|
|
||||||
return send_file(path_or_file=full_path)
|
|
||||||
except FileNotFoundError:
|
|
||||||
abort(404)
|
|
||||||
|
|
||||||
|
|
||||||
@server.get('/api/jobs/<status_val>')
|
@server.get('/api/jobs/<status_val>')
|
||||||
@@ -146,29 +106,33 @@ def filtered_jobs_json(status_val):
|
|||||||
return f'Cannot find jobs with status {status_val}', 400
|
return f'Cannot find jobs with status {status_val}', 400
|
||||||
|
|
||||||
|
|
||||||
@server.post('/api/job/<job_id>/notify_parent_of_status_change')
|
# --------------------------------------------
|
||||||
def subjob_status_change(job_id):
|
# Job Details / File Handling
|
||||||
try:
|
# --------------------------------------------
|
||||||
subjob_details = request.json
|
|
||||||
logger.info(f"Subjob to job id: {job_id} is now {subjob_details['status']}")
|
|
||||||
DistributedJobManager.handle_subjob_status_change(RenderQueue.job_with_id(job_id), subjob_data=subjob_details)
|
|
||||||
return Response(status=200)
|
|
||||||
except JobNotFoundError:
|
|
||||||
return "Job not found", 404
|
|
||||||
|
|
||||||
|
|
||||||
@server.errorhandler(JobNotFoundError)
|
|
||||||
def handle_job_not_found(job_error):
|
|
||||||
return f'Cannot find job with ID {job_error.job_id}', 400
|
|
||||||
|
|
||||||
|
|
||||||
@server.get('/api/job/<job_id>')
|
@server.get('/api/job/<job_id>')
|
||||||
def get_job_status(job_id):
|
def get_job_details(job_id):
|
||||||
|
"""Retrieves the details of a requested job in JSON format
|
||||||
|
|
||||||
|
Args:
|
||||||
|
job_id (str): The ID of the render job.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
dict: A JSON representation of the job's details.
|
||||||
|
"""
|
||||||
return RenderQueue.job_with_id(job_id).json()
|
return RenderQueue.job_with_id(job_id).json()
|
||||||
|
|
||||||
|
|
||||||
@server.get('/api/job/<job_id>/logs')
|
@server.get('/api/job/<job_id>/logs')
|
||||||
def get_job_logs(job_id):
|
def get_job_logs(job_id):
|
||||||
|
"""Retrieves the log file for a specific render job.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
job_id (str): The ID of the render job.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Response: The log file's content as plain text, or an empty response if the log file is not found.
|
||||||
|
"""
|
||||||
found_job = RenderQueue.job_with_id(job_id)
|
found_job = RenderQueue.job_with_id(job_id)
|
||||||
log_path = system_safe_path(found_job.log_path())
|
log_path = system_safe_path(found_job.log_path())
|
||||||
log_data = None
|
log_data = None
|
||||||
@@ -180,11 +144,26 @@ def get_job_logs(job_id):
|
|||||||
|
|
||||||
@server.get('/api/job/<job_id>/file_list')
|
@server.get('/api/job/<job_id>/file_list')
|
||||||
def get_file_list(job_id):
|
def get_file_list(job_id):
|
||||||
return RenderQueue.job_with_id(job_id).file_list()
|
return [os.path.basename(x) for x in RenderQueue.job_with_id(job_id).file_list()]
|
||||||
|
|
||||||
|
|
||||||
|
@server.route('/api/job/<job_id>/download')
|
||||||
|
def download_requested_file(job_id):
|
||||||
|
|
||||||
|
requested_filename = request.args.get('filename')
|
||||||
|
if not requested_filename:
|
||||||
|
return 'Filename required', 400
|
||||||
|
|
||||||
|
found_job = RenderQueue.job_with_id(job_id)
|
||||||
|
for job_filename in found_job.file_list():
|
||||||
|
if os.path.basename(job_filename).lower() == requested_filename.lower():
|
||||||
|
return send_file(job_filename, as_attachment=True, )
|
||||||
|
|
||||||
|
return f"File '{requested_filename}' not found", 404
|
||||||
|
|
||||||
|
|
||||||
@server.route('/api/job/<job_id>/download_all')
|
@server.route('/api/job/<job_id>/download_all')
|
||||||
def download_all(job_id):
|
def download_all_files(job_id):
|
||||||
zip_filename = None
|
zip_filename = None
|
||||||
|
|
||||||
@after_this_request
|
@after_this_request
|
||||||
@@ -199,6 +178,7 @@ def download_all(job_id):
|
|||||||
found_job = RenderQueue.job_with_id(job_id)
|
found_job = RenderQueue.job_with_id(job_id)
|
||||||
output_dir = os.path.dirname(found_job.output_path)
|
output_dir = os.path.dirname(found_job.output_path)
|
||||||
if os.path.exists(output_dir):
|
if os.path.exists(output_dir):
|
||||||
|
from zipfile import ZipFile
|
||||||
zip_filename = system_safe_path(os.path.join(tempfile.gettempdir(),
|
zip_filename = system_safe_path(os.path.join(tempfile.gettempdir(),
|
||||||
pathlib.Path(found_job.input_path).stem + '.zip'))
|
pathlib.Path(found_job.input_path).stem + '.zip'))
|
||||||
with ZipFile(zip_filename, 'w') as zipObj:
|
with ZipFile(zip_filename, 'w') as zipObj:
|
||||||
@@ -210,6 +190,10 @@ def download_all(job_id):
|
|||||||
return f'Cannot find project files for job {job_id}', 500
|
return f'Cannot find project files for job {job_id}', 500
|
||||||
|
|
||||||
|
|
||||||
|
# --------------------------------------------
|
||||||
|
# System Environment / Status
|
||||||
|
# --------------------------------------------
|
||||||
|
|
||||||
@server.get('/api/presets')
|
@server.get('/api/presets')
|
||||||
def presets():
|
def presets():
|
||||||
presets_path = system_safe_path('config/presets.yaml')
|
presets_path = system_safe_path('config/presets.yaml')
|
||||||
@@ -241,13 +225,31 @@ def snapshot():
|
|||||||
return server_data
|
return server_data
|
||||||
|
|
||||||
|
|
||||||
@server.get('/api/_detected_clients')
|
@server.route('/api/status')
|
||||||
def detected_clients():
|
def status():
|
||||||
# todo: dev/debug only. Should not ship this - probably.
|
return {"timestamp": datetime.now().isoformat(),
|
||||||
return ZeroconfServer.found_hostnames()
|
"system_os": current_system_os(),
|
||||||
|
"system_os_version": current_system_os_version(),
|
||||||
|
"system_cpu": current_system_cpu(),
|
||||||
|
"system_cpu_brand": cpuinfo.get_cpu_info()['brand_raw'],
|
||||||
|
"cpu_percent": psutil.cpu_percent(percpu=False),
|
||||||
|
"cpu_percent_per_cpu": psutil.cpu_percent(percpu=True),
|
||||||
|
"cpu_count": psutil.cpu_count(logical=False),
|
||||||
|
"memory_total": psutil.virtual_memory().total,
|
||||||
|
"memory_available": psutil.virtual_memory().available,
|
||||||
|
"memory_percent": psutil.virtual_memory().percent,
|
||||||
|
"job_counts": RenderQueue.job_counts(),
|
||||||
|
"hostname": server.config['HOSTNAME'],
|
||||||
|
"port": server.config['PORT'],
|
||||||
|
"app_version": APP_VERSION,
|
||||||
|
"api_version": API_VERSION
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# New version
|
# --------------------------------------------
|
||||||
|
# Job Lifecyle (Create, Cancel, Delete)
|
||||||
|
# --------------------------------------------
|
||||||
|
|
||||||
@server.post('/api/add_job')
|
@server.post('/api/add_job')
|
||||||
def add_job_handler():
|
def add_job_handler():
|
||||||
# Process request data
|
# Process request data
|
||||||
@@ -301,104 +303,84 @@ def delete_job(job_id):
|
|||||||
|
|
||||||
# Check if we can remove the 'output' directory
|
# Check if we can remove the 'output' directory
|
||||||
found_job = RenderQueue.job_with_id(job_id)
|
found_job = RenderQueue.job_with_id(job_id)
|
||||||
|
project_dir = os.path.dirname(os.path.dirname(found_job.input_path))
|
||||||
output_dir = os.path.dirname(found_job.output_path)
|
output_dir = os.path.dirname(found_job.output_path)
|
||||||
|
found_job.stop()
|
||||||
|
|
||||||
|
try:
|
||||||
|
PreviewManager.delete_previews_for_job(found_job)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error deleting previews for {found_job}: {e}")
|
||||||
|
|
||||||
|
# finally delete the job
|
||||||
|
RenderQueue.delete_job(found_job)
|
||||||
|
|
||||||
|
# delete the output_dir
|
||||||
if server.config['UPLOAD_FOLDER'] in output_dir and os.path.exists(output_dir):
|
if server.config['UPLOAD_FOLDER'] in output_dir and os.path.exists(output_dir):
|
||||||
shutil.rmtree(output_dir)
|
shutil.rmtree(output_dir)
|
||||||
|
|
||||||
# Remove any thumbnails
|
# See if we own the project_dir (i.e. was it uploaded) - if so delete the directory
|
||||||
for filename in os.listdir(server.config['THUMBS_FOLDER']):
|
try:
|
||||||
if job_id in filename:
|
if server.config['UPLOAD_FOLDER'] in project_dir and os.path.exists(project_dir):
|
||||||
os.remove(os.path.join(server.config['THUMBS_FOLDER'], filename))
|
# check to see if any other projects are sharing the same project file
|
||||||
|
project_dir_files = [f for f in os.listdir(project_dir) if not f.startswith('.')]
|
||||||
thumb_path = os.path.join(server.config['THUMBS_FOLDER'], found_job.id + '.mp4')
|
if len(project_dir_files) == 0 or (len(project_dir_files) == 1 and 'source' in project_dir_files[0]):
|
||||||
if os.path.exists(thumb_path):
|
logger.info(f"Removing project directory: {project_dir}")
|
||||||
os.remove(thumb_path)
|
shutil.rmtree(project_dir)
|
||||||
|
except Exception as e:
|
||||||
# See if we own the project_dir (i.e. was it uploaded)
|
logger.error(f"Error removing project files: {e}")
|
||||||
project_dir = os.path.dirname(os.path.dirname(found_job.input_path))
|
|
||||||
if server.config['UPLOAD_FOLDER'] in project_dir and os.path.exists(project_dir):
|
|
||||||
# check to see if any other projects are sharing the same project file
|
|
||||||
project_dir_files = [f for f in os.listdir(project_dir) if not f.startswith('.')]
|
|
||||||
if len(project_dir_files) == 0 or (len(project_dir_files) == 1 and 'source' in project_dir_files[0]):
|
|
||||||
logger.info(f"Removing project directory: {project_dir}")
|
|
||||||
shutil.rmtree(project_dir)
|
|
||||||
|
|
||||||
RenderQueue.delete_job(found_job)
|
|
||||||
if request.args.get('redirect', False):
|
|
||||||
return redirect(url_for('index'))
|
|
||||||
else:
|
|
||||||
return "Job deleted", 200
|
|
||||||
|
|
||||||
|
return "Job deleted", 200
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error deleting job: {e}")
|
logger.error(f"Error deleting job: {e}")
|
||||||
return f"Error deleting job: {e}", 500
|
return f"Error deleting job: {e}", 500
|
||||||
|
|
||||||
|
|
||||||
@server.get('/api/clear_history')
|
# --------------------------------------------
|
||||||
def clear_history():
|
# Engine Info and Management:
|
||||||
RenderQueue.clear_history()
|
# --------------------------------------------
|
||||||
return 'success'
|
|
||||||
|
|
||||||
|
|
||||||
@server.route('/api/status')
|
|
||||||
def status():
|
|
||||||
|
|
||||||
# Get system info
|
|
||||||
return {"timestamp": datetime.now().isoformat(),
|
|
||||||
"system_os": current_system_os(),
|
|
||||||
"system_os_version": current_system_os_version(),
|
|
||||||
"system_cpu": current_system_cpu(),
|
|
||||||
"cpu_percent": psutil.cpu_percent(percpu=False),
|
|
||||||
"cpu_percent_per_cpu": psutil.cpu_percent(percpu=True),
|
|
||||||
"cpu_count": psutil.cpu_count(logical=False),
|
|
||||||
"memory_total": psutil.virtual_memory().total,
|
|
||||||
"memory_available": psutil.virtual_memory().available,
|
|
||||||
"memory_percent": psutil.virtual_memory().percent,
|
|
||||||
"job_counts": RenderQueue.job_counts(),
|
|
||||||
"hostname": server.config['HOSTNAME'],
|
|
||||||
"port": server.config['PORT']
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@server.get('/api/renderer_info')
|
@server.get('/api/renderer_info')
|
||||||
def renderer_info():
|
def renderer_info():
|
||||||
|
|
||||||
response_type = request.args.get('response_type', 'standard')
|
response_type = request.args.get('response_type', 'standard')
|
||||||
|
if response_type not in ['full', 'standard']:
|
||||||
|
raise ValueError(f"Invalid response_type: {response_type}")
|
||||||
|
|
||||||
def process_engine(engine):
|
def process_engine(engine):
|
||||||
try:
|
try:
|
||||||
# Get all installed versions of the engine
|
# Get all installed versions of the engine
|
||||||
installed_versions = EngineManager.all_versions_for_engine(engine.name())
|
installed_versions = EngineManager.all_versions_for_engine(engine.name())
|
||||||
if installed_versions:
|
if not installed_versions:
|
||||||
# Use system-installed versions to avoid permission issues
|
return None
|
||||||
system_installed_versions = [x for x in installed_versions if x['type'] == 'system']
|
|
||||||
install_path = system_installed_versions[0]['path'] if system_installed_versions else \
|
|
||||||
installed_versions[0]['path']
|
|
||||||
|
|
||||||
en = engine(install_path)
|
system_installed_versions = [v for v in installed_versions if v['type'] == 'system']
|
||||||
|
install_path = system_installed_versions[0]['path'] if system_installed_versions else installed_versions[0]['path']
|
||||||
|
|
||||||
if response_type == 'full': # Full dataset - Can be slow
|
en = engine(install_path)
|
||||||
return {
|
engine_name = en.name()
|
||||||
en.name(): {
|
result = {
|
||||||
'is_available': RenderQueue.is_available_for_job(en.name()),
|
engine_name: {
|
||||||
'versions': installed_versions,
|
'is_available': RenderQueue.is_available_for_job(engine_name),
|
||||||
'supported_extensions': engine.supported_extensions(),
|
'versions': installed_versions
|
||||||
'supported_export_formats': en.get_output_formats(),
|
}
|
||||||
'system_info': en.system_info()
|
}
|
||||||
}
|
|
||||||
|
if response_type == 'full':
|
||||||
|
with concurrent.futures.ThreadPoolExecutor() as executor:
|
||||||
|
future_results = {
|
||||||
|
'supported_extensions': executor.submit(en.supported_extensions),
|
||||||
|
'supported_export_formats': executor.submit(en.get_output_formats),
|
||||||
|
'system_info': executor.submit(en.system_info)
|
||||||
}
|
}
|
||||||
elif response_type == 'standard': # Simpler dataset to reduce response times
|
|
||||||
return {
|
for key, future in future_results.items():
|
||||||
en.name(): {
|
result[engine_name][key] = future.result()
|
||||||
'is_available': RenderQueue.is_available_for_job(en.name()),
|
|
||||||
'versions': installed_versions,
|
return result
|
||||||
}
|
|
||||||
}
|
|
||||||
else:
|
|
||||||
raise AttributeError(f"Invalid response_type: {response_type}")
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f'Error fetching details for {engine.name()} renderer: {e}')
|
logger.error(f'Error fetching details for {engine.name()} renderer: {e}')
|
||||||
return {}
|
raise e
|
||||||
|
|
||||||
renderer_data = {}
|
renderer_data = {}
|
||||||
with concurrent.futures.ThreadPoolExecutor() as executor:
|
with concurrent.futures.ThreadPoolExecutor() as executor:
|
||||||
@@ -478,71 +460,95 @@ def get_renderer_help(renderer):
|
|||||||
return f"Cannot find renderer '{renderer}'", 400
|
return f"Cannot find renderer '{renderer}'", 400
|
||||||
|
|
||||||
|
|
||||||
|
# --------------------------------------------
|
||||||
|
# Miscellaneous:
|
||||||
|
# --------------------------------------------
|
||||||
|
@server.post('/api/job/<job_id>/send_subjob_update_notification')
|
||||||
|
def subjob_update_notification(job_id):
|
||||||
|
subjob_details = request.json
|
||||||
|
DistributedJobManager.handle_subjob_update_notification(RenderQueue.job_with_id(job_id), subjob_data=subjob_details)
|
||||||
|
return Response(status=200)
|
||||||
|
|
||||||
|
|
||||||
|
@server.route('/api/job/<job_id>/thumbnail')
|
||||||
|
def job_thumbnail(job_id):
|
||||||
|
|
||||||
|
try:
|
||||||
|
big_thumb = request.args.get('size', False) == "big"
|
||||||
|
video_ok = request.args.get('video_ok', False)
|
||||||
|
found_job = RenderQueue.job_with_id(job_id, none_ok=False)
|
||||||
|
|
||||||
|
# trigger a thumbnail update - just in case
|
||||||
|
PreviewManager.update_previews_for_job(found_job, wait_until_completion=True, timeout=60)
|
||||||
|
previews = PreviewManager.get_previews_for_job(found_job)
|
||||||
|
all_previews_list = previews.get('output', previews.get('input', []))
|
||||||
|
|
||||||
|
video_previews = [x for x in all_previews_list if x['kind'] == 'video']
|
||||||
|
image_previews = [x for x in all_previews_list if x['kind'] == 'image']
|
||||||
|
filtered_list = video_previews if video_previews and video_ok else image_previews
|
||||||
|
|
||||||
|
# todo - sort by size or other metrics here
|
||||||
|
if filtered_list:
|
||||||
|
preview_to_send = filtered_list[0]
|
||||||
|
mime_types = {'image': 'image/jpeg', 'video': 'video/mp4'}
|
||||||
|
file_mime_type = mime_types.get(preview_to_send['kind'], 'unknown')
|
||||||
|
return send_file(preview_to_send['filename'], mimetype=file_mime_type)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f'Error getting thumbnail: {e}')
|
||||||
|
return f'Error getting thumbnail: {e}', 500
|
||||||
|
return "No thumbnail available", 404
|
||||||
|
|
||||||
|
|
||||||
|
# --------------------------------------------
|
||||||
|
# System Benchmarks:
|
||||||
|
# --------------------------------------------
|
||||||
|
|
||||||
@server.get('/api/cpu_benchmark')
|
@server.get('/api/cpu_benchmark')
|
||||||
def get_cpu_benchmark_score():
|
def get_cpu_benchmark_score():
|
||||||
|
from src.utilities.benchmark import cpu_benchmark
|
||||||
return str(cpu_benchmark(10))
|
return str(cpu_benchmark(10))
|
||||||
|
|
||||||
|
|
||||||
@server.get('/api/disk_benchmark')
|
@server.get('/api/disk_benchmark')
|
||||||
def get_disk_benchmark():
|
def get_disk_benchmark():
|
||||||
|
from src.utilities.benchmark import disk_io_benchmark
|
||||||
results = disk_io_benchmark()
|
results = disk_io_benchmark()
|
||||||
return {'write_speed': results[0], 'read_speed': results[-1]}
|
return {'write_speed': results[0], 'read_speed': results[-1]}
|
||||||
|
|
||||||
|
|
||||||
def start_server():
|
# --------------------------------------------
|
||||||
def eval_loop(delay_sec=1):
|
# Error Handlers:
|
||||||
while True:
|
# --------------------------------------------
|
||||||
RenderQueue.evaluate_queue()
|
|
||||||
time.sleep(delay_sec)
|
|
||||||
|
|
||||||
# get hostname
|
@server.errorhandler(JobNotFoundError)
|
||||||
local_hostname = socket.gethostname()
|
def handle_job_not_found(job_error):
|
||||||
local_hostname = local_hostname + (".local" if not local_hostname.endswith(".local") else "")
|
return str(job_error), 400
|
||||||
|
|
||||||
# load flask settings
|
|
||||||
server.config['HOSTNAME'] = local_hostname
|
|
||||||
server.config['PORT'] = int(Config.port_number)
|
|
||||||
server.config['UPLOAD_FOLDER'] = system_safe_path(os.path.expanduser(Config.upload_folder))
|
|
||||||
server.config['THUMBS_FOLDER'] = system_safe_path(os.path.join(os.path.expanduser(Config.upload_folder), 'thumbs'))
|
|
||||||
server.config['MAX_CONTENT_PATH'] = Config.max_content_path
|
|
||||||
server.config['enable_split_jobs'] = Config.enable_split_jobs
|
|
||||||
|
|
||||||
# Setup directory for saving engines to
|
@server.errorhandler(DetachedInstanceError)
|
||||||
EngineManager.engines_path = system_safe_path(os.path.join(os.path.join(os.path.expanduser(Config.upload_folder),
|
def handle_detached_instance(_):
|
||||||
'engines')))
|
return "Unavailable", 503
|
||||||
os.makedirs(EngineManager.engines_path, exist_ok=True)
|
|
||||||
|
|
||||||
# Debug info
|
|
||||||
logger.debug(f"Upload directory: {server.config['UPLOAD_FOLDER']}")
|
|
||||||
logger.debug(f"Thumbs directory: {server.config['THUMBS_FOLDER']}")
|
|
||||||
logger.debug(f"Engines directory: {EngineManager.engines_path}")
|
|
||||||
|
|
||||||
# disable most Flask logging
|
@server.errorhandler(Exception)
|
||||||
flask_log = logging.getLogger('werkzeug')
|
def handle_general_error(general_error):
|
||||||
flask_log.setLevel(Config.flask_log_level.upper())
|
err_msg = f"Server error: {general_error}"
|
||||||
|
logger.error(err_msg)
|
||||||
|
return err_msg, 500
|
||||||
|
|
||||||
# check for updates for render engines if configured or on first launch
|
|
||||||
if Config.update_engines_on_launch or not EngineManager.get_engines():
|
|
||||||
EngineManager.update_all_engines()
|
|
||||||
|
|
||||||
# Set up the RenderQueue object
|
# --------------------------------------------
|
||||||
RenderQueue.load_state(database_directory=server.config['UPLOAD_FOLDER'])
|
# Debug / Development Only:
|
||||||
ServerProxyManager.subscribe_to_listener()
|
# --------------------------------------------
|
||||||
DistributedJobManager.subscribe_to_listener()
|
|
||||||
|
|
||||||
thread = threading.Thread(target=eval_loop, kwargs={'delay_sec': Config.queue_eval_seconds}, daemon=True)
|
@server.get('/api/_debug/detected_clients')
|
||||||
thread.start()
|
def detected_clients():
|
||||||
|
# todo: dev/debug only. Should not ship this - probably.
|
||||||
|
from src.utilities.zeroconf_server import ZeroconfServer
|
||||||
|
return ZeroconfServer.found_hostnames()
|
||||||
|
|
||||||
logger.info(f"Starting Zordon Render Server - Hostname: '{server.config['HOSTNAME']}:'")
|
|
||||||
ZeroconfServer.configure("_zordon._tcp.local.", server.config['HOSTNAME'], server.config['PORT'])
|
|
||||||
ZeroconfServer.properties = {'system_cpu': current_system_cpu(), 'system_cpu_cores': multiprocessing.cpu_count(),
|
|
||||||
'system_os': current_system_os(),
|
|
||||||
'system_os_version': current_system_os_version()}
|
|
||||||
ZeroconfServer.start()
|
|
||||||
|
|
||||||
try:
|
@server.get('/api/_debug/clear_history')
|
||||||
server.run(host='0.0.0.0', port=server.config['PORT'], debug=Config.flask_debug_enable,
|
def clear_history():
|
||||||
use_reloader=False, threaded=True)
|
RenderQueue.clear_history()
|
||||||
finally:
|
return 'success'
|
||||||
RenderQueue.save_state()
|
|
||||||
ZeroconfServer.stop()
|
|
||||||
|
|||||||
113
src/api/preview_manager.py
Normal file
113
src/api/preview_manager.py
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
import logging
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
import threading
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from src.utilities.ffmpeg_helper import generate_thumbnail, save_first_frame
|
||||||
|
|
||||||
|
logger = logging.getLogger()
|
||||||
|
supported_video_formats = ['.mp4', '.mov', '.avi', '.mpg', '.mpeg', '.mxf', '.m4v', '.mkv', '.webm']
|
||||||
|
supported_image_formats = ['.jpg', '.png', '.exr', '.tif', '.tga', '.bmp', '.webp']
|
||||||
|
|
||||||
|
|
||||||
|
class PreviewManager:
|
||||||
|
|
||||||
|
storage_path = None
|
||||||
|
_running_jobs = {}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def __generate_job_preview_worker(cls, job, replace_existing=False, max_width=480):
|
||||||
|
|
||||||
|
# Determine best source file to use for thumbs
|
||||||
|
job_file_list = job.file_list()
|
||||||
|
source_files = job_file_list if job_file_list else [job.input_path]
|
||||||
|
preview_label = "output" if job_file_list else "input"
|
||||||
|
|
||||||
|
# filter by type
|
||||||
|
found_image_files = [f for f in source_files if os.path.splitext(f)[-1].lower() in supported_image_formats]
|
||||||
|
found_video_files = [f for f in source_files if os.path.splitext(f)[-1].lower() in supported_video_formats]
|
||||||
|
|
||||||
|
# check if we even have any valid files to work from
|
||||||
|
if source_files and not found_video_files and not found_image_files:
|
||||||
|
logger.warning(f"No valid image or video files found in files from job: {job}")
|
||||||
|
return
|
||||||
|
|
||||||
|
os.makedirs(cls.storage_path, exist_ok=True)
|
||||||
|
base_path = os.path.join(cls.storage_path, f"{job.id}-{preview_label}-{max_width}")
|
||||||
|
preview_video_path = base_path + '.mp4'
|
||||||
|
preview_image_path = base_path + '.jpg'
|
||||||
|
|
||||||
|
if replace_existing:
|
||||||
|
for x in [preview_image_path, preview_video_path]:
|
||||||
|
try:
|
||||||
|
os.remove(x)
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Generate image previews
|
||||||
|
if (found_video_files or found_image_files) and not os.path.exists(preview_image_path):
|
||||||
|
try:
|
||||||
|
path_of_source = found_image_files[-1] if found_image_files else found_video_files[-1]
|
||||||
|
logger.debug(f"Generating image preview for {path_of_source}")
|
||||||
|
save_first_frame(source_path=path_of_source, dest_path=preview_image_path, max_width=max_width)
|
||||||
|
logger.debug(f"Successfully created image preview for {path_of_source}")
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error generating image preview for {job}: {e}")
|
||||||
|
|
||||||
|
# Generate video previews
|
||||||
|
if found_video_files and not os.path.exists(preview_video_path):
|
||||||
|
try:
|
||||||
|
path_of_source = found_video_files[0]
|
||||||
|
logger.debug(f"Generating video preview for {path_of_source}")
|
||||||
|
generate_thumbnail(source_path=path_of_source, dest_path=preview_video_path, max_width=max_width)
|
||||||
|
logger.debug(f"Successfully created video preview for {path_of_source}")
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
logger.error(f"Error generating video preview for {job}: {e}")
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def update_previews_for_job(cls, job, replace_existing=False, wait_until_completion=False, timeout=None):
|
||||||
|
job_thread = cls._running_jobs.get(job.id)
|
||||||
|
if job_thread and job_thread.is_alive():
|
||||||
|
logger.debug(f'Preview generation job already running for {job}')
|
||||||
|
else:
|
||||||
|
job_thread = threading.Thread(target=cls.__generate_job_preview_worker, args=(job, replace_existing,))
|
||||||
|
job_thread.start()
|
||||||
|
cls._running_jobs[job.id] = job_thread
|
||||||
|
|
||||||
|
if wait_until_completion:
|
||||||
|
job_thread.join(timeout=timeout)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_previews_for_job(cls, job):
|
||||||
|
|
||||||
|
results = {}
|
||||||
|
try:
|
||||||
|
directory_path = Path(cls.storage_path)
|
||||||
|
preview_files_for_job = [f for f in directory_path.iterdir() if f.is_file() and f.name.startswith(job.id)]
|
||||||
|
|
||||||
|
for preview_filename in preview_files_for_job:
|
||||||
|
try:
|
||||||
|
pixel_width = str(preview_filename).split('-')[-1]
|
||||||
|
preview_label = str(os.path.basename(preview_filename)).split('-')[1]
|
||||||
|
extension = os.path.splitext(preview_filename)[-1].lower()
|
||||||
|
kind = 'video' if extension in supported_video_formats else \
|
||||||
|
'image' if extension in supported_image_formats else 'unknown'
|
||||||
|
results[preview_label] = results.get(preview_label, [])
|
||||||
|
results[preview_label].append({'filename': str(preview_filename), 'width': pixel_width, 'kind': kind})
|
||||||
|
except IndexError: # ignore invalid filenames
|
||||||
|
pass
|
||||||
|
except FileNotFoundError:
|
||||||
|
pass
|
||||||
|
return results
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def delete_previews_for_job(cls, job):
|
||||||
|
all_previews = cls.get_previews_for_job(job)
|
||||||
|
flattened_list = [item for sublist in all_previews.values() for item in sublist]
|
||||||
|
for preview in flattened_list:
|
||||||
|
try:
|
||||||
|
logger.debug(f"Removing preview: {preview['filename']}")
|
||||||
|
os.remove(preview['filename'])
|
||||||
|
except OSError as e:
|
||||||
|
logger.error(f"Error removing preview '{preview.get('filename')}': {e}")
|
||||||
@@ -10,7 +10,6 @@ from urllib.parse import urljoin
|
|||||||
|
|
||||||
from src.utilities.misc_helper import is_localhost
|
from src.utilities.misc_helper import is_localhost
|
||||||
from src.utilities.status_utils import RenderStatus
|
from src.utilities.status_utils import RenderStatus
|
||||||
from src.utilities.zeroconf_server import ZeroconfServer
|
|
||||||
|
|
||||||
status_colors = {RenderStatus.ERROR: "red", RenderStatus.CANCELLED: 'orange1', RenderStatus.COMPLETED: 'green',
|
status_colors = {RenderStatus.ERROR: "red", RenderStatus.CANCELLED: 'orange1', RenderStatus.COMPLETED: 'green',
|
||||||
RenderStatus.NOT_STARTED: "yellow", RenderStatus.SCHEDULED: 'purple',
|
RenderStatus.NOT_STARTED: "yellow", RenderStatus.SCHEDULED: 'purple',
|
||||||
@@ -26,15 +25,8 @@ LOOPBACK = '127.0.0.1'
|
|||||||
|
|
||||||
|
|
||||||
class RenderServerProxy:
|
class RenderServerProxy:
|
||||||
"""
|
"""The ServerProxy class is responsible for interacting with a remote server.
|
||||||
The ServerProxy class is responsible for interacting with a remote server.
|
It provides convenience methods to request data from the server and store the status of the server.
|
||||||
It provides methods to request data from the server and store the status of the server.
|
|
||||||
|
|
||||||
Attributes:
|
|
||||||
system_cpu (str): The CPU type of the system.
|
|
||||||
system_cpu_count (int): The number of CPUs in the system.
|
|
||||||
system_os (str): The operating system of the system.
|
|
||||||
system_os_version (str): The version of the operating system.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, hostname, server_port="8080"):
|
def __init__(self, hostname, server_port="8080"):
|
||||||
@@ -54,6 +46,11 @@ class RenderServerProxy:
|
|||||||
self.system_cpu_count = None
|
self.system_cpu_count = None
|
||||||
self.system_os = None
|
self.system_os = None
|
||||||
self.system_os_version = None
|
self.system_os_version = None
|
||||||
|
self.system_api_version = None
|
||||||
|
|
||||||
|
# --------------------------------------------
|
||||||
|
# Basics / Connection:
|
||||||
|
# --------------------------------------------
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"<RenderServerProxy - {self.hostname}>"
|
return f"<RenderServerProxy - {self.hostname}>"
|
||||||
@@ -73,6 +70,10 @@ class RenderServerProxy:
|
|||||||
running_jobs = [x for x in self.__jobs_cache if x['status'] == 'running'] if self.__jobs_cache else []
|
running_jobs = [x for x in self.__jobs_cache if x['status'] == 'running'] if self.__jobs_cache else []
|
||||||
return f"{len(running_jobs)} running" if running_jobs else "Ready"
|
return f"{len(running_jobs)} running" if running_jobs else "Ready"
|
||||||
|
|
||||||
|
# --------------------------------------------
|
||||||
|
# Requests:
|
||||||
|
# --------------------------------------------
|
||||||
|
|
||||||
def request_data(self, payload, timeout=5):
|
def request_data(self, payload, timeout=5):
|
||||||
try:
|
try:
|
||||||
req = self.request(payload, timeout)
|
req = self.request(payload, timeout)
|
||||||
@@ -100,8 +101,14 @@ class RenderServerProxy:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def request(self, payload, timeout=5):
|
def request(self, payload, timeout=5):
|
||||||
|
from src.api.api_server import API_VERSION
|
||||||
hostname = LOOPBACK if self.is_localhost else self.hostname
|
hostname = LOOPBACK if self.is_localhost else self.hostname
|
||||||
return requests.get(f'http://{hostname}:{self.port}/api/{payload}', timeout=timeout)
|
return requests.get(f'http://{hostname}:{self.port}/api/{payload}', timeout=timeout,
|
||||||
|
headers={"X-API-Version": str(API_VERSION)})
|
||||||
|
|
||||||
|
# --------------------------------------------
|
||||||
|
# Background Updates:
|
||||||
|
# --------------------------------------------
|
||||||
|
|
||||||
def start_background_update(self):
|
def start_background_update(self):
|
||||||
if self.__update_in_background:
|
if self.__update_in_background:
|
||||||
@@ -119,17 +126,6 @@ class RenderServerProxy:
|
|||||||
self.__background_thread.daemon = True
|
self.__background_thread.daemon = True
|
||||||
self.__background_thread.start()
|
self.__background_thread.start()
|
||||||
|
|
||||||
def stop_background_update(self):
|
|
||||||
self.__update_in_background = False
|
|
||||||
|
|
||||||
def get_job_info(self, job_id, timeout=5):
|
|
||||||
return self.request_data(f'job/{job_id}', timeout=timeout)
|
|
||||||
|
|
||||||
def get_all_jobs(self, timeout=5, ignore_token=False):
|
|
||||||
if not self.__update_in_background or ignore_token:
|
|
||||||
self.__update_job_cache(timeout, ignore_token)
|
|
||||||
return self.__jobs_cache.copy() if self.__jobs_cache else None
|
|
||||||
|
|
||||||
def __update_job_cache(self, timeout=40, ignore_token=False):
|
def __update_job_cache(self, timeout=40, ignore_token=False):
|
||||||
|
|
||||||
if self.__offline_flags: # if we're offline, don't bother with the long poll
|
if self.__offline_flags: # if we're offline, don't bother with the long poll
|
||||||
@@ -147,15 +143,21 @@ class RenderServerProxy:
|
|||||||
self.__jobs_cache = sorted_jobs
|
self.__jobs_cache = sorted_jobs
|
||||||
self.__jobs_cache_token = status_result['token']
|
self.__jobs_cache_token = status_result['token']
|
||||||
|
|
||||||
|
def stop_background_update(self):
|
||||||
|
self.__update_in_background = False
|
||||||
|
|
||||||
|
# --------------------------------------------
|
||||||
|
# Get System Info:
|
||||||
|
# --------------------------------------------
|
||||||
|
|
||||||
|
def get_all_jobs(self, timeout=5, ignore_token=False):
|
||||||
|
if not self.__update_in_background or ignore_token:
|
||||||
|
self.__update_job_cache(timeout, ignore_token)
|
||||||
|
return self.__jobs_cache.copy() if self.__jobs_cache else None
|
||||||
|
|
||||||
def get_data(self, timeout=5):
|
def get_data(self, timeout=5):
|
||||||
return self.request_data('full_status', timeout=timeout)
|
return self.request_data('full_status', timeout=timeout)
|
||||||
|
|
||||||
def cancel_job(self, job_id, confirm=False):
|
|
||||||
return self.request_data(f'job/{job_id}/cancel?confirm={confirm}')
|
|
||||||
|
|
||||||
def delete_job(self, job_id, confirm=False):
|
|
||||||
return self.request_data(f'job/{job_id}/delete?confirm={confirm}')
|
|
||||||
|
|
||||||
def get_status(self):
|
def get_status(self):
|
||||||
status = self.request_data('status')
|
status = self.request_data('status')
|
||||||
if status and not self.system_cpu:
|
if status and not self.system_cpu:
|
||||||
@@ -163,28 +165,22 @@ class RenderServerProxy:
|
|||||||
self.system_cpu_count = status['cpu_count']
|
self.system_cpu_count = status['cpu_count']
|
||||||
self.system_os = status['system_os']
|
self.system_os = status['system_os']
|
||||||
self.system_os_version = status['system_os_version']
|
self.system_os_version = status['system_os_version']
|
||||||
|
self.system_api_version = status['api_version']
|
||||||
return status
|
return status
|
||||||
|
|
||||||
def is_engine_available(self, engine_name):
|
# --------------------------------------------
|
||||||
return self.request_data(f'{engine_name}/is_available')
|
# Get Job Info:
|
||||||
|
# --------------------------------------------
|
||||||
|
|
||||||
def get_all_engines(self):
|
def get_job_info(self, job_id, timeout=5):
|
||||||
return self.request_data('all_engines')
|
return self.request_data(f'job/{job_id}', timeout=timeout)
|
||||||
|
|
||||||
def notify_parent_of_status_change(self, parent_id, subjob):
|
def get_job_files_list(self, job_id):
|
||||||
"""
|
return self.request_data(f"job/{job_id}/file_list")
|
||||||
Notifies the parent job of a status change in a subjob.
|
|
||||||
|
|
||||||
Args:
|
# --------------------------------------------
|
||||||
parent_id (str): The ID of the parent job.
|
# Job Lifecycle:
|
||||||
subjob (Job): The subjob that has changed status.
|
# --------------------------------------------
|
||||||
|
|
||||||
Returns:
|
|
||||||
Response: The response from the server.
|
|
||||||
"""
|
|
||||||
hostname = LOOPBACK if self.is_localhost else self.hostname
|
|
||||||
return requests.post(f'http://{hostname}:{self.port}/api/job/{parent_id}/notify_parent_of_status_change',
|
|
||||||
json=subjob.json())
|
|
||||||
|
|
||||||
def post_job_to_server(self, file_path, job_list, callback=None):
|
def post_job_to_server(self, file_path, job_list, callback=None):
|
||||||
"""
|
"""
|
||||||
@@ -232,21 +228,36 @@ class RenderServerProxy:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"An error occurred: {e}")
|
logger.error(f"An error occurred: {e}")
|
||||||
|
|
||||||
def get_job_files(self, job_id, save_path):
|
def cancel_job(self, job_id, confirm=False):
|
||||||
|
return self.request_data(f'job/{job_id}/cancel?confirm={confirm}')
|
||||||
|
|
||||||
|
def delete_job(self, job_id, confirm=False):
|
||||||
|
return self.request_data(f'job/{job_id}/delete?confirm={confirm}')
|
||||||
|
|
||||||
|
def send_subjob_update_notification(self, parent_id, subjob):
|
||||||
|
"""
|
||||||
|
Notifies the parent job of an update in a subjob.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
parent_id (str): The ID of the parent job.
|
||||||
|
subjob (Job): The subjob that has updated.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Response: The response from the server.
|
||||||
|
"""
|
||||||
hostname = LOOPBACK if self.is_localhost else self.hostname
|
hostname = LOOPBACK if self.is_localhost else self.hostname
|
||||||
url = f"http://{hostname}:{self.port}/api/job/{job_id}/download_all"
|
return requests.post(f'http://{hostname}:{self.port}/api/job/{parent_id}/send_subjob_update_notification',
|
||||||
return self.download_file(url, filename=save_path)
|
json=subjob.json())
|
||||||
|
|
||||||
@staticmethod
|
# --------------------------------------------
|
||||||
def download_file(url, filename):
|
# Renderers:
|
||||||
with requests.get(url, stream=True) as r:
|
# --------------------------------------------
|
||||||
r.raise_for_status()
|
|
||||||
with open(filename, 'wb') as f:
|
|
||||||
for chunk in r.iter_content(chunk_size=8192):
|
|
||||||
f.write(chunk)
|
|
||||||
return filename
|
|
||||||
|
|
||||||
# --- Renderer --- #
|
def is_engine_available(self, engine_name):
|
||||||
|
return self.request_data(f'{engine_name}/is_available')
|
||||||
|
|
||||||
|
def get_all_engines(self):
|
||||||
|
return self.request_data('all_engines')
|
||||||
|
|
||||||
def get_renderer_info(self, response_type='standard', timeout=5):
|
def get_renderer_info(self, response_type='standard', timeout=5):
|
||||||
"""
|
"""
|
||||||
@@ -277,3 +288,26 @@ class RenderServerProxy:
|
|||||||
form_data = {'engine': engine, 'version': version, 'system_cpu': system_cpu}
|
form_data = {'engine': engine, 'version': version, 'system_cpu': system_cpu}
|
||||||
hostname = LOOPBACK if self.is_localhost else self.hostname
|
hostname = LOOPBACK if self.is_localhost else self.hostname
|
||||||
return requests.post(f'http://{hostname}:{self.port}/api/delete_engine', json=form_data)
|
return requests.post(f'http://{hostname}:{self.port}/api/delete_engine', json=form_data)
|
||||||
|
|
||||||
|
# --------------------------------------------
|
||||||
|
# Download Files:
|
||||||
|
# --------------------------------------------
|
||||||
|
|
||||||
|
def download_all_job_files(self, job_id, save_path):
|
||||||
|
hostname = LOOPBACK if self.is_localhost else self.hostname
|
||||||
|
url = f"http://{hostname}:{self.port}/api/job/{job_id}/download_all"
|
||||||
|
return self.__download_file_from_url(url, output_filepath=save_path)
|
||||||
|
|
||||||
|
def download_job_file(self, job_id, job_filename, save_path):
|
||||||
|
hostname = LOOPBACK if self.is_localhost else self.hostname
|
||||||
|
url = f"http://{hostname}:{self.port}/api/job/{job_id}/download?filename={job_filename}"
|
||||||
|
return self.__download_file_from_url(url, output_filepath=save_path)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def __download_file_from_url(url, output_filepath):
|
||||||
|
with requests.get(url, stream=True) as r:
|
||||||
|
r.raise_for_status()
|
||||||
|
with open(output_filepath, 'wb') as f:
|
||||||
|
for chunk in r.iter_content(chunk_size=8192):
|
||||||
|
f.write(chunk)
|
||||||
|
return output_filepath
|
||||||
|
|||||||
@@ -3,17 +3,16 @@ import os
|
|||||||
import socket
|
import socket
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
import zipfile
|
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
|
||||||
|
|
||||||
import requests
|
|
||||||
from plyer import notification
|
from plyer import notification
|
||||||
from pubsub import pub
|
from pubsub import pub
|
||||||
|
|
||||||
|
from src.api.preview_manager import PreviewManager
|
||||||
from src.api.server_proxy import RenderServerProxy
|
from src.api.server_proxy import RenderServerProxy
|
||||||
from src.engines.engine_manager import EngineManager
|
from src.engines.engine_manager import EngineManager
|
||||||
from src.render_queue import RenderQueue
|
from src.render_queue import RenderQueue
|
||||||
from src.utilities.misc_helper import get_file_size_human
|
from src.utilities.config import Config
|
||||||
|
from src.utilities.server_helper import download_missing_frames_from_subjob, distribute_server_work
|
||||||
from src.utilities.status_utils import RenderStatus, string_to_status
|
from src.utilities.status_utils import RenderStatus, string_to_status
|
||||||
from src.utilities.zeroconf_server import ZeroconfServer
|
from src.utilities.zeroconf_server import ZeroconfServer
|
||||||
|
|
||||||
@@ -32,6 +31,43 @@ class DistributedJobManager:
|
|||||||
This should be called once, typically during the initialization phase.
|
This should be called once, typically during the initialization phase.
|
||||||
"""
|
"""
|
||||||
pub.subscribe(cls.__local_job_status_changed, 'status_change')
|
pub.subscribe(cls.__local_job_status_changed, 'status_change')
|
||||||
|
pub.subscribe(cls.__local_job_frame_complete, 'frame_complete')
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def __local_job_frame_complete(cls, job_id, frame_number, update_interval=5):
|
||||||
|
|
||||||
|
"""
|
||||||
|
Responds to the 'frame_complete' pubsub message for local jobs.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
job_id (str): The ID of the job that has changed status.
|
||||||
|
old_status (str): The previous status of the job.
|
||||||
|
new_status (str): The new (current) status of the job.
|
||||||
|
|
||||||
|
Note: Do not call directly. Instead, call via the 'frame_complete' pubsub message.
|
||||||
|
"""
|
||||||
|
|
||||||
|
render_job = RenderQueue.job_with_id(job_id, none_ok=True)
|
||||||
|
if not render_job: # ignore jobs not in the queue
|
||||||
|
return
|
||||||
|
|
||||||
|
logger.debug(f"Job {job_id} has completed frame #{frame_number}")
|
||||||
|
replace_existing_previews = (frame_number % update_interval) == 0
|
||||||
|
cls.__job_update_shared(render_job, replace_existing_previews)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def __job_update_shared(cls, render_job, replace_existing_previews=False):
|
||||||
|
# update previews
|
||||||
|
PreviewManager.update_previews_for_job(job=render_job, replace_existing=replace_existing_previews)
|
||||||
|
|
||||||
|
# notify parent to allow individual frames to be copied instead of waiting until the end
|
||||||
|
if render_job.parent:
|
||||||
|
parent_id, parent_hostname = render_job.parent.split('@')[0], render_job.parent.split('@')[-1]
|
||||||
|
try:
|
||||||
|
logger.debug(f'Job {render_job.id} updating parent {parent_id}@{parent_hostname}')
|
||||||
|
RenderServerProxy(parent_hostname).send_subjob_update_notification(parent_id, render_job)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error notifying parent {parent_hostname} about update in subjob {render_job.id}: {e}")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def __local_job_status_changed(cls, job_id, old_status, new_status):
|
def __local_job_status_changed(cls, job_id, old_status, new_status):
|
||||||
@@ -39,10 +75,10 @@ class DistributedJobManager:
|
|||||||
Responds to the 'status_change' pubsub message for local jobs.
|
Responds to the 'status_change' pubsub message for local jobs.
|
||||||
If it's a child job, it notifies the parent job about the status change.
|
If it's a child job, it notifies the parent job about the status change.
|
||||||
|
|
||||||
Parameters:
|
Args:
|
||||||
job_id (str): The ID of the job that has changed status.
|
job_id (str): The ID of the job that has changed status.
|
||||||
old_status (str): The previous status of the job.
|
old_status (str): The previous status of the job.
|
||||||
new_status (str): The new (current) status of the job.
|
new_status (str): The new (current) status of the job.
|
||||||
|
|
||||||
Note: Do not call directly. Instead, call via the 'status_change' pubsub message.
|
Note: Do not call directly. Instead, call via the 'status_change' pubsub message.
|
||||||
"""
|
"""
|
||||||
@@ -52,15 +88,15 @@ class DistributedJobManager:
|
|||||||
return
|
return
|
||||||
|
|
||||||
logger.debug(f"Job {job_id} status change: {old_status} -> {new_status}")
|
logger.debug(f"Job {job_id} status change: {old_status} -> {new_status}")
|
||||||
if render_job.parent: # If local job is a subjob from a remote server
|
|
||||||
parent_id, hostname = render_job.parent.split('@')[0], render_job.parent.split('@')[-1]
|
|
||||||
RenderServerProxy(hostname).notify_parent_of_status_change(parent_id=parent_id, subjob=render_job)
|
|
||||||
|
|
||||||
# handle cancelling all the children
|
cls.__job_update_shared(render_job, replace_existing_previews=(render_job.status == RenderStatus.COMPLETED))
|
||||||
elif render_job.children and new_status in [RenderStatus.CANCELLED, RenderStatus.ERROR]:
|
|
||||||
for child in render_job.children:
|
# Handle children
|
||||||
child_id, hostname = child.split('@')
|
if render_job.children:
|
||||||
RenderServerProxy(hostname).cancel_job(child_id, confirm=True)
|
if new_status in [RenderStatus.CANCELLED, RenderStatus.ERROR]: # Cancel children if necessary
|
||||||
|
for child in render_job.children:
|
||||||
|
child_id, child_hostname = child.split('@')
|
||||||
|
RenderServerProxy(child_hostname).cancel_job(child_id, confirm=True)
|
||||||
|
|
||||||
# UI Notifications
|
# UI Notifications
|
||||||
try:
|
try:
|
||||||
@@ -93,15 +129,12 @@ class DistributedJobManager:
|
|||||||
# --------------------------------------------
|
# --------------------------------------------
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_render_job(cls, job_data, loaded_project_local_path):
|
def create_render_job(cls, new_job_attributes, loaded_project_local_path):
|
||||||
"""
|
"""Creates render jobs. Pass in dict of job_data and the local path to the project. It creates and returns a new
|
||||||
Creates render jobs.
|
render job.
|
||||||
|
|
||||||
This method takes a list of job data, a local path to a loaded project, and a job directory. It creates a render
|
|
||||||
job for each job data in the list and appends the result to a list. The list of results is then returned.
|
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
job_data (dict): Job data.
|
new_job_attributes (dict): Dict of desired attributes for new job (frame count, renderer, output path, etc)
|
||||||
loaded_project_local_path (str): The local path to the loaded project.
|
loaded_project_local_path (str): The local path to the loaded project.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
@@ -109,7 +142,7 @@ class DistributedJobManager:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# get new output path in output_dir
|
# get new output path in output_dir
|
||||||
output_path = job_data.get('output_path')
|
output_path = new_job_attributes.get('output_path')
|
||||||
if not output_path:
|
if not output_path:
|
||||||
loaded_project_filename = os.path.basename(loaded_project_local_path)
|
loaded_project_filename = os.path.basename(loaded_project_local_path)
|
||||||
output_filename = os.path.splitext(loaded_project_filename)[0]
|
output_filename = os.path.splitext(loaded_project_filename)[0]
|
||||||
@@ -123,26 +156,28 @@ class DistributedJobManager:
|
|||||||
logger.debug(f"New job output path: {output_path}")
|
logger.debug(f"New job output path: {output_path}")
|
||||||
|
|
||||||
# create & configure jobs
|
# create & configure jobs
|
||||||
worker = EngineManager.create_worker(renderer=job_data['renderer'],
|
worker = EngineManager.create_worker(renderer=new_job_attributes['renderer'],
|
||||||
input_path=loaded_project_local_path,
|
input_path=loaded_project_local_path,
|
||||||
output_path=output_path,
|
output_path=output_path,
|
||||||
engine_version=job_data.get('engine_version'),
|
engine_version=new_job_attributes.get('engine_version'),
|
||||||
args=job_data.get('args', {}),
|
args=new_job_attributes.get('args', {}),
|
||||||
parent=job_data.get('parent'),
|
parent=new_job_attributes.get('parent'),
|
||||||
name=job_data.get('name'))
|
name=new_job_attributes.get('name'))
|
||||||
worker.status = job_data.get("initial_status", worker.status) # todo: is this necessary?
|
worker.status = new_job_attributes.get("initial_status", worker.status) # todo: is this necessary?
|
||||||
worker.priority = int(job_data.get('priority', worker.priority))
|
worker.priority = int(new_job_attributes.get('priority', worker.priority))
|
||||||
worker.start_frame = int(job_data.get("start_frame", worker.start_frame))
|
worker.start_frame = int(new_job_attributes.get("start_frame", worker.start_frame))
|
||||||
worker.end_frame = int(job_data.get("end_frame", worker.end_frame))
|
worker.end_frame = int(new_job_attributes.get("end_frame", worker.end_frame))
|
||||||
|
worker.watchdog_timeout = Config.worker_process_timeout
|
||||||
worker.hostname = socket.gethostname()
|
worker.hostname = socket.gethostname()
|
||||||
|
|
||||||
# determine if we can / should split the job
|
# determine if we can / should split the job
|
||||||
if job_data.get("enable_split_jobs", False) and (worker.total_frames > 1) and not worker.parent:
|
if new_job_attributes.get("enable_split_jobs", False) and (worker.total_frames > 1) and not worker.parent:
|
||||||
cls.split_into_subjobs_async(worker, job_data, loaded_project_local_path)
|
cls.split_into_subjobs_async(worker, new_job_attributes, loaded_project_local_path)
|
||||||
else:
|
else:
|
||||||
logger.debug("Not splitting into subjobs")
|
worker.status = RenderStatus.NOT_STARTED
|
||||||
|
|
||||||
RenderQueue.add_to_render_queue(worker, force_start=job_data.get('force_start', False))
|
RenderQueue.add_to_render_queue(worker, force_start=new_job_attributes.get('force_start', False))
|
||||||
|
PreviewManager.update_previews_for_job(worker)
|
||||||
|
|
||||||
return worker
|
return worker
|
||||||
|
|
||||||
@@ -151,9 +186,8 @@ class DistributedJobManager:
|
|||||||
# --------------------------------------------
|
# --------------------------------------------
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def handle_subjob_status_change(cls, local_job, subjob_data):
|
def handle_subjob_update_notification(cls, local_job, subjob_data):
|
||||||
"""
|
"""Responds to a notification from a remote subjob and the host requests any subsequent updates from the subjob.
|
||||||
Responds to a status change from a remote subjob and triggers the creation or modification of subjobs as needed.
|
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
local_job (BaseRenderWorker): The local parent job worker.
|
local_job (BaseRenderWorker): The local parent job worker.
|
||||||
@@ -162,140 +196,104 @@ class DistributedJobManager:
|
|||||||
|
|
||||||
subjob_status = string_to_status(subjob_data['status'])
|
subjob_status = string_to_status(subjob_data['status'])
|
||||||
subjob_id = subjob_data['id']
|
subjob_id = subjob_data['id']
|
||||||
subjob_hostname = next((hostname.split('@')[1] for hostname in local_job.children if
|
subjob_hostname = subjob_data['hostname']
|
||||||
hostname.split('@')[0] == subjob_id), None)
|
subjob_key = f'{subjob_id}@{subjob_hostname}'
|
||||||
local_job.children[f'{subjob_id}@{subjob_hostname}'] = subjob_data
|
old_status = local_job.children.get(subjob_key, {}).get('status')
|
||||||
|
local_job.children[subjob_key] = subjob_data
|
||||||
|
|
||||||
logname = f"{local_job.id}:{subjob_id}@{subjob_hostname}"
|
logname = f"<Parent: {local_job.id} | Child: {subjob_key}>"
|
||||||
logger.debug(f"Subjob status changed: {logname} -> {subjob_status.value}")
|
if old_status != subjob_status.value:
|
||||||
|
logger.debug(f"Subjob status changed: {logname} -> {subjob_status.value}")
|
||||||
|
|
||||||
# Download complete or partial render jobs
|
download_success = download_missing_frames_from_subjob(local_job, subjob_id, subjob_hostname)
|
||||||
if subjob_status in [RenderStatus.COMPLETED, RenderStatus.CANCELLED, RenderStatus.ERROR] and \
|
if subjob_data['status'] == 'completed' and download_success:
|
||||||
subjob_data['file_count']:
|
local_job.children[subjob_key]['download_status'] = 'completed'
|
||||||
download_result = cls.download_from_subjob(local_job, subjob_id, subjob_hostname)
|
|
||||||
if not download_result:
|
|
||||||
# todo: handle error
|
|
||||||
logger.error(f"Unable to download subjob files from {logname} with status {subjob_status.value}")
|
|
||||||
|
|
||||||
if subjob_status == RenderStatus.CANCELLED or subjob_status == RenderStatus.ERROR:
|
|
||||||
# todo: determine missing frames and schedule new job
|
|
||||||
pass
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def download_from_subjob(local_job, subjob_id, subjob_hostname):
|
|
||||||
"""
|
|
||||||
Downloads and extracts files from a completed subjob on a remote server.
|
|
||||||
|
|
||||||
Parameters:
|
|
||||||
local_job (BaseRenderWorker): The local parent job worker.
|
|
||||||
subjob_id (str or int): The ID of the subjob.
|
|
||||||
subjob_hostname (str): The hostname of the remote server where the subjob is located.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
bool: True if the files have been downloaded and extracted successfully, False otherwise.
|
|
||||||
"""
|
|
||||||
|
|
||||||
child_key = f'{subjob_id}@{subjob_hostname}'
|
|
||||||
logname = f"{local_job.id}:{child_key}"
|
|
||||||
zip_file_path = local_job.output_path + f'_{subjob_hostname}_{subjob_id}.zip'
|
|
||||||
|
|
||||||
# download zip file from server
|
|
||||||
try:
|
|
||||||
local_job.children[child_key]['download_status'] = 'working'
|
|
||||||
logger.info(f"Downloading completed subjob files from {subjob_hostname} to localhost")
|
|
||||||
RenderServerProxy(subjob_hostname).get_job_files(subjob_id, zip_file_path)
|
|
||||||
logger.info(f"File transfer complete for {logname} - Transferred {get_file_size_human(zip_file_path)}")
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"Error downloading files from remote server: {e}")
|
|
||||||
local_job.children[child_key]['download_status'] = 'failed'
|
|
||||||
return False
|
|
||||||
|
|
||||||
# extract zip
|
|
||||||
try:
|
|
||||||
logger.debug(f"Extracting zip file: {zip_file_path}")
|
|
||||||
extract_path = os.path.dirname(zip_file_path)
|
|
||||||
with zipfile.ZipFile(zip_file_path, 'r') as zip_ref:
|
|
||||||
zip_ref.extractall(extract_path)
|
|
||||||
logger.info(f"Successfully extracted zip to: {extract_path}")
|
|
||||||
os.remove(zip_file_path)
|
|
||||||
local_job.children[child_key]['download_status'] = 'complete'
|
|
||||||
except Exception as e:
|
|
||||||
logger.exception(f"Exception extracting zip file: {e}")
|
|
||||||
local_job.children[child_key]['download_status'] = 'failed'
|
|
||||||
|
|
||||||
return local_job.children[child_key].get('download_status', None) == 'complete'
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def wait_for_subjobs(cls, local_job):
|
def wait_for_subjobs(cls, parent_job):
|
||||||
logger.debug(f"Waiting for subjobs for job {local_job}")
|
"""Check the status of subjobs and waits until they are all finished. Download rendered frames from subjobs
|
||||||
local_job.status = RenderStatus.WAITING_FOR_SUBJOBS
|
when they are completed.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
parent_job: Worker object that has child jobs
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
"""
|
||||||
|
logger.debug(f"Waiting for subjobs for job {parent_job}")
|
||||||
|
parent_job.status = RenderStatus.WAITING_FOR_SUBJOBS
|
||||||
statuses_to_download = [RenderStatus.CANCELLED, RenderStatus.ERROR, RenderStatus.COMPLETED]
|
statuses_to_download = [RenderStatus.CANCELLED, RenderStatus.ERROR, RenderStatus.COMPLETED]
|
||||||
|
|
||||||
def subjobs_not_downloaded():
|
def subjobs_not_downloaded():
|
||||||
return {k: v for k, v in local_job.children.items() if 'download_status' not in v or
|
return {k: v for k, v in parent_job.children.items() if 'download_status' not in v or
|
||||||
v['download_status'] == 'working' or v['download_status'] is None}
|
v['download_status'] == 'working' or v['download_status'] is None}
|
||||||
|
|
||||||
logger.info(f'Waiting on {len(subjobs_not_downloaded())} subjobs for {local_job.id}')
|
logger.info(f'Waiting on {len(subjobs_not_downloaded())} subjobs for {parent_job.id}')
|
||||||
|
|
||||||
while len(subjobs_not_downloaded()):
|
server_delay = 10
|
||||||
for child_key, subjob_cached_data in subjobs_not_downloaded().items():
|
sleep_counter = 0
|
||||||
|
while parent_job.status == RenderStatus.WAITING_FOR_SUBJOBS:
|
||||||
|
|
||||||
subjob_id = child_key.split('@')[0]
|
if sleep_counter % server_delay == 0: # only ping servers every x seconds
|
||||||
subjob_hostname = child_key.split('@')[-1]
|
for child_key, subjob_cached_data in subjobs_not_downloaded().items():
|
||||||
|
|
||||||
# Fetch info from server and handle failing case
|
subjob_id = child_key.split('@')[0]
|
||||||
subjob_data = RenderServerProxy(subjob_hostname).get_job_info(subjob_id)
|
subjob_hostname = child_key.split('@')[-1]
|
||||||
if not subjob_data:
|
|
||||||
logger.warning(f"No response from: {subjob_hostname}")
|
|
||||||
# todo: handle timeout / missing server situations
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Update parent job cache but keep the download status
|
# Fetch info from server and handle failing case
|
||||||
download_status = local_job.children[child_key].get('download_status', None)
|
subjob_data = RenderServerProxy(subjob_hostname).get_job_info(subjob_id)
|
||||||
local_job.children[child_key] = subjob_data
|
if not subjob_data:
|
||||||
local_job.children[child_key]['download_status'] = download_status
|
logger.warning(f"No response from {subjob_hostname}")
|
||||||
|
# timeout / missing server situations
|
||||||
|
parent_job.children[child_key]['download_status'] = f'error: No response from {subjob_hostname}'
|
||||||
|
continue
|
||||||
|
|
||||||
status = string_to_status(subjob_data.get('status', ''))
|
# Update parent job cache but keep the download status
|
||||||
status_msg = f"Subjob {child_key} | {status} | " \
|
download_status = parent_job.children[child_key].get('download_status', None)
|
||||||
f"{float(subjob_data.get('percent_complete')) * 100.0}%"
|
parent_job.children[child_key] = subjob_data
|
||||||
logger.debug(status_msg)
|
parent_job.children[child_key]['download_status'] = download_status
|
||||||
|
|
||||||
# Still working in another thread - keep waiting
|
status = string_to_status(subjob_data.get('status', ''))
|
||||||
if download_status == 'working':
|
status_msg = f"Subjob {child_key} | {status} | " \
|
||||||
continue
|
f"{float(subjob_data.get('percent_complete')) * 100.0}%"
|
||||||
|
logger.debug(status_msg)
|
||||||
|
|
||||||
# Check if job is finished, but has not had files copied yet over yet
|
# Check if job is finished, but has not had files copied yet over yet
|
||||||
if download_status is None and subjob_data['file_count'] and status in statuses_to_download:
|
if download_status is None and subjob_data['file_count'] and status in statuses_to_download:
|
||||||
download_result = cls.download_from_subjob(local_job, subjob_id, subjob_hostname)
|
try:
|
||||||
if not download_result:
|
download_missing_frames_from_subjob(parent_job, subjob_id, subjob_hostname)
|
||||||
logger.error("Failed to download from subjob")
|
parent_job.children[child_key]['download_status'] = 'complete'
|
||||||
# todo: error handling here
|
except Exception as e:
|
||||||
|
logger.error(f"Error downloading missing frames from subjob: {e}")
|
||||||
|
parent_job.children[child_key]['download_status'] = 'error: {}'
|
||||||
|
|
||||||
# Any finished jobs not successfully downloaded at this point are skipped
|
# Any finished jobs not successfully downloaded at this point are skipped
|
||||||
if local_job.children[child_key].get('download_status', None) is None and \
|
if parent_job.children[child_key].get('download_status', None) is None and \
|
||||||
status in statuses_to_download:
|
status in statuses_to_download:
|
||||||
logger.warning(f"Skipping waiting on downloading from subjob: {child_key}")
|
logger.warning(f"Skipping waiting on downloading from subjob: {child_key}")
|
||||||
local_job.children[child_key]['download_status'] = 'skipped'
|
parent_job.children[child_key]['download_status'] = 'skipped'
|
||||||
|
|
||||||
if subjobs_not_downloaded():
|
if subjobs_not_downloaded():
|
||||||
logger.debug(f"Waiting on {len(subjobs_not_downloaded())} subjobs on "
|
logger.debug(f"Waiting on {len(subjobs_not_downloaded())} subjobs on "
|
||||||
f"{', '.join(list(subjobs_not_downloaded().keys()))}")
|
f"{', '.join(list(subjobs_not_downloaded().keys()))}")
|
||||||
time.sleep(5)
|
time.sleep(1)
|
||||||
|
sleep_counter += 1
|
||||||
|
else: # exit the loop
|
||||||
|
parent_job.status = RenderStatus.RUNNING
|
||||||
|
|
||||||
# --------------------------------------------
|
# --------------------------------------------
|
||||||
# Creating Subjobs
|
# Creating Subjobs
|
||||||
# --------------------------------------------
|
# --------------------------------------------
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def split_into_subjobs_async(cls, parent_worker, job_data, project_path, system_os=None):
|
def split_into_subjobs_async(cls, parent_worker, new_job_attributes, project_path, system_os=None):
|
||||||
# todo: I don't love this
|
# todo: I don't love this
|
||||||
parent_worker.status = RenderStatus.CONFIGURING
|
parent_worker.status = RenderStatus.CONFIGURING
|
||||||
cls.background_worker = threading.Thread(target=cls.split_into_subjobs, args=(parent_worker, job_data,
|
cls.background_worker = threading.Thread(target=cls.split_into_subjobs, args=(parent_worker, new_job_attributes,
|
||||||
project_path, system_os))
|
project_path, system_os))
|
||||||
cls.background_worker.start()
|
cls.background_worker.start()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def split_into_subjobs(cls, parent_worker, job_data, project_path, system_os=None, specific_servers=None):
|
def split_into_subjobs(cls, parent_worker, new_job_attributes, project_path, system_os=None, specific_servers=None):
|
||||||
"""
|
"""
|
||||||
Splits a job into subjobs and distributes them among available servers.
|
Splits a job into subjobs and distributes them among available servers.
|
||||||
|
|
||||||
@@ -304,43 +302,43 @@ class DistributedJobManager:
|
|||||||
subjob.
|
subjob.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
parent_worker (Worker): The worker that is handling the job.
|
parent_worker (Worker): The parent job what we're creating the subjobs for.
|
||||||
job_data (dict): The data for the job to be split.
|
new_job_attributes (dict): Dict of desired attributes for new job (frame count, renderer, output path, etc)
|
||||||
project_path (str): The path to the project associated with the job.
|
project_path (str): The path to the project.
|
||||||
system_os (str, optional): The operating system of the servers. Default is any OS.
|
system_os (str, optional): Required OS. Default is any.
|
||||||
specific_servers (list, optional): List of specific servers to split work between. Defaults to all found.
|
specific_servers (list, optional): List of specific servers to split work between. Defaults to all found.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Check availability
|
# Check availability
|
||||||
parent_worker.status = RenderStatus.CONFIGURING
|
available_servers = specific_servers if specific_servers else cls.find_available_servers(parent_worker.renderer,
|
||||||
available_servers = specific_servers if specific_servers else cls.find_available_servers(parent_worker.renderer, system_os)
|
system_os)
|
||||||
logger.debug(f"Splitting into subjobs - Available servers: {available_servers}")
|
# skip if theres no external servers found
|
||||||
all_subjob_server_data = cls.distribute_server_work(parent_worker.start_frame, parent_worker.end_frame, available_servers)
|
external_servers = [x for x in available_servers if x['hostname'] != parent_worker.hostname]
|
||||||
|
if not external_servers:
|
||||||
|
parent_worker.status = RenderStatus.NOT_STARTED
|
||||||
|
return
|
||||||
|
|
||||||
|
logger.debug(f"Splitting into subjobs - Available servers: {[x['hostname'] for x in available_servers]}")
|
||||||
|
all_subjob_server_data = distribute_server_work(parent_worker.start_frame, parent_worker.end_frame, available_servers)
|
||||||
|
|
||||||
# Prep and submit these sub-jobs
|
# Prep and submit these sub-jobs
|
||||||
logger.info(f"Job {parent_worker.id} split plan: {all_subjob_server_data}")
|
logger.info(f"Job {parent_worker.id} split plan: {all_subjob_server_data}")
|
||||||
try:
|
try:
|
||||||
for subjob_data in all_subjob_server_data:
|
for subjob_data in all_subjob_server_data:
|
||||||
subjob_hostname = subjob_data['hostname']
|
subjob_hostname = subjob_data['hostname']
|
||||||
if subjob_hostname != parent_worker.hostname:
|
post_results = cls.__create_subjob(new_job_attributes, project_path, subjob_data, subjob_hostname,
|
||||||
post_results = cls.__create_subjob(job_data, project_path, subjob_data, subjob_hostname,
|
parent_worker)
|
||||||
parent_worker)
|
if not post_results.ok:
|
||||||
if not post_results.ok:
|
ValueError(f"Failed to create subjob on {subjob_hostname}")
|
||||||
ValueError(f"Failed to create subjob on {subjob_hostname}")
|
|
||||||
|
|
||||||
# save child info
|
# save child info
|
||||||
submission_results = post_results.json()[0]
|
submission_results = post_results.json()[0]
|
||||||
child_key = f"{submission_results['id']}@{subjob_hostname}"
|
child_key = f"{submission_results['id']}@{subjob_hostname}"
|
||||||
parent_worker.children[child_key] = submission_results
|
parent_worker.children[child_key] = submission_results
|
||||||
else:
|
|
||||||
# truncate parent render_job
|
|
||||||
parent_worker.start_frame = max(subjob_data['frame_range'][0], parent_worker.start_frame)
|
|
||||||
parent_worker.end_frame = min(subjob_data['frame_range'][-1], parent_worker.end_frame)
|
|
||||||
logger.info(f"Local job now rendering from {parent_worker.start_frame} to {parent_worker.end_frame}")
|
|
||||||
|
|
||||||
# start subjobs
|
# start subjobs
|
||||||
logger.debug(f"Created {len(all_subjob_server_data) - 1} subjobs successfully")
|
logger.debug(f"Created {len(all_subjob_server_data)} subjobs successfully")
|
||||||
parent_worker.name = f"{parent_worker.name}[{parent_worker.start_frame}-{parent_worker.end_frame}]"
|
parent_worker.name = f"{parent_worker.name} (Parent)"
|
||||||
parent_worker.status = RenderStatus.NOT_STARTED # todo: this won't work with scheduled starts
|
parent_worker.status = RenderStatus.NOT_STARTED # todo: this won't work with scheduled starts
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# cancel all the subjobs
|
# cancel all the subjobs
|
||||||
@@ -349,8 +347,9 @@ class DistributedJobManager:
|
|||||||
RenderServerProxy(parent_worker.hostname).cancel_job(parent_worker.id, confirm=True)
|
RenderServerProxy(parent_worker.hostname).cancel_job(parent_worker.id, confirm=True)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __create_subjob(job_data, project_path, server_data, server_hostname, parent_worker):
|
def __create_subjob(new_job_attributes, project_path, server_data, server_hostname, parent_worker):
|
||||||
subjob = job_data.copy()
|
"""Convenience method to create subjobs for a parent worker"""
|
||||||
|
subjob = new_job_attributes.copy()
|
||||||
subjob['name'] = f"{parent_worker.name}[{server_data['frame_range'][0]}-{server_data['frame_range'][-1]}]"
|
subjob['name'] = f"{parent_worker.name}[{server_data['frame_range'][0]}-{server_data['frame_range'][-1]}]"
|
||||||
subjob['parent'] = f"{parent_worker.id}@{parent_worker.hostname}"
|
subjob['parent'] = f"{parent_worker.id}@{parent_worker.hostname}"
|
||||||
subjob['start_frame'] = server_data['frame_range'][0]
|
subjob['start_frame'] = server_data['frame_range'][0]
|
||||||
@@ -366,126 +365,6 @@ class DistributedJobManager:
|
|||||||
# Server Handling
|
# Server Handling
|
||||||
# --------------------------------------------
|
# --------------------------------------------
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def distribute_server_work(start_frame, end_frame, available_servers, method='cpu_benchmark'):
|
|
||||||
"""
|
|
||||||
Splits the frame range among available servers proportionally based on their performance (CPU count).
|
|
||||||
|
|
||||||
Args:
|
|
||||||
start_frame (int): The start frame number of the animation to be rendered.
|
|
||||||
end_frame (int): The end frame number of the animation to be rendered.
|
|
||||||
available_servers (list): A list of available server dictionaries. Each server dictionary should include
|
|
||||||
'hostname' and 'cpu_count' keys (see find_available_servers).
|
|
||||||
method (str, optional): Specifies the distribution method. Possible values are 'cpu_benchmark', 'cpu_count'
|
|
||||||
and 'evenly'.
|
|
||||||
Defaults to 'cpu_benchmark'.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
list: A list of server dictionaries where each dictionary includes the frame range and total number of
|
|
||||||
frames to be rendered by the server.
|
|
||||||
"""
|
|
||||||
# Calculate respective frames for each server
|
|
||||||
def divide_frames_by_cpu_count(frame_start, frame_end, servers):
|
|
||||||
total_frames = frame_end - frame_start + 1
|
|
||||||
total_cpus = sum(server['cpu_count'] for server in servers)
|
|
||||||
|
|
||||||
frame_ranges = {}
|
|
||||||
current_frame = frame_start
|
|
||||||
allocated_frames = 0
|
|
||||||
|
|
||||||
for i, server in enumerate(servers):
|
|
||||||
if i == len(servers) - 1: # if it's the last server
|
|
||||||
# Give all remaining frames to the last server
|
|
||||||
num_frames = total_frames - allocated_frames
|
|
||||||
else:
|
|
||||||
num_frames = round((server['cpu_count'] / total_cpus) * total_frames)
|
|
||||||
allocated_frames += num_frames
|
|
||||||
|
|
||||||
frame_end_for_server = current_frame + num_frames - 1
|
|
||||||
|
|
||||||
if current_frame <= frame_end_for_server:
|
|
||||||
frame_ranges[server['hostname']] = (current_frame, frame_end_for_server)
|
|
||||||
current_frame = frame_end_for_server + 1
|
|
||||||
|
|
||||||
return frame_ranges
|
|
||||||
|
|
||||||
def divide_frames_by_benchmark(frame_start, frame_end, servers):
|
|
||||||
|
|
||||||
def fetch_benchmark(server):
|
|
||||||
try:
|
|
||||||
benchmark = requests.get(f'http://{server["hostname"]}:{ZeroconfServer.server_port}'
|
|
||||||
f'/api/cpu_benchmark').text
|
|
||||||
server['cpu_benchmark'] = benchmark
|
|
||||||
logger.debug(f'Benchmark for {server["hostname"]}: {benchmark}')
|
|
||||||
except requests.exceptions.RequestException as e:
|
|
||||||
logger.error(f'Error fetching benchmark for {server["hostname"]}: {e}')
|
|
||||||
|
|
||||||
# Number of threads to use (can adjust based on your needs or number of servers)
|
|
||||||
threads = len(servers)
|
|
||||||
|
|
||||||
with ThreadPoolExecutor(max_workers=threads) as executor:
|
|
||||||
executor.map(fetch_benchmark, servers)
|
|
||||||
|
|
||||||
total_frames = frame_end - frame_start + 1
|
|
||||||
total_performance = sum(int(server['cpu_benchmark']) for server in servers)
|
|
||||||
|
|
||||||
frame_ranges = {}
|
|
||||||
current_frame = frame_start
|
|
||||||
allocated_frames = 0
|
|
||||||
|
|
||||||
for i, server in enumerate(servers):
|
|
||||||
if i == len(servers) - 1: # if it's the last server
|
|
||||||
# Give all remaining frames to the last server
|
|
||||||
num_frames = total_frames - allocated_frames
|
|
||||||
else:
|
|
||||||
num_frames = round((int(server['cpu_benchmark']) / total_performance) * total_frames)
|
|
||||||
allocated_frames += num_frames
|
|
||||||
|
|
||||||
frame_end_for_server = current_frame + num_frames - 1
|
|
||||||
|
|
||||||
if current_frame <= frame_end_for_server:
|
|
||||||
frame_ranges[server['hostname']] = (current_frame, frame_end_for_server)
|
|
||||||
current_frame = frame_end_for_server + 1
|
|
||||||
|
|
||||||
return frame_ranges
|
|
||||||
|
|
||||||
def divide_frames_equally(frame_start, frame_end, servers):
|
|
||||||
frame_range = frame_end - frame_start + 1
|
|
||||||
frames_per_server = frame_range // len(servers)
|
|
||||||
leftover_frames = frame_range % len(servers)
|
|
||||||
|
|
||||||
frame_ranges = {}
|
|
||||||
current_start = frame_start
|
|
||||||
for i, server in enumerate(servers):
|
|
||||||
current_end = current_start + frames_per_server - 1
|
|
||||||
if leftover_frames > 0:
|
|
||||||
current_end += 1
|
|
||||||
leftover_frames -= 1
|
|
||||||
if current_start <= current_end:
|
|
||||||
frame_ranges[server['hostname']] = (current_start, current_end)
|
|
||||||
current_start = current_end + 1
|
|
||||||
|
|
||||||
return frame_ranges
|
|
||||||
|
|
||||||
if len(available_servers) == 1:
|
|
||||||
breakdown = {available_servers[0]['hostname']: (start_frame, end_frame)}
|
|
||||||
else:
|
|
||||||
logger.debug(f'Splitting between {len(available_servers)} servers by {method} method')
|
|
||||||
if method == 'evenly':
|
|
||||||
breakdown = divide_frames_equally(start_frame, end_frame, available_servers)
|
|
||||||
elif method == 'cpu_benchmark':
|
|
||||||
breakdown = divide_frames_by_benchmark(start_frame, end_frame, available_servers)
|
|
||||||
elif method == 'cpu_count':
|
|
||||||
breakdown = divide_frames_by_cpu_count(start_frame, end_frame, available_servers)
|
|
||||||
else:
|
|
||||||
raise ValueError(f"Invalid distribution method: {method}")
|
|
||||||
|
|
||||||
server_breakdown = [server for server in available_servers if breakdown.get(server['hostname']) is not None]
|
|
||||||
for server in server_breakdown:
|
|
||||||
server['frame_range'] = breakdown[server['hostname']]
|
|
||||||
server['total_frames'] = breakdown[server['hostname']][-1] - breakdown[server['hostname']][0] + 1
|
|
||||||
return server_breakdown
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def find_available_servers(engine_name, system_os=None):
|
def find_available_servers(engine_name, system_os=None):
|
||||||
"""
|
"""
|
||||||
@@ -495,13 +374,15 @@ class DistributedJobManager:
|
|||||||
:param system_os: str, Restrict results to servers running a specific OS
|
:param system_os: str, Restrict results to servers running a specific OS
|
||||||
:return: A list of dictionaries with each dict containing hostname and cpu_count of available servers
|
:return: A list of dictionaries with each dict containing hostname and cpu_count of available servers
|
||||||
"""
|
"""
|
||||||
|
from api.api_server import API_VERSION
|
||||||
available_servers = []
|
available_servers = []
|
||||||
for hostname in ZeroconfServer.found_hostnames():
|
for hostname in ZeroconfServer.found_hostnames():
|
||||||
host_properties = ZeroconfServer.get_hostname_properties(hostname)
|
host_properties = ZeroconfServer.get_hostname_properties(hostname)
|
||||||
if not system_os or (system_os and system_os == host_properties.get('system_os')):
|
if host_properties.get('api_version') == API_VERSION:
|
||||||
response = RenderServerProxy(hostname).is_engine_available(engine_name)
|
if not system_os or (system_os and system_os == host_properties.get('system_os')):
|
||||||
if response and response.get('available', False):
|
response = RenderServerProxy(hostname).is_engine_available(engine_name)
|
||||||
available_servers.append(response)
|
if response and response.get('available', False):
|
||||||
|
available_servers.append(response)
|
||||||
|
|
||||||
return available_servers
|
return available_servers
|
||||||
|
|
||||||
@@ -515,6 +396,6 @@ if __name__ == '__main__':
|
|||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
available_servers = DistributedJobManager.find_available_servers('blender')
|
available_servers = DistributedJobManager.find_available_servers('blender')
|
||||||
print(f"AVAILABLE SERVERS ({len(available_servers)}): {available_servers}")
|
print(f"AVAILABLE SERVERS ({len(available_servers)}): {available_servers}")
|
||||||
# results = DistributedJobManager.distribute_server_work(1, 100, available_servers)
|
# results = distribute_server_work(1, 100, available_servers)
|
||||||
# print(f"RESULTS: {results}")
|
# print(f"RESULTS: {results}")
|
||||||
ZeroconfServer.stop()
|
ZeroconfServer.stop()
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ from src.utilities.misc_helper import system_safe_path
|
|||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
_creationflags = subprocess.CREATE_NO_WINDOW if platform.system() == 'Windows' else 0
|
||||||
|
|
||||||
|
|
||||||
class Blender(BaseRenderEngine):
|
class Blender(BaseRenderEngine):
|
||||||
|
|
||||||
@@ -22,12 +24,12 @@ class Blender(BaseRenderEngine):
|
|||||||
from src.engines.blender.blender_worker import BlenderRenderWorker
|
from src.engines.blender.blender_worker import BlenderRenderWorker
|
||||||
return BlenderRenderWorker
|
return BlenderRenderWorker
|
||||||
|
|
||||||
def ui_options(self):
|
|
||||||
from src.engines.blender.blender_ui import BlenderUI
|
|
||||||
return BlenderUI.get_options(self)
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def supported_extensions():
|
def ui_options(system_info):
|
||||||
|
from src.engines.blender.blender_ui import BlenderUI
|
||||||
|
return BlenderUI.get_options(system_info)
|
||||||
|
|
||||||
|
def supported_extensions(self):
|
||||||
return ['blend']
|
return ['blend']
|
||||||
|
|
||||||
def version(self):
|
def version(self):
|
||||||
@@ -35,7 +37,8 @@ class Blender(BaseRenderEngine):
|
|||||||
try:
|
try:
|
||||||
render_path = self.renderer_path()
|
render_path = self.renderer_path()
|
||||||
if render_path:
|
if render_path:
|
||||||
ver_out = subprocess.check_output([render_path, '-v'], timeout=SUBPROCESS_TIMEOUT)
|
ver_out = subprocess.check_output([render_path, '-v'], timeout=SUBPROCESS_TIMEOUT,
|
||||||
|
creationflags=_creationflags)
|
||||||
version = ver_out.decode('utf-8').splitlines()[0].replace('Blender', '').strip()
|
version = ver_out.decode('utf-8').splitlines()[0].replace('Blender', '').strip()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f'Failed to get Blender version: {e}')
|
logger.error(f'Failed to get Blender version: {e}')
|
||||||
@@ -50,9 +53,11 @@ class Blender(BaseRenderEngine):
|
|||||||
if os.path.exists(project_path):
|
if os.path.exists(project_path):
|
||||||
try:
|
try:
|
||||||
return subprocess.run([self.renderer_path(), '-b', project_path, '--python-expr', python_expression],
|
return subprocess.run([self.renderer_path(), '-b', project_path, '--python-expr', python_expression],
|
||||||
capture_output=True, timeout=timeout)
|
capture_output=True, timeout=timeout, creationflags=_creationflags)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error running python expression in blender: {e}")
|
err_msg = f"Error running python expression in blender: {e}"
|
||||||
|
logger.error(err_msg)
|
||||||
|
raise ChildProcessError(err_msg)
|
||||||
else:
|
else:
|
||||||
raise FileNotFoundError(f'Project file not found: {project_path}')
|
raise FileNotFoundError(f'Project file not found: {project_path}')
|
||||||
|
|
||||||
@@ -67,9 +72,16 @@ class Blender(BaseRenderEngine):
|
|||||||
command = [self.renderer_path(), '-b', '--python', script_path]
|
command = [self.renderer_path(), '-b', '--python', script_path]
|
||||||
if project_path:
|
if project_path:
|
||||||
command.insert(2, project_path)
|
command.insert(2, project_path)
|
||||||
return subprocess.run(command, capture_output=True, timeout=timeout)
|
result = subprocess.run(command, capture_output=True, timeout=timeout, creationflags=_creationflags)
|
||||||
|
return result
|
||||||
|
except subprocess.TimeoutExpired:
|
||||||
|
err_msg = f"Timed out after {timeout}s while running python script in blender: {script_path}"
|
||||||
|
logger.error(err_msg)
|
||||||
|
raise TimeoutError(err_msg)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.exception(f"Error running python script in blender: {e}")
|
err_msg = f"Error running python script in blender: {e}"
|
||||||
|
logger.error(err_msg)
|
||||||
|
raise ChildProcessError(err_msg)
|
||||||
|
|
||||||
def get_project_info(self, project_path, timeout=10):
|
def get_project_info(self, project_path, timeout=10):
|
||||||
scene_info = {}
|
scene_info = {}
|
||||||
@@ -86,10 +98,12 @@ class Blender(BaseRenderEngine):
|
|||||||
elif line.startswith('Error'):
|
elif line.startswith('Error'):
|
||||||
logger.error(f"get_scene_info error: {line.strip()}")
|
logger.error(f"get_scene_info error: {line.strip()}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f'Error getting file details for .blend file: {e}')
|
msg = f'Error getting file details for .blend file: {e}'
|
||||||
|
logger.error(msg)
|
||||||
|
raise ChildProcessError(msg)
|
||||||
return scene_info
|
return scene_info
|
||||||
|
|
||||||
def pack_project_file(self, project_path, timeout=30):
|
def pack_project_file(self, project_path, timeout=None):
|
||||||
# Credit to L0Lock for pack script - https://blender.stackexchange.com/a/243935
|
# Credit to L0Lock for pack script - https://blender.stackexchange.com/a/243935
|
||||||
try:
|
try:
|
||||||
logger.info(f"Starting to pack Blender file: {project_path}")
|
logger.info(f"Starting to pack Blender file: {project_path}")
|
||||||
@@ -112,11 +126,13 @@ class Blender(BaseRenderEngine):
|
|||||||
logger.info(f'Blender file packed successfully to {new_path}')
|
logger.info(f'Blender file packed successfully to {new_path}')
|
||||||
return new_path
|
return new_path
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f'Error packing .blend file: {e}')
|
msg = f'Error packing .blend file: {e}'
|
||||||
|
logger.error(msg)
|
||||||
|
raise ChildProcessError(msg)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_arguments(self):
|
def get_arguments(self):
|
||||||
help_text = subprocess.check_output([self.renderer_path(), '-h']).decode('utf-8')
|
help_text = subprocess.check_output([self.renderer_path(), '-h'], creationflags=_creationflags).decode('utf-8')
|
||||||
lines = help_text.splitlines()
|
lines = help_text.splitlines()
|
||||||
|
|
||||||
options = {}
|
options = {}
|
||||||
@@ -164,12 +180,12 @@ class Blender(BaseRenderEngine):
|
|||||||
|
|
||||||
def supported_render_engines(self):
|
def supported_render_engines(self):
|
||||||
engine_output = subprocess.run([self.renderer_path(), '-E', 'help'], timeout=SUBPROCESS_TIMEOUT,
|
engine_output = subprocess.run([self.renderer_path(), '-E', 'help'], timeout=SUBPROCESS_TIMEOUT,
|
||||||
capture_output=True).stdout.decode('utf-8').strip()
|
capture_output=True, creationflags=_creationflags).stdout.decode('utf-8').strip()
|
||||||
render_engines = [x.strip() for x in engine_output.split('Blender Engine Listing:')[-1].strip().splitlines()]
|
render_engines = [x.strip() for x in engine_output.split('Blender Engine Listing:')[-1].strip().splitlines()]
|
||||||
return render_engines
|
return render_engines
|
||||||
|
|
||||||
def perform_presubmission_tasks(self, project_path):
|
def perform_presubmission_tasks(self, project_path):
|
||||||
packed_path = self.pack_project_file(project_path, timeout=30)
|
packed_path = self.pack_project_file(project_path, timeout=120)
|
||||||
return packed_path
|
return packed_path
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
|
|
||||||
class BlenderUI:
|
class BlenderUI:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_options(instance):
|
def get_options(system_info):
|
||||||
options = [
|
options = [
|
||||||
{'name': 'engine', 'options': instance.supported_render_engines()},
|
{'name': 'engine', 'options': system_info.get('engines', [])},
|
||||||
{'name': 'render_device', 'options': ['Any', 'GPU', 'CPU']},
|
{'name': 'render_device', 'options': ['Any', 'GPU', 'CPU']},
|
||||||
]
|
]
|
||||||
return options
|
return options
|
||||||
|
|||||||
@@ -31,6 +31,12 @@ class BlenderRenderWorker(BaseRenderWorker):
|
|||||||
cmd.append('-b')
|
cmd.append('-b')
|
||||||
cmd.append(self.input_path)
|
cmd.append(self.input_path)
|
||||||
|
|
||||||
|
# Set Render Engine
|
||||||
|
blender_engine = self.args.get('engine')
|
||||||
|
if blender_engine:
|
||||||
|
blender_engine = blender_engine.upper()
|
||||||
|
cmd.extend(['-E', blender_engine])
|
||||||
|
|
||||||
# Start Python expressions - # todo: investigate splitting into separate 'setup' script
|
# Start Python expressions - # todo: investigate splitting into separate 'setup' script
|
||||||
cmd.append('--python-expr')
|
cmd.append('--python-expr')
|
||||||
python_exp = 'import bpy; bpy.context.scene.render.use_overwrite = False;'
|
python_exp = 'import bpy; bpy.context.scene.render.use_overwrite = False;'
|
||||||
@@ -40,8 +46,7 @@ class BlenderRenderWorker(BaseRenderWorker):
|
|||||||
if custom_camera:
|
if custom_camera:
|
||||||
python_exp = python_exp + f"bpy.context.scene.camera = bpy.data.objects['{custom_camera}'];"
|
python_exp = python_exp + f"bpy.context.scene.camera = bpy.data.objects['{custom_camera}'];"
|
||||||
|
|
||||||
# Set Render Device (gpu/cpu/any)
|
# Set Render Device for Cycles (gpu/cpu/any)
|
||||||
blender_engine = self.args.get('engine', 'BLENDER_EEVEE').upper()
|
|
||||||
if blender_engine == 'CYCLES':
|
if blender_engine == 'CYCLES':
|
||||||
render_device = self.args.get('render_device', 'any').lower()
|
render_device = self.args.get('render_device', 'any').lower()
|
||||||
if render_device not in {'any', 'gpu', 'cpu'}:
|
if render_device not in {'any', 'gpu', 'cpu'}:
|
||||||
@@ -62,8 +67,11 @@ class BlenderRenderWorker(BaseRenderWorker):
|
|||||||
# Export format
|
# Export format
|
||||||
export_format = self.args.get('export_format', None) or 'JPEG'
|
export_format = self.args.get('export_format', None) or 'JPEG'
|
||||||
|
|
||||||
path_without_ext = os.path.splitext(self.output_path)[0] + "_"
|
main_part, ext = os.path.splitext(self.output_path)
|
||||||
cmd.extend(['-E', blender_engine, '-o', path_without_ext, '-F', export_format])
|
# Remove the extension only if it is not composed entirely of digits
|
||||||
|
path_without_ext = main_part if not ext[1:].isdigit() else self.output_path
|
||||||
|
path_without_ext += "_"
|
||||||
|
cmd.extend(['-o', path_without_ext, '-F', export_format])
|
||||||
|
|
||||||
# set frame range
|
# set frame range
|
||||||
cmd.extend(['-s', self.start_frame, '-e', self.end_frame, '-a'])
|
cmd.extend(['-s', self.start_frame, '-e', self.end_frame, '-a'])
|
||||||
@@ -107,6 +115,7 @@ class BlenderRenderWorker(BaseRenderWorker):
|
|||||||
output_file_number = output_filename_match.groups()[0]
|
output_file_number = output_filename_match.groups()[0]
|
||||||
try:
|
try:
|
||||||
self.current_frame = int(output_file_number)
|
self.current_frame = int(output_file_number)
|
||||||
|
self._send_frame_complete_notification()
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
elif render_stats_match:
|
elif render_stats_match:
|
||||||
@@ -115,15 +124,15 @@ class BlenderRenderWorker(BaseRenderWorker):
|
|||||||
logger.info(f'Frame #{self.current_frame} - '
|
logger.info(f'Frame #{self.current_frame} - '
|
||||||
f'{frame_count} of {self.total_frames} completed in {time_completed} | '
|
f'{frame_count} of {self.total_frames} completed in {time_completed} | '
|
||||||
f'Total Elapsed Time: {datetime.now() - self.start_time}')
|
f'Total Elapsed Time: {datetime.now() - self.start_time}')
|
||||||
else:
|
|
||||||
logger.debug(f'DEBUG: {line}')
|
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
# if len(line.strip()):
|
# if len(line.strip()):
|
||||||
# logger.debug(line.strip())
|
# logger.debug(line.strip())
|
||||||
|
|
||||||
def percent_complete(self):
|
def percent_complete(self):
|
||||||
if self.total_frames <= 1:
|
if self.status == RenderStatus.COMPLETED:
|
||||||
|
return 1
|
||||||
|
elif self.total_frames <= 1:
|
||||||
return self.__frame_percent_complete
|
return self.__frame_percent_complete
|
||||||
else:
|
else:
|
||||||
whole_frame_percent = (self.current_frame - self.start_frame) / self.total_frames
|
whole_frame_percent = (self.current_frame - self.start_frame) / self.total_frames
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import tarfile
|
|
||||||
import tempfile
|
import tempfile
|
||||||
import zipfile
|
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
@@ -12,26 +10,150 @@ logger = logging.getLogger()
|
|||||||
|
|
||||||
|
|
||||||
class EngineDownloader:
|
class EngineDownloader:
|
||||||
|
"""A class responsible for downloading and extracting rendering engines from publicly available URLs.
|
||||||
|
|
||||||
|
Attributes:
|
||||||
|
supported_formats (list[str]): A list of file formats supported by the downloader.
|
||||||
|
"""
|
||||||
|
|
||||||
supported_formats = ['.zip', '.tar.xz', '.dmg']
|
supported_formats = ['.zip', '.tar.xz', '.dmg']
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# --------------------------------------------
|
||||||
|
# Required Overrides for Subclasses:
|
||||||
|
# --------------------------------------------
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def find_most_recent_version(cls, system_os=None, cpu=None, lts_only=False):
|
def find_most_recent_version(cls, system_os=None, cpu=None, lts_only=False):
|
||||||
raise NotImplementedError # implement this method in your engine subclass
|
"""
|
||||||
|
Finds the most recent version of the rendering engine available for download.
|
||||||
|
|
||||||
|
This method should be overridden in a subclass to implement the logic for determining
|
||||||
|
the most recent version of the rendering engine, optionally filtering by long-term
|
||||||
|
support (LTS) versions, the operating system, and CPU architecture.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
system_os (str, optional): Desired OS ('linux', 'macos', 'windows'). Defaults to system os.
|
||||||
|
cpu (str, optional): The CPU architecture for which to download the engine. Default is system cpu.
|
||||||
|
lts_only (bool, optional): Limit the search to LTS (long-term support) versions only. Default is False.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
dict: A dict with the following keys:
|
||||||
|
- 'cpu' (str): The CPU architecture.
|
||||||
|
- 'system_os' (str): The operating system.
|
||||||
|
- 'file' (str): The filename of the version's download file.
|
||||||
|
- 'url' (str): The remote URL for downloading the version.
|
||||||
|
- 'version' (str): The version number.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
NotImplementedError: If the method is not overridden in a subclass.
|
||||||
|
"""
|
||||||
|
raise NotImplementedError(f"find_most_recent_version not implemented for {cls.__class__.__name__}")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def version_is_available_to_download(cls, version, system_os=None, cpu=None):
|
def version_is_available_to_download(cls, version, system_os=None, cpu=None):
|
||||||
raise NotImplementedError # implement this method in your engine subclass
|
"""Checks if a requested version of the rendering engine is available for download.
|
||||||
|
|
||||||
|
This method should be overridden in a subclass to implement the logic for determining
|
||||||
|
whether a given version of the rendering engine is available for download, based on the
|
||||||
|
operating system and CPU architecture.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
version (str): The requested renderer version to download.
|
||||||
|
system_os (str, optional): Desired OS ('linux', 'macos', 'windows'). Defaults to system os.
|
||||||
|
cpu (str, optional): The CPU architecture for which to download the engine. Default is system cpu.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
bool: True if the version is available for download, False otherwise.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
NotImplementedError: If the method is not overridden in a subclass.
|
||||||
|
"""
|
||||||
|
raise NotImplementedError(f"version_is_available_to_download not implemented for {cls.__class__.__name__}")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def download_engine(cls, version, download_location, system_os=None, cpu=None, timeout=120):
|
def download_engine(cls, version, download_location, system_os=None, cpu=None, timeout=120):
|
||||||
raise NotImplementedError # implement this method in your engine subclass
|
"""Downloads the requested version of the rendering engine to the given download location.
|
||||||
|
|
||||||
|
This method should be overridden in a subclass to implement the logic for downloading
|
||||||
|
a specific version of the rendering engine. The method is intended to handle the
|
||||||
|
downloading process based on the version, operating system, CPU architecture, and
|
||||||
|
timeout parameters.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
version (str): The requested renderer version to download.
|
||||||
|
download_location (str): The directory where the engine should be downloaded.
|
||||||
|
system_os (str, optional): Desired OS ('linux', 'macos', 'windows'). Defaults to system os.
|
||||||
|
cpu (str, optional): The CPU architecture for which to download the engine. Default is system cpu.
|
||||||
|
timeout (int, optional): The maximum time in seconds to wait for the download. Default is 120 seconds.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
NotImplementedError: If the method is not overridden in a subclass.
|
||||||
|
"""
|
||||||
|
raise NotImplementedError(f"download_engine not implemented for {cls.__class__.__name__}")
|
||||||
|
|
||||||
|
# --------------------------------------------
|
||||||
|
# Optional Overrides for Subclasses:
|
||||||
|
# --------------------------------------------
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def all_versions(cls, system_os=None, cpu=None):
|
||||||
|
"""Retrieves a list of available versions of the software for a specific operating system and CPU architecture.
|
||||||
|
|
||||||
|
This method fetches all available versions for the given operating system and CPU type, constructing
|
||||||
|
a list of dictionaries containing details such as the version, CPU architecture, system OS, and the
|
||||||
|
remote URL for downloading each version.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
system_os (str, optional): Desired OS ('linux', 'macos', 'windows'). Defaults to system os.
|
||||||
|
cpu (str, optional): The CPU architecture for which to download the engine. Default is system cpu.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
list[dict]: A list of dictionaries, each containing:
|
||||||
|
- 'cpu' (str): The CPU architecture.
|
||||||
|
- 'file' (str): The filename of the version's download file.
|
||||||
|
- 'system_os' (str): The operating system.
|
||||||
|
- 'url' (str): The remote URL for downloading the version.
|
||||||
|
- 'version' (str): The version number.
|
||||||
|
"""
|
||||||
|
return []
|
||||||
|
|
||||||
|
# --------------------------------------------
|
||||||
|
# Do Not Override These Methods:
|
||||||
|
# --------------------------------------------
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def download_and_extract_app(cls, remote_url, download_location, timeout=120):
|
def download_and_extract_app(cls, remote_url, download_location, timeout=120):
|
||||||
|
"""Downloads an application from the given remote URL and extracts it to the specified location.
|
||||||
|
|
||||||
|
This method handles the downloading of the application, supports multiple archive formats,
|
||||||
|
and extracts the contents to the specified `download_location`. It also manages temporary
|
||||||
|
files and logs progress throughout the process.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
remote_url (str): The URL of the application to download.
|
||||||
|
download_location (str): The directory where the application should be extracted.
|
||||||
|
timeout (int, optional): The maximum time in seconds to wait for the download. Default is 120 seconds.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: The path to the directory where the application was extracted.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
Exception: Catches and logs any exceptions that occur during the download or extraction process.
|
||||||
|
|
||||||
|
Supported Formats:
|
||||||
|
- `.tar.xz`: Extracted using the `tarfile` module.
|
||||||
|
- `.zip`: Extracted using the `zipfile` module.
|
||||||
|
- `.dmg`: macOS disk image files, handled using the `dmglib` library.
|
||||||
|
- Other formats will result in an error being logged.
|
||||||
|
|
||||||
|
Notes:
|
||||||
|
- If the application already exists in the `download_location`, the method will log an error
|
||||||
|
and return without downloading or extracting.
|
||||||
|
- Temporary files created during the download process are cleaned up after completion.
|
||||||
|
"""
|
||||||
|
|
||||||
# Create a temp download directory
|
# Create a temp download directory
|
||||||
temp_download_dir = tempfile.mkdtemp()
|
temp_download_dir = tempfile.mkdtemp()
|
||||||
@@ -80,6 +202,7 @@ class EngineDownloader:
|
|||||||
# Extract the downloaded file
|
# Extract the downloaded file
|
||||||
# Process .tar.xz files
|
# Process .tar.xz files
|
||||||
if temp_downloaded_file_path.lower().endswith('.tar.xz'):
|
if temp_downloaded_file_path.lower().endswith('.tar.xz'):
|
||||||
|
import tarfile
|
||||||
try:
|
try:
|
||||||
with tarfile.open(temp_downloaded_file_path, 'r:xz') as tar:
|
with tarfile.open(temp_downloaded_file_path, 'r:xz') as tar:
|
||||||
tar.extractall(path=download_location)
|
tar.extractall(path=download_location)
|
||||||
@@ -93,6 +216,7 @@ class EngineDownloader:
|
|||||||
|
|
||||||
# Process .zip files
|
# Process .zip files
|
||||||
elif temp_downloaded_file_path.lower().endswith('.zip'):
|
elif temp_downloaded_file_path.lower().endswith('.zip'):
|
||||||
|
import zipfile
|
||||||
try:
|
try:
|
||||||
with zipfile.ZipFile(temp_downloaded_file_path, 'r') as zip_ref:
|
with zipfile.ZipFile(temp_downloaded_file_path, 'r') as zip_ref:
|
||||||
zip_ref.extractall(download_location)
|
zip_ref.extractall(download_location)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import platform
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
@@ -7,19 +8,139 @@ SUBPROCESS_TIMEOUT = 5
|
|||||||
|
|
||||||
|
|
||||||
class BaseRenderEngine(object):
|
class BaseRenderEngine(object):
|
||||||
|
"""Base class for render engines. This class provides common functionality and structure for various rendering
|
||||||
|
engines. Create subclasses and override the methods marked below to add additional renderers
|
||||||
|
|
||||||
|
Attributes:
|
||||||
|
install_paths (list): A list of default installation paths where the render engine
|
||||||
|
might be found. This list can be populated with common paths to help locate the
|
||||||
|
executable on different operating systems or environments.
|
||||||
|
"""
|
||||||
|
|
||||||
install_paths = []
|
install_paths = []
|
||||||
supported_extensions = []
|
|
||||||
|
# --------------------------------------------
|
||||||
|
# Required Overrides for Subclasses:
|
||||||
|
# --------------------------------------------
|
||||||
|
|
||||||
def __init__(self, custom_path=None):
|
def __init__(self, custom_path=None):
|
||||||
self.custom_renderer_path = custom_path
|
self.custom_renderer_path = custom_path
|
||||||
if not self.renderer_path() or not os.path.exists(self.renderer_path()):
|
if not self.renderer_path() or not os.path.exists(self.renderer_path()):
|
||||||
raise FileNotFoundError(f"Cannot find path to renderer for {self.name()} instance")
|
raise FileNotFoundError(f"Cannot find path to renderer for {self.name()} instance: {self.renderer_path()}")
|
||||||
|
|
||||||
if not os.access(self.renderer_path(), os.X_OK):
|
if not os.access(self.renderer_path(), os.X_OK):
|
||||||
logger.warning(f"Path is not executable. Setting permissions to 755 for {self.renderer_path()}")
|
logger.warning(f"Path is not executable. Setting permissions to 755 for {self.renderer_path()}")
|
||||||
os.chmod(self.renderer_path(), 0o755)
|
os.chmod(self.renderer_path(), 0o755)
|
||||||
|
|
||||||
|
def version(self):
|
||||||
|
"""Return the version number as a string.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: Version number.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
NotImplementedError: If not overridden.
|
||||||
|
"""
|
||||||
|
raise NotImplementedError(f"version not implemented for {self.__class__.__name__}")
|
||||||
|
|
||||||
|
def get_project_info(self, project_path, timeout=10):
|
||||||
|
"""Extracts detailed project information from the given project path.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
project_path (str): The path to the project file.
|
||||||
|
timeout (int, optional): The maximum time (in seconds) to wait for the operation. Default is 10 seconds.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
dict: A dictionary containing project information (subclasses should define the structure).
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
NotImplementedError: If the method is not overridden in a subclass.
|
||||||
|
"""
|
||||||
|
raise NotImplementedError(f"get_project_info not implemented for {self.__class__.__name__}")
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_output_formats(cls):
|
||||||
|
"""Returns a list of available output formats supported by the renderer.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
list[str]: A list of strings representing the available output formats.
|
||||||
|
"""
|
||||||
|
raise NotImplementedError(f"get_output_formats not implemented for {cls.__name__}")
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def worker_class(): # override when subclassing to link worker class
|
||||||
|
raise NotImplementedError("Worker class not implemented")
|
||||||
|
|
||||||
|
# --------------------------------------------
|
||||||
|
# Optional Overrides for Subclasses:
|
||||||
|
# --------------------------------------------
|
||||||
|
|
||||||
|
def supported_extensions(self):
|
||||||
|
"""
|
||||||
|
Returns:
|
||||||
|
list[str]: list of supported extensions
|
||||||
|
"""
|
||||||
|
return []
|
||||||
|
|
||||||
|
def get_help(self):
|
||||||
|
"""Retrieves the help documentation for the renderer.
|
||||||
|
|
||||||
|
This method runs the renderer's help command (default: '-h') and captures the output.
|
||||||
|
Override this method if the renderer uses a different help flag.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: The help documentation as a string.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
FileNotFoundError: If the renderer path is not found.
|
||||||
|
"""
|
||||||
|
path = self.renderer_path()
|
||||||
|
if not path:
|
||||||
|
raise FileNotFoundError("renderer path not found")
|
||||||
|
creationflags = subprocess.CREATE_NO_WINDOW if platform.system() == 'Windows' else 0
|
||||||
|
help_doc = subprocess.check_output([path, '-h'], stderr=subprocess.STDOUT,
|
||||||
|
timeout=SUBPROCESS_TIMEOUT, creationflags=creationflags).decode('utf-8')
|
||||||
|
return help_doc
|
||||||
|
|
||||||
|
def system_info(self):
|
||||||
|
"""Return additional information about the system specfic to the engine (configured GPUs, render engines, etc)
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
dict: A dictionary with engine-specific system information
|
||||||
|
"""
|
||||||
|
return {}
|
||||||
|
|
||||||
|
def perform_presubmission_tasks(self, project_path):
|
||||||
|
"""Perform any pre-submission tasks on a project file before uploading it to a server (pack textures, etc.)
|
||||||
|
|
||||||
|
Override this method to:
|
||||||
|
1. Copy the project file to a temporary location (DO NOT MODIFY ORIGINAL PATH).
|
||||||
|
2. Perform additional modifications or tasks.
|
||||||
|
3. Return the path to the modified project file.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
project_path (str): The original project file path.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: The path to the modified project file.
|
||||||
|
"""
|
||||||
|
return project_path
|
||||||
|
|
||||||
|
def get_arguments(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def downloader(): # override when subclassing if using a downloader class
|
||||||
|
return None
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def ui_options(system_info): # override to return options for ui
|
||||||
|
return {}
|
||||||
|
|
||||||
|
# --------------------------------------------
|
||||||
|
# Do Not Override These Methods:
|
||||||
|
# --------------------------------------------
|
||||||
|
|
||||||
def renderer_path(self):
|
def renderer_path(self):
|
||||||
return self.custom_renderer_path or self.default_renderer_path()
|
return self.custom_renderer_path or self.default_renderer_path()
|
||||||
|
|
||||||
@@ -39,41 +160,3 @@ class BaseRenderEngine(object):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.exception(e)
|
logger.exception(e)
|
||||||
return path
|
return path
|
||||||
|
|
||||||
def version(self):
|
|
||||||
raise NotImplementedError("version not implemented")
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def downloader(): # override when subclassing if using a downloader class
|
|
||||||
return None
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def worker_class(): # override when subclassing to link worker class
|
|
||||||
raise NotImplementedError("Worker class not implemented")
|
|
||||||
|
|
||||||
def ui_options(self): # override to return options for ui
|
|
||||||
return {}
|
|
||||||
|
|
||||||
def get_help(self): # override if renderer uses different help flag
|
|
||||||
path = self.renderer_path()
|
|
||||||
if not path:
|
|
||||||
raise FileNotFoundError("renderer path not found")
|
|
||||||
help_doc = subprocess.check_output([path, '-h'], stderr=subprocess.STDOUT,
|
|
||||||
timeout=SUBPROCESS_TIMEOUT).decode('utf-8')
|
|
||||||
return help_doc
|
|
||||||
|
|
||||||
def get_project_info(self, project_path, timeout=10):
|
|
||||||
raise NotImplementedError(f"get_project_info not implemented for {self.__name__}")
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def get_output_formats(cls):
|
|
||||||
raise NotImplementedError(f"get_output_formats not implemented for {cls.__name__}")
|
|
||||||
|
|
||||||
def get_arguments(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def system_info(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def perform_presubmission_tasks(self, project_path):
|
|
||||||
return project_path
|
|
||||||
|
|||||||
@@ -3,8 +3,10 @@ import io
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import signal
|
||||||
import subprocess
|
import subprocess
|
||||||
import threading
|
import threading
|
||||||
|
import time
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
import psutil
|
import psutil
|
||||||
@@ -46,6 +48,10 @@ class BaseRenderWorker(Base):
|
|||||||
|
|
||||||
engine = None
|
engine = None
|
||||||
|
|
||||||
|
# --------------------------------------------
|
||||||
|
# Required Overrides for Subclasses:
|
||||||
|
# --------------------------------------------
|
||||||
|
|
||||||
def __init__(self, input_path, output_path, engine_path, priority=2, args=None, ignore_extensions=True, parent=None,
|
def __init__(self, input_path, output_path, engine_path, priority=2, args=None, ignore_extensions=True, parent=None,
|
||||||
name=None):
|
name=None):
|
||||||
|
|
||||||
@@ -55,7 +61,7 @@ class BaseRenderWorker(Base):
|
|||||||
logger.error(err_meg)
|
logger.error(err_meg)
|
||||||
raise ValueError(err_meg)
|
raise ValueError(err_meg)
|
||||||
if not self.engine:
|
if not self.engine:
|
||||||
raise NotImplementedError("Engine not defined")
|
raise NotImplementedError(f"Engine not defined for {self.__class__.__name__}")
|
||||||
|
|
||||||
def generate_id():
|
def generate_id():
|
||||||
import uuid
|
import uuid
|
||||||
@@ -89,15 +95,64 @@ class BaseRenderWorker(Base):
|
|||||||
self.end_time = None
|
self.end_time = None
|
||||||
|
|
||||||
# History
|
# History
|
||||||
self.status = RenderStatus.NOT_STARTED
|
self.status = RenderStatus.CONFIGURING
|
||||||
self.warnings = []
|
self.warnings = []
|
||||||
self.errors = []
|
self.errors = []
|
||||||
|
|
||||||
# Threads and processes
|
# Threads and processes
|
||||||
self.__thread = threading.Thread(target=self.run, args=())
|
self.__thread = threading.Thread(target=self.__run, args=())
|
||||||
self.__thread.daemon = True
|
self.__thread.daemon = True
|
||||||
self.__process = None
|
self.__process = None
|
||||||
self.last_output = None
|
self.last_output = None
|
||||||
|
self.__last_output_time = None
|
||||||
|
self.watchdog_timeout = 120
|
||||||
|
|
||||||
|
def generate_worker_subprocess(self):
|
||||||
|
"""Generate a return a list of the command line arguments necessary to perform requested job
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
list[str]: list of command line arguments
|
||||||
|
"""
|
||||||
|
raise NotImplementedError("generate_worker_subprocess not implemented")
|
||||||
|
|
||||||
|
def _parse_stdout(self, line):
|
||||||
|
"""Parses a line of standard output from the renderer.
|
||||||
|
|
||||||
|
This method should be overridden in a subclass to implement the logic for processing
|
||||||
|
and interpreting a single line of output from the renderer's standard output stream.
|
||||||
|
|
||||||
|
On frame completion, the subclass should:
|
||||||
|
1. Update value of self.current_frame
|
||||||
|
2. Call self._send_frame_complete_notification()
|
||||||
|
|
||||||
|
Args:
|
||||||
|
line (str): A line of text from the renderer's standard output.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
NotImplementedError: If the method is not overridden in a subclass.
|
||||||
|
"""
|
||||||
|
raise NotImplementedError(f"_parse_stdout not implemented for {self.__class__.__name__}")
|
||||||
|
|
||||||
|
# --------------------------------------------
|
||||||
|
# Optional Overrides for Subclasses:
|
||||||
|
# --------------------------------------------
|
||||||
|
|
||||||
|
def percent_complete(self):
|
||||||
|
# todo: fix this
|
||||||
|
if self.status == RenderStatus.COMPLETED:
|
||||||
|
return 1.0
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def post_processing(self):
|
||||||
|
"""Override to perform any engine-specific postprocessing"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
# --------------------------------------------
|
||||||
|
# Do Not Override These Methods:
|
||||||
|
# --------------------------------------------
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return f"<Job id:{self.id} p{self.priority} {self.renderer}-{self.renderer_version} '{self.name}' status:{self.status.value}>"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def total_frames(self):
|
def total_frames(self):
|
||||||
@@ -121,33 +176,27 @@ class BaseRenderWorker(Base):
|
|||||||
self._status = RenderStatus.CANCELLED.value
|
self._status = RenderStatus.CANCELLED.value
|
||||||
return string_to_status(self._status)
|
return string_to_status(self._status)
|
||||||
|
|
||||||
def validate(self):
|
def _send_frame_complete_notification(self):
|
||||||
if not os.path.exists(self.input_path):
|
pub.sendMessage('frame_complete', job_id=self.id, frame_number=self.current_frame)
|
||||||
raise FileNotFoundError(f"Cannot find input path: {self.input_path}")
|
|
||||||
self.generate_subprocess()
|
|
||||||
|
|
||||||
def generate_subprocess(self):
|
def generate_subprocess(self):
|
||||||
# Convert raw args from string if available and catch conflicts
|
# Convert raw args from string if available and catch conflicts
|
||||||
generated_args = [str(x) for x in self.generate_worker_subprocess()]
|
generated_args = [str(x) for x in self.generate_worker_subprocess()]
|
||||||
generated_args_flags = [x for x in generated_args if x.startswith('-')]
|
generated_args_flags = [x for x in generated_args if x.startswith('-')]
|
||||||
if len(generated_args_flags) != len(set(generated_args_flags)):
|
if len(generated_args_flags) != len(set(generated_args_flags)):
|
||||||
msg = "Cannot generate subprocess - Multiple arg conflicts detected"
|
msg = f"Cannot generate subprocess - Multiple arg conflicts detected: {generated_args}"
|
||||||
logger.error(msg)
|
logger.error(msg)
|
||||||
logger.debug(f"Generated args for subprocess: {generated_args}")
|
|
||||||
raise ValueError(msg)
|
raise ValueError(msg)
|
||||||
return generated_args
|
return generated_args
|
||||||
|
|
||||||
def get_raw_args(self):
|
def get_raw_args(self):
|
||||||
raw_args_string = self.args.get('raw', None)
|
raw_args_string = self.args.get('raw', '')
|
||||||
raw_args = None
|
raw_args = None
|
||||||
if raw_args_string:
|
if raw_args_string:
|
||||||
import shlex
|
import shlex
|
||||||
raw_args = shlex.split(raw_args_string)
|
raw_args = shlex.split(raw_args_string)
|
||||||
return raw_args
|
return raw_args
|
||||||
|
|
||||||
def generate_worker_subprocess(self):
|
|
||||||
raise NotImplementedError("generate_worker_subprocess not implemented")
|
|
||||||
|
|
||||||
def log_path(self):
|
def log_path(self):
|
||||||
filename = (self.name or os.path.basename(self.input_path)) + '_' + \
|
filename = (self.name or os.path.basename(self.input_path)) + '_' + \
|
||||||
self.date_created.strftime("%Y.%m.%d_%H.%M.%S") + '.log'
|
self.date_created.strftime("%Y.%m.%d_%H.%M.%S") + '.log'
|
||||||
@@ -155,7 +204,7 @@ class BaseRenderWorker(Base):
|
|||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
|
|
||||||
if self.status not in [RenderStatus.SCHEDULED, RenderStatus.NOT_STARTED]:
|
if self.status not in [RenderStatus.SCHEDULED, RenderStatus.NOT_STARTED, RenderStatus.CONFIGURING]:
|
||||||
logger.error(f"Trying to start job with status: {self.status}")
|
logger.error(f"Trying to start job with status: {self.status}")
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -173,101 +222,218 @@ class BaseRenderWorker(Base):
|
|||||||
self.errors.append(msg)
|
self.errors.append(msg)
|
||||||
return
|
return
|
||||||
|
|
||||||
self.status = RenderStatus.RUNNING
|
self.status = RenderStatus.RUNNING if not self.children else RenderStatus.WAITING_FOR_SUBJOBS
|
||||||
self.start_time = datetime.now()
|
self.start_time = datetime.now()
|
||||||
logger.info(f'Starting {self.engine.name()} {self.renderer_version} Render for {self.input_path} | '
|
|
||||||
f'Frame Count: {self.total_frames}')
|
|
||||||
self.__thread.start()
|
self.__thread.start()
|
||||||
|
|
||||||
def run(self):
|
# handle multiple attempts at running subprocess
|
||||||
# Setup logging
|
def __run__subprocess_cycle(self, log_file):
|
||||||
log_dir = os.path.dirname(self.log_path())
|
|
||||||
os.makedirs(log_dir, exist_ok=True)
|
|
||||||
|
|
||||||
subprocess_cmds = self.generate_subprocess()
|
subprocess_cmds = self.generate_subprocess()
|
||||||
initial_file_count = len(self.file_list())
|
initial_file_count = len(self.file_list())
|
||||||
failed_attempts = 0
|
failed_attempts = 0
|
||||||
|
|
||||||
with open(self.log_path(), "a") as f:
|
log_file.write(f"Running command: {subprocess_cmds}\n")
|
||||||
|
log_file.write('=' * 80 + '\n\n')
|
||||||
|
|
||||||
f.write(f"{self.start_time.isoformat()} - Starting {self.engine.name()} {self.renderer_version} "
|
while True:
|
||||||
f"render for {self.input_path}\n\n")
|
# Log attempt #
|
||||||
f.write(f"Running command: {subprocess_cmds}\n")
|
if failed_attempts:
|
||||||
f.write('=' * 80 + '\n\n')
|
if failed_attempts >= self.maximum_attempts:
|
||||||
|
err_msg = f"Maximum attempts exceeded ({self.maximum_attempts})"
|
||||||
|
logger.error(err_msg)
|
||||||
|
self.status = RenderStatus.ERROR
|
||||||
|
self.errors.append(err_msg)
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
log_file.write(f'\n{"=" * 20} Attempt #{failed_attempts + 1} {"=" * 20}\n\n')
|
||||||
|
logger.warning(f"Restarting render - Attempt #{failed_attempts + 1}")
|
||||||
|
self.status = RenderStatus.RUNNING
|
||||||
|
|
||||||
while True:
|
return_code = self.__setup_and_run_process(log_file, subprocess_cmds)
|
||||||
# Log attempt #
|
|
||||||
if failed_attempts:
|
|
||||||
if failed_attempts >= self.maximum_attempts:
|
|
||||||
err_msg = f"Maximum attempts exceeded ({self.maximum_attempts})"
|
|
||||||
logger.error(err_msg)
|
|
||||||
self.status = RenderStatus.ERROR
|
|
||||||
self.errors.append(err_msg)
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
f.write(f'\n{"=" * 20} Attempt #{failed_attempts + 1} {"=" * 20}\n\n')
|
|
||||||
logger.warning(f"Restarting render - Attempt #{failed_attempts + 1}")
|
|
||||||
self.status = RenderStatus.RUNNING
|
|
||||||
|
|
||||||
# Start process and get updates
|
message = f"{'=' * 50}\n\n{self.engine.name()} render ended with code {return_code} " \
|
||||||
|
f"after {self.time_elapsed()}\n\n"
|
||||||
|
log_file.write(message)
|
||||||
|
|
||||||
|
# don't try again if we've been cancelled
|
||||||
|
if self.status in [RenderStatus.CANCELLED, RenderStatus.ERROR]:
|
||||||
|
return
|
||||||
|
|
||||||
|
# if file output hasn't increased, return as error, otherwise restart process.
|
||||||
|
file_count_has_increased = len(self.file_list()) > initial_file_count
|
||||||
|
if (self.status == RenderStatus.RUNNING) and file_count_has_increased and not return_code:
|
||||||
|
break
|
||||||
|
|
||||||
|
if return_code:
|
||||||
|
err_msg = f"{self.engine.name()} render failed with code {return_code}"
|
||||||
|
logger.error(err_msg)
|
||||||
|
self.errors.append(err_msg)
|
||||||
|
|
||||||
|
# handle instances where renderer exits ok but doesnt generate files
|
||||||
|
if not return_code and not file_count_has_increased:
|
||||||
|
err_msg = (f"{self.engine.name()} render exited ok, but file count has not increased. "
|
||||||
|
f"Count is still {len(self.file_list())}")
|
||||||
|
log_file.write(f'Error: {err_msg}\n\n')
|
||||||
|
self.errors.append(err_msg)
|
||||||
|
|
||||||
|
# only count the attempt as failed if renderer creates no output - reset counter on successful output
|
||||||
|
failed_attempts = 0 if file_count_has_increased else failed_attempts + 1
|
||||||
|
|
||||||
|
def __run__wait_for_subjobs(self, logfile):
|
||||||
|
from src.distributed_job_manager import DistributedJobManager
|
||||||
|
DistributedJobManager.wait_for_subjobs(parent_job=self)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def log_and_print(message, log_file, level='info'):
|
||||||
|
if level == 'debug':
|
||||||
|
logger.debug(message)
|
||||||
|
elif level == 'error':
|
||||||
|
logger.error(message)
|
||||||
|
else:
|
||||||
|
logger.info(message)
|
||||||
|
log_file.write(f"{message}\n")
|
||||||
|
|
||||||
|
def __run(self):
|
||||||
|
|
||||||
|
# Setup logging
|
||||||
|
log_dir = os.path.dirname(self.log_path())
|
||||||
|
os.makedirs(log_dir, exist_ok=True)
|
||||||
|
|
||||||
|
with open(self.log_path(), "a") as log_file:
|
||||||
|
|
||||||
|
self.log_and_print(f"{self.start_time.isoformat()} - Starting "
|
||||||
|
f"{self.engine.name()} {self.renderer_version} render job for {self.name} "
|
||||||
|
f"({self.input_path})", log_file)
|
||||||
|
log_file.write(f"\n")
|
||||||
|
if not self.children:
|
||||||
|
self.__run__subprocess_cycle(log_file)
|
||||||
|
else:
|
||||||
|
self.__run__wait_for_subjobs(log_file)
|
||||||
|
|
||||||
|
# Validate Output - End if missing frames
|
||||||
|
if self.status == RenderStatus.RUNNING:
|
||||||
|
file_list_length = len(self.file_list())
|
||||||
|
expected_list_length = (self.end_frame - self.start_frame + 1) if self.end_frame else 1
|
||||||
|
|
||||||
|
msg = f"Frames: Expected ({expected_list_length}) vs actual ({file_list_length}) for {self}"
|
||||||
|
self.log_and_print(msg, log_file, 'debug')
|
||||||
|
|
||||||
|
if file_list_length not in (expected_list_length, 1):
|
||||||
|
msg = f"Missing frames: Expected ({expected_list_length}) vs actual ({file_list_length})"
|
||||||
|
self.log_and_print(msg, log_file, 'error')
|
||||||
|
self.errors.append(msg)
|
||||||
|
self.status = RenderStatus.ERROR
|
||||||
|
# todo: create new subjob to generate missing frames
|
||||||
|
|
||||||
|
# cleanup and close if cancelled / error
|
||||||
|
if self.status in [RenderStatus.CANCELLED, RenderStatus.ERROR]:
|
||||||
|
self.end_time = datetime.now()
|
||||||
|
message = f"{self.engine.name()} render ended with status '{self.status.value}' " \
|
||||||
|
f"after {self.time_elapsed()}"
|
||||||
|
self.log_and_print(message, log_file)
|
||||||
|
log_file.close()
|
||||||
|
return
|
||||||
|
|
||||||
|
# Post Render Work
|
||||||
|
if not self.parent:
|
||||||
|
logger.debug(f"Starting post-processing work for {self}")
|
||||||
|
self.log_and_print(f"Starting post-processing work for {self}", log_file, 'debug')
|
||||||
|
self.post_processing()
|
||||||
|
self.log_and_print(f"Completed post-processing work for {self}", log_file, 'debug')
|
||||||
|
|
||||||
|
self.status = RenderStatus.COMPLETED
|
||||||
|
self.end_time = datetime.now()
|
||||||
|
message = f"Render {self.name} completed successfully after {self.time_elapsed()}"
|
||||||
|
self.log_and_print(message, log_file)
|
||||||
|
|
||||||
|
def __setup_and_run_process(self, f, subprocess_cmds):
|
||||||
|
|
||||||
|
def watchdog():
|
||||||
|
logger.debug(f'Starting process watchdog for {self} with {self.watchdog_timeout}s timeout')
|
||||||
|
while self.__process.poll() is None:
|
||||||
|
time_since_last_update = time.time() - self.__last_output_time
|
||||||
|
if time_since_last_update > self.watchdog_timeout:
|
||||||
|
logger.error(f"Process for {self} terminated due to exceeding timeout ({self.watchdog_timeout}s)")
|
||||||
|
self.__kill_process()
|
||||||
|
break
|
||||||
|
# logger.debug(f'Watchdog for {self} - Time since last update: {time_since_last_update}')
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
logger.debug(f'Stopping process watchdog for {self}')
|
||||||
|
|
||||||
|
return_code = -1
|
||||||
|
watchdog_thread = threading.Thread(target=watchdog)
|
||||||
|
watchdog_thread.daemon = True
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Start process and get updates
|
||||||
|
if os.name == 'posix': # linux / mac
|
||||||
self.__process = subprocess.Popen(subprocess_cmds, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
|
self.__process = subprocess.Popen(subprocess_cmds, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
|
||||||
universal_newlines=False)
|
universal_newlines=False, preexec_fn=os.setsid)
|
||||||
|
else: # windows
|
||||||
|
creationflags = subprocess.CREATE_NEW_PROCESS_GROUP | subprocess.CREATE_NO_WINDOW
|
||||||
|
self.__process = subprocess.Popen(subprocess_cmds, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
|
||||||
|
universal_newlines=False,
|
||||||
|
creationflags=creationflags)
|
||||||
|
|
||||||
for c in io.TextIOWrapper(self.__process.stdout, encoding="utf-8"): # or another encoding
|
# Start watchdog
|
||||||
|
self.__last_output_time = time.time()
|
||||||
|
watchdog_thread.start()
|
||||||
|
|
||||||
|
for c in io.TextIOWrapper(self.__process.stdout, encoding="utf-8"): # or another encoding
|
||||||
|
self.last_output = c.strip()
|
||||||
|
self.__last_output_time = time.time()
|
||||||
|
try:
|
||||||
f.write(c)
|
f.write(c)
|
||||||
f.flush()
|
f.flush()
|
||||||
os.fsync(f.fileno())
|
os.fsync(f.fileno())
|
||||||
self.last_output = c.strip()
|
except Exception as e:
|
||||||
|
logger.error(f"Error saving log to disk: {e}")
|
||||||
|
|
||||||
|
try:
|
||||||
self._parse_stdout(c.strip())
|
self._parse_stdout(c.strip())
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f'Error parsing stdout: {e}')
|
||||||
|
|
||||||
f.write('\n')
|
f.write('\n')
|
||||||
|
|
||||||
# Check return codes and process
|
# Check return codes and process
|
||||||
return_code = self.__process.wait()
|
return_code = self.__process.wait()
|
||||||
self.end_time = datetime.now()
|
except Exception as e:
|
||||||
|
message = f'Uncaught error running render process: {e}'
|
||||||
|
f.write(message)
|
||||||
|
logger.exception(message)
|
||||||
|
self.__kill_process()
|
||||||
|
|
||||||
if self.status in [RenderStatus.CANCELLED, RenderStatus.ERROR]: # user cancelled
|
# let watchdog end before continuing - prevents multiple watchdogs running when process restarts
|
||||||
message = f"{self.engine.name()} render ended with status '{self.status}' " \
|
if watchdog_thread.is_alive():
|
||||||
f"after {self.time_elapsed()}"
|
watchdog_thread.join()
|
||||||
f.write(message)
|
|
||||||
return
|
|
||||||
|
|
||||||
# if file output hasn't increased, return as error, otherwise restart process.
|
return return_code
|
||||||
if len(self.file_list()) <= initial_file_count:
|
|
||||||
err_msg = f"File count has not increased. Count is still {len(self.file_list())}"
|
|
||||||
f.write(f'Error: {err_msg}\n\n')
|
|
||||||
self.errors.append(err_msg)
|
|
||||||
self.status = RenderStatus.ERROR
|
|
||||||
|
|
||||||
# Handle completed - All else counts as failed attempt
|
def __kill_process(self):
|
||||||
if (self.status == RenderStatus.COMPLETED) and not return_code:
|
try:
|
||||||
message = (f"{'=' * 50}\n\n{self.engine.name()} render completed successfully in "
|
if self.__process.poll():
|
||||||
f"{self.time_elapsed()}\n")
|
return
|
||||||
f.write(message)
|
logger.debug(f"Trying to kill process {self.__process}")
|
||||||
break
|
self.__process.terminate()
|
||||||
|
self.__process.kill()
|
||||||
# Handle non-zero return codes
|
if os.name == 'posix': # linux / macos
|
||||||
message = f"{'=' * 50}\n\n{self.engine.name()} render failed with code {return_code} " \
|
os.killpg(os.getpgid(self.__process.pid), signal.SIGTERM)
|
||||||
f"after {self.time_elapsed()}\n\n"
|
os.killpg(os.getpgid(self.__process.pid), signal.SIGKILL)
|
||||||
f.write(message)
|
else: # windows
|
||||||
self.errors.append(message)
|
parent = psutil.Process(self.__process.pid)
|
||||||
failed_attempts += 1
|
for child in parent.children(recursive=True):
|
||||||
|
child.kill()
|
||||||
if self.children:
|
self.__process.wait(timeout=5)
|
||||||
from src.distributed_job_manager import DistributedJobManager
|
logger.debug(f"Process ended with status {self.__process.poll()}")
|
||||||
DistributedJobManager.wait_for_subjobs(local_job=self)
|
except (ProcessLookupError, AttributeError, psutil.NoSuchProcess):
|
||||||
|
pass
|
||||||
# Post Render Work
|
except Exception as e:
|
||||||
logger.debug("Starting post-processing work")
|
logger.error(f"Error stopping the process: {e}")
|
||||||
self.post_processing()
|
|
||||||
self.status = RenderStatus.COMPLETED
|
|
||||||
logger.info(f"Render {self.id}-{self.name} completed successfully after {self.time_elapsed()}")
|
|
||||||
|
|
||||||
def post_processing(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def is_running(self):
|
def is_running(self):
|
||||||
if self.__thread:
|
if hasattr(self, '__thread'):
|
||||||
return self.__thread.is_alive()
|
return self.__thread.is_alive()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@@ -278,15 +444,11 @@ class BaseRenderWorker(Base):
|
|||||||
self.stop(is_error=True)
|
self.stop(is_error=True)
|
||||||
|
|
||||||
def stop(self, is_error=False):
|
def stop(self, is_error=False):
|
||||||
if hasattr(self, '__process'):
|
logger.debug(f"Stopping {self}")
|
||||||
try:
|
|
||||||
process = psutil.Process(self.__process.pid)
|
# cleanup status
|
||||||
for proc in process.children(recursive=True):
|
if self.status in [RenderStatus.RUNNING, RenderStatus.NOT_STARTED, RenderStatus.SCHEDULED,
|
||||||
proc.kill()
|
RenderStatus.CONFIGURING]:
|
||||||
process.kill()
|
|
||||||
except Exception as e:
|
|
||||||
logger.debug(f"Error stopping the process: {e}")
|
|
||||||
if self.status in [RenderStatus.RUNNING, RenderStatus.NOT_STARTED, RenderStatus.SCHEDULED]:
|
|
||||||
if is_error:
|
if is_error:
|
||||||
err_message = self.errors[-1] if self.errors else 'Unknown error'
|
err_message = self.errors[-1] if self.errors else 'Unknown error'
|
||||||
logger.error(f"Halting render due to error: {err_message}")
|
logger.error(f"Halting render due to error: {err_message}")
|
||||||
@@ -294,13 +456,9 @@ class BaseRenderWorker(Base):
|
|||||||
else:
|
else:
|
||||||
self.status = RenderStatus.CANCELLED
|
self.status = RenderStatus.CANCELLED
|
||||||
|
|
||||||
def percent_complete(self):
|
self.__kill_process()
|
||||||
if self.status == RenderStatus.COMPLETED:
|
if self.is_running(): # allow the log files to close
|
||||||
return 1.0
|
self.__thread.join(timeout=5)
|
||||||
return 0
|
|
||||||
|
|
||||||
def _parse_stdout(self, line):
|
|
||||||
raise NotImplementedError("_parse_stdout not implemented")
|
|
||||||
|
|
||||||
def time_elapsed(self):
|
def time_elapsed(self):
|
||||||
return get_time_elapsed(self.start_time, self.end_time)
|
return get_time_elapsed(self.start_time, self.end_time)
|
||||||
@@ -308,7 +466,11 @@ class BaseRenderWorker(Base):
|
|||||||
def file_list(self):
|
def file_list(self):
|
||||||
try:
|
try:
|
||||||
job_dir = os.path.dirname(self.output_path)
|
job_dir = os.path.dirname(self.output_path)
|
||||||
file_list = [os.path.join(job_dir, file) for file in os.listdir(job_dir)]
|
file_list = [
|
||||||
|
os.path.join(job_dir, file)
|
||||||
|
for file in os.listdir(job_dir)
|
||||||
|
if not file.startswith('.') # Ignore hidden files
|
||||||
|
]
|
||||||
file_list.sort()
|
file_list.sort()
|
||||||
return file_list
|
return file_list
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
|
|||||||
@@ -12,6 +12,9 @@ logger = logging.getLogger()
|
|||||||
|
|
||||||
|
|
||||||
class EngineManager:
|
class EngineManager:
|
||||||
|
"""Class that manages different versions of installed renderers and handles fetching and downloading new versions,
|
||||||
|
if possible.
|
||||||
|
"""
|
||||||
|
|
||||||
engines_path = None
|
engines_path = None
|
||||||
download_tasks = []
|
download_tasks = []
|
||||||
@@ -27,7 +30,7 @@ class EngineManager:
|
|||||||
return obj
|
return obj
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_engines(cls, filter_name=None):
|
def get_engines(cls, filter_name=None, include_corrupt=False):
|
||||||
|
|
||||||
if not cls.engines_path:
|
if not cls.engines_path:
|
||||||
raise FileNotFoundError("Engine path is not set")
|
raise FileNotFoundError("Engine path is not set")
|
||||||
@@ -49,10 +52,8 @@ class EngineManager:
|
|||||||
# Initialize binary_name with engine name
|
# Initialize binary_name with engine name
|
||||||
binary_name = result_dict['engine'].lower()
|
binary_name = result_dict['engine'].lower()
|
||||||
# Determine the correct binary name based on the engine and system_os
|
# Determine the correct binary name based on the engine and system_os
|
||||||
for eng in cls.supported_engines():
|
eng = cls.engine_with_name(result_dict['engine'])
|
||||||
if eng.name().lower() == result_dict['engine']:
|
binary_name = eng.binary_names.get(result_dict['system_os'], binary_name)
|
||||||
binary_name = eng.binary_names.get(result_dict['system_os'], binary_name)
|
|
||||||
break
|
|
||||||
|
|
||||||
# Find the path to the binary file
|
# Find the path to the binary file
|
||||||
path = next(
|
path = next(
|
||||||
@@ -60,8 +61,16 @@ class EngineManager:
|
|||||||
os.walk(system_safe_path(os.path.join(cls.engines_path, directory))) if binary_name in files),
|
os.walk(system_safe_path(os.path.join(cls.engines_path, directory))) if binary_name in files),
|
||||||
None
|
None
|
||||||
)
|
)
|
||||||
|
|
||||||
result_dict['path'] = path
|
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
|
# 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']:
|
if not filter_name or filter_name == result_dict['engine']:
|
||||||
results.append(result_dict)
|
results.append(result_dict)
|
||||||
@@ -69,10 +78,14 @@ class EngineManager:
|
|||||||
logger.warning(f"Cannot find local engines download directory: {e}")
|
logger.warning(f"Cannot find local engines download directory: {e}")
|
||||||
|
|
||||||
# add system installs to this list - use bg thread because it can be slow
|
# 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 {
|
return {
|
||||||
'engine': eng.name(),
|
'engine': eng.name(),
|
||||||
'version': eng().version(),
|
'version': version or 'error',
|
||||||
'system_os': current_system_os(),
|
'system_os': current_system_os(),
|
||||||
'cpu': current_system_cpu(),
|
'cpu': current_system_cpu(),
|
||||||
'path': eng.default_renderer_path(),
|
'path': eng.default_renderer_path(),
|
||||||
@@ -81,7 +94,7 @@ class EngineManager:
|
|||||||
|
|
||||||
with concurrent.futures.ThreadPoolExecutor() as executor:
|
with concurrent.futures.ThreadPoolExecutor() as executor:
|
||||||
futures = {
|
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()
|
for eng in cls.supported_engines()
|
||||||
if eng.default_renderer_path() and (not filter_name or filter_name == eng.name())
|
if eng.default_renderer_path() and (not filter_name or filter_name == eng.name())
|
||||||
}
|
}
|
||||||
@@ -94,8 +107,8 @@ class EngineManager:
|
|||||||
return results
|
return results
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def all_versions_for_engine(cls, engine_name):
|
def all_versions_for_engine(cls, engine_name, include_corrupt=False):
|
||||||
versions = cls.get_engines(filter_name=engine_name)
|
versions = cls.get_engines(filter_name=engine_name, include_corrupt=include_corrupt)
|
||||||
sorted_versions = sorted(versions, key=lambda x: x['version'], reverse=True)
|
sorted_versions = sorted(versions, key=lambda x: x['version'], reverse=True)
|
||||||
return sorted_versions
|
return sorted_versions
|
||||||
|
|
||||||
@@ -110,7 +123,7 @@ class EngineManager:
|
|||||||
return filtered[0]
|
return filtered[0]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
logger.error(f"Cannot find newest engine version for {engine}-{system_os}-{cpu}")
|
logger.error(f"Cannot find newest engine version for {engine}-{system_os}-{cpu}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def is_version_downloaded(cls, engine, version, system_os=None, cpu=None):
|
def is_version_downloaded(cls, engine, version, system_os=None, cpu=None):
|
||||||
@@ -172,12 +185,12 @@ class EngineManager:
|
|||||||
|
|
||||||
if background:
|
if background:
|
||||||
return thread
|
return thread
|
||||||
else:
|
|
||||||
thread.join()
|
thread.join()
|
||||||
found_engine = cls.is_version_downloaded(engine, version, system_os, cpu) # Check that engine downloaded
|
found_engine = cls.is_version_downloaded(engine, version, system_os, cpu) # Check that engine downloaded
|
||||||
if not found_engine:
|
if not found_engine:
|
||||||
logger.error(f"Error downloading {engine}")
|
logger.error(f"Error downloading {engine}")
|
||||||
return found_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):
|
||||||
@@ -204,13 +217,19 @@ class EngineManager:
|
|||||||
def engine_update_task(engine_class):
|
def engine_update_task(engine_class):
|
||||||
logger.debug(f"Checking for updates to {engine_class.name()}")
|
logger.debug(f"Checking for updates to {engine_class.name()}")
|
||||||
latest_version = engine_class.downloader().find_most_recent_version()
|
latest_version = engine_class.downloader().find_most_recent_version()
|
||||||
if latest_version:
|
|
||||||
logger.debug(f"Latest version of {engine_class.name()} available: {latest_version.get('version')}")
|
if not latest_version:
|
||||||
if not cls.is_version_downloaded(engine_class.name(), latest_version.get('version')):
|
logger.warning(f"Could not find most recent version of {engine.name()} to download")
|
||||||
logger.info(f"Downloading latest version of {engine_class.name()}...")
|
return
|
||||||
cls.download_engine(engine=engine_class.name(), version=latest_version['version'], background=True)
|
|
||||||
else:
|
version_num = latest_version.get('version')
|
||||||
logger.warning(f"Unable to get check for updates for {engine.name()}")
|
if cls.is_version_downloaded(engine_class.name(), version_num):
|
||||||
|
logger.debug(f"Latest version of {engine_class.name()} ({version_num}) already downloaded")
|
||||||
|
return
|
||||||
|
|
||||||
|
# download the engine
|
||||||
|
logger.info(f"Downloading latest version of {engine_class.name()} ({version_num})...")
|
||||||
|
cls.download_engine(engine=engine_class.name(), version=version_num, background=True)
|
||||||
|
|
||||||
logger.info(f"Checking for updates for render engines...")
|
logger.info(f"Checking for updates for render engines...")
|
||||||
threads = []
|
threads = []
|
||||||
@@ -260,13 +279,24 @@ class EngineManager:
|
|||||||
_, extension = os.path.splitext(path)
|
_, extension = os.path.splitext(path)
|
||||||
extension = extension.lower().strip('.')
|
extension = extension.lower().strip('.')
|
||||||
for engine in cls.supported_engines():
|
for engine in cls.supported_engines():
|
||||||
if extension in engine.supported_extensions():
|
if extension in engine().supported_extensions():
|
||||||
return engine
|
return engine
|
||||||
undefined_renderer_support = [x for x in cls.supported_engines() if not x.supported_extensions()]
|
undefined_renderer_support = [x for x in cls.supported_engines() if not x().supported_extensions()]
|
||||||
return undefined_renderer_support[0]
|
return undefined_renderer_support[0]
|
||||||
|
|
||||||
|
|
||||||
class EngineDownloadWorker(threading.Thread):
|
class EngineDownloadWorker(threading.Thread):
|
||||||
|
"""A thread worker for downloading a specific version of a rendering engine.
|
||||||
|
|
||||||
|
This class handles the process of downloading a rendering engine in a separate thread,
|
||||||
|
ensuring that the download process does not block the main application.
|
||||||
|
|
||||||
|
Attributes:
|
||||||
|
engine (str): The name of the rendering engine to download.
|
||||||
|
version (str): The version of the rendering engine to download.
|
||||||
|
system_os (str, optional): The operating system for which to download the engine. Defaults to current OS type.
|
||||||
|
cpu (str, optional): Requested CPU architecture. Defaults to system CPU type.
|
||||||
|
"""
|
||||||
def __init__(self, engine, version, system_os=None, cpu=None):
|
def __init__(self, engine, version, system_os=None, cpu=None):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.engine = engine
|
self.engine = engine
|
||||||
@@ -275,18 +305,21 @@ class EngineDownloadWorker(threading.Thread):
|
|||||||
self.cpu = cpu
|
self.cpu = cpu
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
existing_download = EngineManager.is_version_downloaded(self.engine, self.version, self.system_os, self.cpu)
|
try:
|
||||||
if existing_download:
|
existing_download = EngineManager.is_version_downloaded(self.engine, self.version, self.system_os, self.cpu)
|
||||||
logger.info(f"Requested download of {self.engine} {self.version}, but local copy already exists")
|
if existing_download:
|
||||||
return existing_download
|
logger.info(f"Requested download of {self.engine} {self.version}, but local copy already exists")
|
||||||
|
return existing_download
|
||||||
|
|
||||||
# Get the appropriate downloader class based on the engine type
|
# Get the appropriate downloader class based on the engine type
|
||||||
EngineManager.engine_with_name(self.engine).downloader().download_engine(
|
EngineManager.engine_with_name(self.engine).downloader().download_engine(
|
||||||
self.version, download_location=EngineManager.engines_path, system_os=self.system_os, cpu=self.cpu,
|
self.version, download_location=EngineManager.engines_path, system_os=self.system_os, cpu=self.cpu,
|
||||||
timeout=300)
|
timeout=300)
|
||||||
|
except Exception as e:
|
||||||
# remove itself from the downloader list
|
logger.error(f"Error in download worker: {e}")
|
||||||
EngineManager.download_tasks.remove(self)
|
finally:
|
||||||
|
# remove itself from the downloader list
|
||||||
|
EngineManager.download_tasks.remove(self)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
@@ -132,8 +132,8 @@ class FFMPEGDownloader(EngineDownloader):
|
|||||||
system_os = system_os or current_system_os()
|
system_os = system_os or current_system_os()
|
||||||
cpu = cpu or current_system_cpu()
|
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):
|
except (IndexError, requests.exceptions.RequestException) as e:
|
||||||
logger.error(f"Cannot get most recent version of ffmpeg")
|
logger.error(f"Cannot get most recent version of ffmpeg: {e}")
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ import re
|
|||||||
|
|
||||||
from src.engines.core.base_engine import *
|
from src.engines.core.base_engine import *
|
||||||
|
|
||||||
|
_creationflags = subprocess.CREATE_NO_WINDOW if platform.system() == 'Windows' else 0
|
||||||
|
|
||||||
|
|
||||||
class FFMPEG(BaseRenderEngine):
|
class FFMPEG(BaseRenderEngine):
|
||||||
binary_names = {'linux': 'ffmpeg', 'windows': 'ffmpeg.exe', 'macos': 'ffmpeg'}
|
binary_names = {'linux': 'ffmpeg', 'windows': 'ffmpeg.exe', 'macos': 'ffmpeg'}
|
||||||
@@ -21,10 +23,9 @@ class FFMPEG(BaseRenderEngine):
|
|||||||
from src.engines.ffmpeg.ffmpeg_ui import FFMPEGUI
|
from src.engines.ffmpeg.ffmpeg_ui import FFMPEGUI
|
||||||
return FFMPEGUI.get_options(self)
|
return FFMPEGUI.get_options(self)
|
||||||
|
|
||||||
@classmethod
|
def supported_extensions(self):
|
||||||
def supported_extensions(cls):
|
help_text = (subprocess.check_output([self.renderer_path(), '-h', 'full'], stderr=subprocess.STDOUT,
|
||||||
help_text = (subprocess.check_output([cls().renderer_path(), '-h', 'full'], stderr=subprocess.STDOUT)
|
creationflags=_creationflags).decode('utf-8'))
|
||||||
.decode('utf-8'))
|
|
||||||
found = re.findall(r'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()
|
found_extensions = set()
|
||||||
for match in found:
|
for match in found:
|
||||||
@@ -34,8 +35,8 @@ class FFMPEG(BaseRenderEngine):
|
|||||||
def version(self):
|
def version(self):
|
||||||
version = None
|
version = None
|
||||||
try:
|
try:
|
||||||
ver_out = subprocess.check_output([self.renderer_path(), '-version'],
|
ver_out = subprocess.check_output([self.renderer_path(), '-version'], timeout=SUBPROCESS_TIMEOUT,
|
||||||
timeout=SUBPROCESS_TIMEOUT).decode('utf-8')
|
creationflags=_creationflags).decode('utf-8')
|
||||||
match = re.match(r".*version\s*([\w.*]+)\W*", ver_out)
|
match = re.match(r".*version\s*([\w.*]+)\W*", ver_out)
|
||||||
if match:
|
if match:
|
||||||
version = match.groups()[0]
|
version = match.groups()[0]
|
||||||
@@ -50,7 +51,8 @@ class FFMPEG(BaseRenderEngine):
|
|||||||
'ffprobe', '-v', 'quiet', '-print_format', 'json',
|
'ffprobe', '-v', 'quiet', '-print_format', 'json',
|
||||||
'-show_streams', '-select_streams', 'v', project_path
|
'-show_streams', '-select_streams', 'v', project_path
|
||||||
]
|
]
|
||||||
output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, text=True)
|
output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, text=True,
|
||||||
|
creationflags=_creationflags)
|
||||||
video_info = json.loads(output)
|
video_info = json.loads(output)
|
||||||
|
|
||||||
# Extract the necessary information
|
# Extract the necessary information
|
||||||
@@ -81,7 +83,7 @@ class FFMPEG(BaseRenderEngine):
|
|||||||
|
|
||||||
def get_encoders(self):
|
def get_encoders(self):
|
||||||
raw_stdout = subprocess.check_output([self.renderer_path(), '-encoders'], stderr=subprocess.DEVNULL,
|
raw_stdout = subprocess.check_output([self.renderer_path(), '-encoders'], stderr=subprocess.DEVNULL,
|
||||||
timeout=SUBPROCESS_TIMEOUT).decode('utf-8')
|
timeout=SUBPROCESS_TIMEOUT, creationflags=_creationflags).decode('utf-8')
|
||||||
pattern = r'(?P<type>[VASFXBD.]{6})\s+(?P<name>\S{2,})\s+(?P<description>.*)'
|
pattern = r'(?P<type>[VASFXBD.]{6})\s+(?P<name>\S{2,})\s+(?P<description>.*)'
|
||||||
encoders = [m.groupdict() for m in re.finditer(pattern, raw_stdout)]
|
encoders = [m.groupdict() for m in re.finditer(pattern, raw_stdout)]
|
||||||
return encoders
|
return encoders
|
||||||
@@ -93,7 +95,8 @@ class FFMPEG(BaseRenderEngine):
|
|||||||
def get_all_formats(self):
|
def get_all_formats(self):
|
||||||
try:
|
try:
|
||||||
formats_raw = subprocess.check_output([self.renderer_path(), '-formats'], stderr=subprocess.DEVNULL,
|
formats_raw = subprocess.check_output([self.renderer_path(), '-formats'], stderr=subprocess.DEVNULL,
|
||||||
timeout=SUBPROCESS_TIMEOUT).decode('utf-8')
|
timeout=SUBPROCESS_TIMEOUT,
|
||||||
|
creationflags=_creationflags).decode('utf-8')
|
||||||
pattern = r'(?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)]
|
all_formats = [m.groupdict() for m in re.finditer(pattern, formats_raw)]
|
||||||
return all_formats
|
return all_formats
|
||||||
@@ -105,7 +108,8 @@ class FFMPEG(BaseRenderEngine):
|
|||||||
# Extract the common extension using regex
|
# Extract the common extension using regex
|
||||||
muxer_flag = 'muxer' if 'E' in ffmpeg_format['type'] else 'demuxer'
|
muxer_flag = 'muxer' if 'E' in ffmpeg_format['type'] else 'demuxer'
|
||||||
format_detail_raw = subprocess.check_output(
|
format_detail_raw = subprocess.check_output(
|
||||||
[self.renderer_path(), '-hide_banner', '-h', f"{muxer_flag}={ffmpeg_format['id']}"]).decode('utf-8')
|
[self.renderer_path(), '-hide_banner', '-h', f"{muxer_flag}={ffmpeg_format['id']}"],
|
||||||
|
creationflags=_creationflags).decode('utf-8')
|
||||||
pattern = r"Common extensions: (\w+)"
|
pattern = r"Common extensions: (\w+)"
|
||||||
common_extensions = re.findall(pattern, format_detail_raw)
|
common_extensions = re.findall(pattern, format_detail_raw)
|
||||||
found_extensions = []
|
found_extensions = []
|
||||||
@@ -119,7 +123,7 @@ class FFMPEG(BaseRenderEngine):
|
|||||||
def get_frame_count(self, path_to_file):
|
def get_frame_count(self, path_to_file):
|
||||||
raw_stdout = subprocess.check_output([self.renderer_path(), '-i', path_to_file, '-map', '0:v:0', '-c', 'copy',
|
raw_stdout = subprocess.check_output([self.renderer_path(), '-i', path_to_file, '-map', '0:v:0', '-c', 'copy',
|
||||||
'-f', 'null', '-'], stderr=subprocess.STDOUT,
|
'-f', 'null', '-'], stderr=subprocess.STDOUT,
|
||||||
timeout=SUBPROCESS_TIMEOUT).decode('utf-8')
|
timeout=SUBPROCESS_TIMEOUT, creationflags=_creationflags).decode('utf-8')
|
||||||
match = re.findall(r'frame=\s*(\d+)', raw_stdout)
|
match = re.findall(r'frame=\s*(\d+)', raw_stdout)
|
||||||
if match:
|
if match:
|
||||||
frame_number = int(match[-1])
|
frame_number = int(match[-1])
|
||||||
@@ -127,8 +131,8 @@ class FFMPEG(BaseRenderEngine):
|
|||||||
return -1
|
return -1
|
||||||
|
|
||||||
def get_arguments(self):
|
def get_arguments(self):
|
||||||
help_text = (subprocess.check_output([self.renderer_path(), '-h', 'long'], stderr=subprocess.STDOUT)
|
help_text = (subprocess.check_output([self.renderer_path(), '-h', 'long'], stderr=subprocess.STDOUT,
|
||||||
.decode('utf-8'))
|
creationflags=_creationflags).decode('utf-8'))
|
||||||
lines = help_text.splitlines()
|
lines = help_text.splitlines()
|
||||||
|
|
||||||
options = {}
|
options = {}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
class FFMPEGUI:
|
class FFMPEGUI:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_options(instance):
|
def get_options(system_info):
|
||||||
options = []
|
options = []
|
||||||
return options
|
return options
|
||||||
|
|||||||
191
src/init.py
191
src/init.py
@@ -1,78 +1,195 @@
|
|||||||
''' app/init.py '''
|
|
||||||
import logging
|
import logging
|
||||||
|
import multiprocessing
|
||||||
import os
|
import os
|
||||||
|
import socket
|
||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
from collections import deque
|
from collections import deque
|
||||||
|
|
||||||
from PyQt6.QtCore import QObject, pyqtSignal
|
import cpuinfo
|
||||||
from PyQt6.QtWidgets import QApplication
|
import psutil
|
||||||
|
|
||||||
|
from src.api.api_server import API_VERSION
|
||||||
from src.api.api_server import start_server
|
from src.api.api_server import start_server
|
||||||
|
from src.api.preview_manager import PreviewManager
|
||||||
|
from src.api.serverproxy_manager import ServerProxyManager
|
||||||
|
from src.distributed_job_manager import DistributedJobManager
|
||||||
from src.engines.engine_manager import EngineManager
|
from src.engines.engine_manager import EngineManager
|
||||||
from src.render_queue import RenderQueue
|
from src.render_queue import RenderQueue
|
||||||
from src.ui.main_window import MainWindow
|
|
||||||
from src.utilities.config import Config
|
from src.utilities.config import Config
|
||||||
from src.utilities.misc_helper import system_safe_path
|
from src.utilities.misc_helper import (get_gpu_info, system_safe_path, current_system_cpu, current_system_os,
|
||||||
|
current_system_os_version, check_for_updates)
|
||||||
|
from src.utilities.zeroconf_server import ZeroconfServer
|
||||||
|
from src.version import APP_NAME, APP_VERSION, APP_REPO_NAME, APP_REPO_OWNER
|
||||||
|
|
||||||
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
def run() -> int:
|
def run(server_only=False) -> int:
|
||||||
"""
|
"""Initializes the application and runs it.
|
||||||
Initializes the application and runs it.
|
|
||||||
|
Args:
|
||||||
|
server_only: Run in server-only CLI mode. Default is False (runs in GUI mode).
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
int: The exit status code.
|
int: The exit status code.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def existing_process(process_name):
|
||||||
|
import psutil
|
||||||
|
current_pid = os.getpid()
|
||||||
|
current_process = psutil.Process(current_pid)
|
||||||
|
for proc in psutil.process_iter(['pid', 'name', 'ppid']):
|
||||||
|
proc_name = proc.info['name'].lower().rstrip('.exe')
|
||||||
|
if proc_name == process_name.lower() and proc.info['pid'] != current_pid:
|
||||||
|
if proc.info['pid'] == current_process.ppid():
|
||||||
|
continue # parent process
|
||||||
|
elif proc.info['ppid'] == current_pid:
|
||||||
|
continue # child process
|
||||||
|
else:
|
||||||
|
return proc # unrelated process
|
||||||
|
return None
|
||||||
|
|
||||||
|
# setup logging
|
||||||
|
logging.basicConfig(format='%(asctime)s: %(levelname)s: %(module)s: %(message)s', datefmt='%d-%b-%y %H:%M:%S',
|
||||||
|
level=Config.server_log_level.upper())
|
||||||
|
logging.getLogger("requests").setLevel(logging.WARNING) # suppress noisy requests/urllib3 logging
|
||||||
|
logging.getLogger("urllib3").setLevel(logging.WARNING)
|
||||||
|
|
||||||
|
# check for existing instance
|
||||||
|
existing_proc = existing_process(APP_NAME)
|
||||||
|
if existing_proc:
|
||||||
|
logger.fatal(f"Another instance of {APP_NAME} is already running (pid: {existing_proc.pid})")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
# Setup logging for console ui
|
||||||
|
buffer_handler = __setup_buffer_handler() if not server_only else None
|
||||||
|
|
||||||
|
# check for updates
|
||||||
|
update_thread = threading.Thread(target=check_for_updates, args=(APP_REPO_NAME, APP_REPO_OWNER, APP_NAME,
|
||||||
|
APP_VERSION))
|
||||||
|
update_thread.start()
|
||||||
|
|
||||||
|
# main start
|
||||||
|
logger.info(f"Starting {APP_NAME} Render Server")
|
||||||
|
return_code = 0
|
||||||
try:
|
try:
|
||||||
# Load Config YAML
|
# Load Config YAML
|
||||||
Config.setup_config_dir()
|
Config.setup_config_dir()
|
||||||
Config.load_config(system_safe_path(os.path.join(Config.config_dir(), 'config.yaml')))
|
Config.load_config(system_safe_path(os.path.join(Config.config_dir(), 'config.yaml')))
|
||||||
|
|
||||||
|
# configure default paths
|
||||||
EngineManager.engines_path = system_safe_path(
|
EngineManager.engines_path = system_safe_path(
|
||||||
os.path.join(os.path.join(os.path.expanduser(Config.upload_folder),
|
os.path.join(os.path.join(os.path.expanduser(Config.upload_folder),
|
||||||
'engines')))
|
'engines')))
|
||||||
logging.basicConfig(format='%(asctime)s: %(levelname)s: %(module)s: %(message)s', datefmt='%d-%b-%y %H:%M:%S',
|
os.makedirs(EngineManager.engines_path, exist_ok=True)
|
||||||
level=Config.server_log_level.upper())
|
PreviewManager.storage_path = system_safe_path(
|
||||||
|
os.path.join(os.path.expanduser(Config.upload_folder), 'previews'))
|
||||||
|
|
||||||
app: QApplication = QApplication(sys.argv)
|
# Debug info
|
||||||
|
logger.debug(f"Upload directory: {os.path.expanduser(Config.upload_folder)}")
|
||||||
|
logger.debug(f"Thumbs directory: {PreviewManager.storage_path}")
|
||||||
|
logger.debug(f"Engines directory: {EngineManager.engines_path}")
|
||||||
|
|
||||||
# Start server in background
|
# Set up the RenderQueue object
|
||||||
background_server = threading.Thread(target=start_server)
|
RenderQueue.load_state(database_directory=system_safe_path(os.path.expanduser(Config.upload_folder)))
|
||||||
background_server.daemon = True
|
ServerProxyManager.subscribe_to_listener()
|
||||||
background_server.start()
|
DistributedJobManager.subscribe_to_listener()
|
||||||
|
|
||||||
# Setup logging for console ui
|
# check for updates for render engines if configured or on first launch
|
||||||
buffer_handler = BufferingHandler()
|
if Config.update_engines_on_launch or not EngineManager.get_engines():
|
||||||
buffer_handler.setFormatter(logging.getLogger().handlers[0].formatter)
|
EngineManager.update_all_engines()
|
||||||
logger = logging.getLogger()
|
|
||||||
logger.addHandler(buffer_handler)
|
|
||||||
|
|
||||||
window: MainWindow = MainWindow()
|
# get hostname
|
||||||
window.buffer_handler = buffer_handler
|
local_hostname = socket.gethostname()
|
||||||
window.show()
|
local_hostname = local_hostname + (".local" if not local_hostname.endswith(".local") else "")
|
||||||
|
|
||||||
return_code = app.exec()
|
# configure and start API server
|
||||||
|
api_server = threading.Thread(target=start_server, args=(local_hostname,))
|
||||||
|
api_server.daemon = True
|
||||||
|
api_server.start()
|
||||||
|
|
||||||
|
# start zeroconf server
|
||||||
|
ZeroconfServer.configure(f"_{APP_NAME.lower()}._tcp.local.", local_hostname, Config.port_number)
|
||||||
|
ZeroconfServer.properties = {'system_cpu': current_system_cpu(),
|
||||||
|
'system_cpu_brand': cpuinfo.get_cpu_info()['brand_raw'],
|
||||||
|
'system_cpu_cores': multiprocessing.cpu_count(),
|
||||||
|
'system_os': current_system_os(),
|
||||||
|
'system_os_version': current_system_os_version(),
|
||||||
|
'system_memory': round(psutil.virtual_memory().total / (1024**3)), # in GB
|
||||||
|
'gpu_info': get_gpu_info(),
|
||||||
|
'api_version': API_VERSION}
|
||||||
|
ZeroconfServer.start()
|
||||||
|
logger.info(f"{APP_NAME} Render Server started - Hostname: {local_hostname}")
|
||||||
|
RenderQueue.start() # Start evaluating the render queue
|
||||||
|
|
||||||
|
# start in gui or server only (cli) mode
|
||||||
|
logger.debug(f"Launching in {'server only' if server_only else 'GUI'} mode")
|
||||||
|
if server_only: # CLI only
|
||||||
|
api_server.join()
|
||||||
|
else: # GUI
|
||||||
|
return_code = __show_gui(buffer_handler)
|
||||||
|
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
pass
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"Unhandled exception: {e}")
|
logging.error(f"Unhandled exception: {e}")
|
||||||
return_code = 1
|
return_code = 1
|
||||||
finally:
|
finally:
|
||||||
RenderQueue.prepare_for_shutdown()
|
# shut down gracefully
|
||||||
|
logger.info(f"{APP_NAME} Render Server is preparing to shut down")
|
||||||
|
try:
|
||||||
|
RenderQueue.prepare_for_shutdown()
|
||||||
|
except Exception as e:
|
||||||
|
logger.exception(f"Exception during prepare for shutdown: {e}")
|
||||||
|
ZeroconfServer.stop()
|
||||||
|
logger.info(f"{APP_NAME} Render Server has shut down")
|
||||||
return sys.exit(return_code)
|
return sys.exit(return_code)
|
||||||
|
|
||||||
|
|
||||||
class BufferingHandler(logging.Handler, QObject):
|
def __setup_buffer_handler():
|
||||||
new_record = pyqtSignal(str)
|
# lazy load GUI frameworks
|
||||||
|
from PyQt6.QtCore import QObject, pyqtSignal
|
||||||
|
|
||||||
def __init__(self, capacity=100):
|
class BufferingHandler(logging.Handler, QObject):
|
||||||
logging.Handler.__init__(self)
|
new_record = pyqtSignal(str)
|
||||||
QObject.__init__(self)
|
|
||||||
self.buffer = deque(maxlen=capacity) # Define a buffer with a fixed capacity
|
|
||||||
|
|
||||||
def emit(self, record):
|
def __init__(self, capacity=100):
|
||||||
msg = self.format(record)
|
logging.Handler.__init__(self)
|
||||||
self.buffer.append(msg) # Add message to the buffer
|
QObject.__init__(self)
|
||||||
self.new_record.emit(msg) # Emit signal
|
self.buffer = deque(maxlen=capacity) # Define a buffer with a fixed capacity
|
||||||
|
|
||||||
def get_buffer(self):
|
def emit(self, record):
|
||||||
return list(self.buffer) # Return a copy of the buffer
|
try:
|
||||||
|
msg = self.format(record)
|
||||||
|
self.buffer.append(msg) # Add message to the buffer
|
||||||
|
self.new_record.emit(msg) # Emit signal
|
||||||
|
except RuntimeError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def get_buffer(self):
|
||||||
|
return list(self.buffer) # Return a copy of the buffer
|
||||||
|
|
||||||
|
buffer_handler = BufferingHandler()
|
||||||
|
buffer_handler.setFormatter(logging.getLogger().handlers[0].formatter)
|
||||||
|
new_logger = logging.getLogger()
|
||||||
|
new_logger.addHandler(buffer_handler)
|
||||||
|
return buffer_handler
|
||||||
|
|
||||||
|
|
||||||
|
def __show_gui(buffer_handler):
|
||||||
|
# lazy load GUI frameworks
|
||||||
|
from PyQt6.QtWidgets import QApplication
|
||||||
|
|
||||||
|
# load application
|
||||||
|
app: QApplication = QApplication(sys.argv)
|
||||||
|
if app.style().objectName() != 'macos':
|
||||||
|
app.setStyle('Fusion')
|
||||||
|
|
||||||
|
# configure main window
|
||||||
|
from src.ui.main_window import MainWindow
|
||||||
|
window: MainWindow = MainWindow()
|
||||||
|
window.buffer_handler = buffer_handler
|
||||||
|
window.show()
|
||||||
|
|
||||||
|
return app.exec()
|
||||||
|
|||||||
@@ -2,12 +2,13 @@ import logging
|
|||||||
import os
|
import os
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
from pubsub import pub
|
||||||
from sqlalchemy import create_engine
|
from sqlalchemy import create_engine
|
||||||
from sqlalchemy.orm import sessionmaker
|
from sqlalchemy.orm import sessionmaker
|
||||||
|
from sqlalchemy.orm.exc import DetachedInstanceError
|
||||||
|
|
||||||
from src.utilities.status_utils import RenderStatus
|
|
||||||
from src.engines.engine_manager import EngineManager
|
|
||||||
from src.engines.core.base_worker import Base
|
from src.engines.core.base_worker import Base
|
||||||
|
from src.utilities.status_utils import RenderStatus
|
||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
|
|
||||||
@@ -17,6 +18,9 @@ class JobNotFoundError(Exception):
|
|||||||
super().__init__(args)
|
super().__init__(args)
|
||||||
self.job_id = job_id
|
self.job_id = job_id
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"Cannot find job with ID: {self.job_id}"
|
||||||
|
|
||||||
|
|
||||||
class RenderQueue:
|
class RenderQueue:
|
||||||
engine = None
|
engine = None
|
||||||
@@ -24,18 +28,53 @@ class RenderQueue:
|
|||||||
job_queue = []
|
job_queue = []
|
||||||
maximum_renderer_instances = {'blender': 1, 'aerender': 1, 'ffmpeg': 4}
|
maximum_renderer_instances = {'blender': 1, 'aerender': 1, 'ffmpeg': 4}
|
||||||
last_saved_counts = {}
|
last_saved_counts = {}
|
||||||
|
is_running = False
|
||||||
|
|
||||||
def __init__(self):
|
# --------------------------------------------
|
||||||
pass
|
# Render Queue Evaluation:
|
||||||
|
# --------------------------------------------
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def add_to_render_queue(cls, render_job, force_start=False):
|
def start(cls):
|
||||||
logger.debug('Adding priority {} job to render queue: {}'.format(render_job.priority, render_job))
|
"""Start evaluating the render queue"""
|
||||||
cls.job_queue.append(render_job)
|
logger.debug("Starting render queue updates")
|
||||||
if force_start and render_job.status in (RenderStatus.NOT_STARTED, RenderStatus.SCHEDULED):
|
cls.is_running = True
|
||||||
cls.start_job(render_job)
|
cls.evaluate_queue()
|
||||||
cls.session.add(render_job)
|
|
||||||
cls.save_state()
|
@classmethod
|
||||||
|
def evaluate_queue(cls):
|
||||||
|
try:
|
||||||
|
not_started = cls.jobs_with_status(RenderStatus.NOT_STARTED, priority_sorted=True)
|
||||||
|
for job in not_started:
|
||||||
|
if cls.is_available_for_job(job.renderer, job.priority):
|
||||||
|
cls.start_job(job)
|
||||||
|
|
||||||
|
scheduled = cls.jobs_with_status(RenderStatus.SCHEDULED, priority_sorted=True)
|
||||||
|
for job in scheduled:
|
||||||
|
if job.scheduled_start <= datetime.now():
|
||||||
|
logger.debug(f"Starting scheduled job: {job}")
|
||||||
|
cls.start_job(job)
|
||||||
|
|
||||||
|
if cls.last_saved_counts != cls.job_counts():
|
||||||
|
cls.save_state()
|
||||||
|
except DetachedInstanceError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def __local_job_status_changed(cls, job_id, old_status, new_status):
|
||||||
|
render_job = RenderQueue.job_with_id(job_id, none_ok=True)
|
||||||
|
if render_job and cls.is_running: # ignore changes from render jobs not in the queue yet
|
||||||
|
logger.debug(f"RenderQueue detected job {job_id} has changed from {old_status} -> {new_status}")
|
||||||
|
RenderQueue.evaluate_queue()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def stop(cls):
|
||||||
|
logger.debug("Stopping render queue updates")
|
||||||
|
cls.is_running = False
|
||||||
|
|
||||||
|
# --------------------------------------------
|
||||||
|
# Fetch Jobs:
|
||||||
|
# --------------------------------------------
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def all_jobs(cls):
|
def all_jobs(cls):
|
||||||
@@ -66,12 +105,15 @@ class RenderQueue:
|
|||||||
return found_job
|
return found_job
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def clear_history(cls):
|
def job_counts(cls):
|
||||||
to_remove = [x for x in cls.all_jobs() if x.status in [RenderStatus.CANCELLED,
|
job_counts = {}
|
||||||
RenderStatus.COMPLETED, RenderStatus.ERROR]]
|
for job_status in RenderStatus:
|
||||||
for job_to_remove in to_remove:
|
job_counts[job_status.value] = len(cls.jobs_with_status(job_status))
|
||||||
cls.delete_job(job_to_remove)
|
return job_counts
|
||||||
cls.save_state()
|
|
||||||
|
# --------------------------------------------
|
||||||
|
# Startup / Shutdown:
|
||||||
|
# --------------------------------------------
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def load_state(cls, database_directory):
|
def load_state(cls, database_directory):
|
||||||
@@ -81,6 +123,7 @@ class RenderQueue:
|
|||||||
cls.session = sessionmaker(bind=cls.engine)()
|
cls.session = sessionmaker(bind=cls.engine)()
|
||||||
from src.engines.core.base_worker import BaseRenderWorker
|
from src.engines.core.base_worker import BaseRenderWorker
|
||||||
cls.job_queue = cls.session.query(BaseRenderWorker).all()
|
cls.job_queue = cls.session.query(BaseRenderWorker).all()
|
||||||
|
pub.subscribe(cls.__local_job_status_changed, 'status_change')
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def save_state(cls):
|
def save_state(cls):
|
||||||
@@ -89,11 +132,22 @@ class RenderQueue:
|
|||||||
@classmethod
|
@classmethod
|
||||||
def prepare_for_shutdown(cls):
|
def prepare_for_shutdown(cls):
|
||||||
logger.debug("Closing session")
|
logger.debug("Closing session")
|
||||||
|
cls.stop()
|
||||||
running_jobs = cls.jobs_with_status(RenderStatus.RUNNING) # cancel all running jobs
|
running_jobs = cls.jobs_with_status(RenderStatus.RUNNING) # cancel all running jobs
|
||||||
[cls.cancel_job(job) for job in running_jobs]
|
[cls.cancel_job(job) for job in running_jobs]
|
||||||
cls.save_state()
|
cls.save_state()
|
||||||
cls.session.close()
|
cls.session.close()
|
||||||
|
|
||||||
|
# --------------------------------------------
|
||||||
|
# Renderer Availability:
|
||||||
|
# --------------------------------------------
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def renderer_instances(cls):
|
||||||
|
from collections import Counter
|
||||||
|
all_instances = [x.renderer for x in cls.running_jobs()]
|
||||||
|
return Counter(all_instances)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def is_available_for_job(cls, renderer, priority=2):
|
def is_available_for_job(cls, renderer, priority=2):
|
||||||
|
|
||||||
@@ -103,52 +157,50 @@ class RenderQueue:
|
|||||||
maxed_out_instances = renderer in instances.keys() and instances[renderer] >= max_allowed_instances
|
maxed_out_instances = renderer in instances.keys() and instances[renderer] >= max_allowed_instances
|
||||||
return not maxed_out_instances and not higher_priority_jobs
|
return not maxed_out_instances and not higher_priority_jobs
|
||||||
|
|
||||||
|
# --------------------------------------------
|
||||||
|
# Job Lifecycle Management:
|
||||||
|
# --------------------------------------------
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def evaluate_queue(cls):
|
def add_to_render_queue(cls, render_job, force_start=False):
|
||||||
not_started = cls.jobs_with_status(RenderStatus.NOT_STARTED, priority_sorted=True)
|
logger.info(f"Adding job to render queue: {render_job}")
|
||||||
for job in not_started:
|
cls.job_queue.append(render_job)
|
||||||
if cls.is_available_for_job(job.renderer, job.priority):
|
if cls.is_running and force_start and render_job.status in (RenderStatus.NOT_STARTED, RenderStatus.SCHEDULED):
|
||||||
cls.start_job(job)
|
cls.start_job(render_job)
|
||||||
|
cls.session.add(render_job)
|
||||||
scheduled = cls.jobs_with_status(RenderStatus.SCHEDULED, priority_sorted=True)
|
cls.save_state()
|
||||||
for job in scheduled:
|
if cls.is_running:
|
||||||
if job.scheduled_start <= datetime.now():
|
cls.evaluate_queue()
|
||||||
logger.debug(f"Starting scheduled job: {job}")
|
|
||||||
cls.start_job(job)
|
|
||||||
|
|
||||||
if cls.last_saved_counts != cls.job_counts():
|
|
||||||
cls.save_state()
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def start_job(cls, job):
|
def start_job(cls, job):
|
||||||
logger.info(f'Starting render: {job.name} - Priority {job.priority}')
|
logger.info(f'Starting job: {job}')
|
||||||
job.start()
|
job.start()
|
||||||
cls.save_state()
|
cls.save_state()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def cancel_job(cls, job):
|
def cancel_job(cls, job):
|
||||||
logger.info(f'Cancelling job ID: {job.id}')
|
logger.info(f'Cancelling job: {job}')
|
||||||
job.stop()
|
job.stop()
|
||||||
return job.status == RenderStatus.CANCELLED
|
return job.status == RenderStatus.CANCELLED
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def delete_job(cls, job):
|
def delete_job(cls, job):
|
||||||
logger.info(f"Deleting job ID: {job.id}")
|
logger.info(f"Deleting job: {job}")
|
||||||
job.stop()
|
job.stop()
|
||||||
cls.job_queue.remove(job)
|
cls.job_queue.remove(job)
|
||||||
cls.session.delete(job)
|
cls.session.delete(job)
|
||||||
cls.save_state()
|
cls.save_state()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@classmethod
|
# --------------------------------------------
|
||||||
def renderer_instances(cls):
|
# Miscellaneous:
|
||||||
from collections import Counter
|
# --------------------------------------------
|
||||||
all_instances = [x.renderer for x in cls.running_jobs()]
|
|
||||||
return Counter(all_instances)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def job_counts(cls):
|
def clear_history(cls):
|
||||||
job_counts = {}
|
to_remove = [x for x in cls.all_jobs() if x.status in [RenderStatus.CANCELLED,
|
||||||
for job_status in RenderStatus:
|
RenderStatus.COMPLETED, RenderStatus.ERROR]]
|
||||||
job_counts[job_status.value] = len(cls.jobs_with_status(job_status))
|
for job_to_remove in to_remove:
|
||||||
return job_counts
|
cls.delete_job(job_to_remove)
|
||||||
|
cls.save_state()
|
||||||
|
|||||||
74
src/ui/about_window.py
Normal file
74
src/ui/about_window.py
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from PyQt6.QtCore import Qt
|
||||||
|
from PyQt6.QtGui import QPixmap
|
||||||
|
from PyQt6.QtWidgets import QDialog, QVBoxLayout, QLabel, QDialogButtonBox, QHBoxLayout
|
||||||
|
|
||||||
|
from src.version import *
|
||||||
|
|
||||||
|
|
||||||
|
class AboutDialog(QDialog):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
self.setWindowTitle(f"About {APP_NAME}")
|
||||||
|
|
||||||
|
# Create the layout
|
||||||
|
layout = QVBoxLayout()
|
||||||
|
|
||||||
|
# App Icon
|
||||||
|
icon_name = 'Server.png' # todo: temp icon - replace with final later
|
||||||
|
icon_path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))),
|
||||||
|
'resources', icon_name)
|
||||||
|
icon_label = QLabel(self)
|
||||||
|
icon_pixmap = QPixmap(icon_path)
|
||||||
|
icon_label.setPixmap(icon_pixmap)
|
||||||
|
icon_layout = QHBoxLayout()
|
||||||
|
icon_layout.addStretch()
|
||||||
|
icon_layout.addWidget(icon_label)
|
||||||
|
icon_layout.addStretch()
|
||||||
|
layout.addLayout(icon_layout)
|
||||||
|
|
||||||
|
# Application name
|
||||||
|
name_label = QLabel(f"<h2>{APP_NAME}</h2>")
|
||||||
|
layout.addWidget(name_label)
|
||||||
|
|
||||||
|
# Description
|
||||||
|
description_label = QLabel(APP_DESCRIPTION)
|
||||||
|
layout.addWidget(description_label)
|
||||||
|
|
||||||
|
# Version
|
||||||
|
version_label = QLabel(f"<strong>Version:</strong> {APP_VERSION}")
|
||||||
|
layout.addWidget(version_label)
|
||||||
|
|
||||||
|
# Contributors
|
||||||
|
contributors_label = QLabel(f"Copyright © {APP_COPYRIGHT_YEAR} {APP_AUTHOR}")
|
||||||
|
layout.addWidget(contributors_label)
|
||||||
|
|
||||||
|
# License
|
||||||
|
license_label = QLabel(f"Released under {APP_LICENSE}")
|
||||||
|
layout.addWidget(license_label)
|
||||||
|
|
||||||
|
# Add an "OK" button to close the dialog
|
||||||
|
button_box = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok)
|
||||||
|
button_box.accepted.connect(self.accept)
|
||||||
|
layout.addWidget(button_box)
|
||||||
|
|
||||||
|
# Set the layout for the dialog
|
||||||
|
self.setLayout(layout)
|
||||||
|
|
||||||
|
# Make the dialog non-resizable
|
||||||
|
self.setWindowFlags(self.windowFlags() & ~Qt.WindowType.WindowContextHelpButtonHint)
|
||||||
|
self.setFixedSize(self.sizeHint())
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
# lazy load GUI frameworks
|
||||||
|
from PyQt6.QtWidgets import QApplication
|
||||||
|
|
||||||
|
# load application
|
||||||
|
app: QApplication = QApplication(sys.argv)
|
||||||
|
window: AboutDialog = AboutDialog()
|
||||||
|
window.show()
|
||||||
|
|
||||||
|
app.exec()
|
||||||
@@ -55,7 +55,7 @@ class NewRenderJobForm(QWidget):
|
|||||||
self.priority_input = None
|
self.priority_input = None
|
||||||
self.end_frame_input = None
|
self.end_frame_input = None
|
||||||
self.start_frame_input = None
|
self.start_frame_input = None
|
||||||
self.output_path_input = None
|
self.render_name_input = None
|
||||||
self.scene_file_input = None
|
self.scene_file_input = None
|
||||||
self.scene_file_browse_button = None
|
self.scene_file_browse_button = None
|
||||||
self.job_name_input = None
|
self.job_name_input = None
|
||||||
@@ -68,11 +68,12 @@ class NewRenderJobForm(QWidget):
|
|||||||
# Setup
|
# Setup
|
||||||
self.setWindowTitle("New Job")
|
self.setWindowTitle("New Job")
|
||||||
self.setup_ui()
|
self.setup_ui()
|
||||||
|
self.update_renderer_info()
|
||||||
self.setup_project()
|
self.setup_project()
|
||||||
|
|
||||||
# get renderer info in bg thread
|
# get renderer info in bg thread
|
||||||
t = threading.Thread(target=self.update_renderer_info)
|
# t = threading.Thread(target=self.update_renderer_info)
|
||||||
t.start()
|
# t.start()
|
||||||
|
|
||||||
self.show()
|
self.show()
|
||||||
|
|
||||||
@@ -136,11 +137,11 @@ class NewRenderJobForm(QWidget):
|
|||||||
self.output_settings_group = QGroupBox("Output Settings")
|
self.output_settings_group = QGroupBox("Output Settings")
|
||||||
output_settings_layout = QVBoxLayout(self.output_settings_group)
|
output_settings_layout = QVBoxLayout(self.output_settings_group)
|
||||||
# output path
|
# output path
|
||||||
output_path_layout = QHBoxLayout()
|
render_name_layout = QHBoxLayout()
|
||||||
output_path_layout.addWidget(QLabel("Render name:"))
|
render_name_layout.addWidget(QLabel("Render name:"))
|
||||||
self.output_path_input = QLineEdit()
|
self.render_name_input = QLineEdit()
|
||||||
output_path_layout.addWidget(self.output_path_input)
|
render_name_layout.addWidget(self.render_name_input)
|
||||||
output_settings_layout.addLayout(output_path_layout)
|
output_settings_layout.addLayout(render_name_layout)
|
||||||
# file format
|
# file format
|
||||||
file_format_layout = QHBoxLayout()
|
file_format_layout = QHBoxLayout()
|
||||||
file_format_layout.addWidget(QLabel("Format:"))
|
file_format_layout.addWidget(QLabel("Format:"))
|
||||||
@@ -281,7 +282,7 @@ class NewRenderJobForm(QWidget):
|
|||||||
|
|
||||||
output_name, _ = os.path.splitext(os.path.basename(self.scene_file_input.text()))
|
output_name, _ = os.path.splitext(os.path.basename(self.scene_file_input.text()))
|
||||||
output_name = output_name.replace(' ', '_')
|
output_name = output_name.replace(' ', '_')
|
||||||
self.output_path_input.setText(output_name)
|
self.render_name_input.setText(output_name)
|
||||||
file_name = self.scene_file_input.text()
|
file_name = self.scene_file_input.text()
|
||||||
|
|
||||||
# setup bg worker
|
# setup bg worker
|
||||||
@@ -292,7 +293,7 @@ class NewRenderJobForm(QWidget):
|
|||||||
def browse_output_path(self):
|
def browse_output_path(self):
|
||||||
directory = QFileDialog.getExistingDirectory(self, "Select Output Directory")
|
directory = QFileDialog.getExistingDirectory(self, "Select Output Directory")
|
||||||
if directory:
|
if directory:
|
||||||
self.output_path_input.setText(directory)
|
self.render_name_input.setText(directory)
|
||||||
|
|
||||||
def args_help_button_clicked(self):
|
def args_help_button_clicked(self):
|
||||||
url = (f'http://{self.server_proxy.hostname}:{self.server_proxy.port}/api/renderer/'
|
url = (f'http://{self.server_proxy.hostname}:{self.server_proxy.port}/api/renderer/'
|
||||||
@@ -316,8 +317,6 @@ class NewRenderJobForm(QWidget):
|
|||||||
self.renderer_type.setCurrentIndex(0) #todo: find out why we don't have renderer info yet
|
self.renderer_type.setCurrentIndex(0) #todo: find out why we don't have renderer info yet
|
||||||
# not ideal but if we don't have the renderer info we have to pick something
|
# not ideal but if we don't have the renderer info we have to pick something
|
||||||
|
|
||||||
self.output_path_input.setText(os.path.basename(input_path))
|
|
||||||
|
|
||||||
# cleanup progress UI
|
# cleanup progress UI
|
||||||
self.load_file_group.setHidden(True)
|
self.load_file_group.setHidden(True)
|
||||||
self.toggle_renderer_enablement(True)
|
self.toggle_renderer_enablement(True)
|
||||||
@@ -350,7 +349,8 @@ class NewRenderJobForm(QWidget):
|
|||||||
# Dynamic Engine Options
|
# Dynamic Engine Options
|
||||||
clear_layout(self.renderer_options_layout) # clear old options
|
clear_layout(self.renderer_options_layout) # clear old options
|
||||||
# dynamically populate option list
|
# dynamically populate option list
|
||||||
self.current_engine_options = engine().ui_options()
|
system_info = self.renderer_info.get(engine.name(), {}).get('system_info', {})
|
||||||
|
self.current_engine_options = engine.ui_options(system_info=system_info)
|
||||||
for option in self.current_engine_options:
|
for option in self.current_engine_options:
|
||||||
h_layout = QHBoxLayout()
|
h_layout = QHBoxLayout()
|
||||||
label = QLabel(option['name'].replace('_', ' ').capitalize() + ':')
|
label = QLabel(option['name'].replace('_', ' ').capitalize() + ':')
|
||||||
@@ -377,7 +377,7 @@ class NewRenderJobForm(QWidget):
|
|||||||
self.cameras_group.setHidden(True)
|
self.cameras_group.setHidden(True)
|
||||||
self.submit_button.setEnabled(enabled)
|
self.submit_button.setEnabled(enabled)
|
||||||
|
|
||||||
def after_job_submission(self, result):
|
def after_job_submission(self, error_string):
|
||||||
|
|
||||||
# UI cleanup
|
# UI cleanup
|
||||||
self.submit_progress.setMaximum(0)
|
self.submit_progress.setMaximum(0)
|
||||||
@@ -389,7 +389,7 @@ class NewRenderJobForm(QWidget):
|
|||||||
self.toggle_renderer_enablement(True)
|
self.toggle_renderer_enablement(True)
|
||||||
|
|
||||||
self.msg_box = QMessageBox()
|
self.msg_box = QMessageBox()
|
||||||
if result.ok:
|
if not error_string:
|
||||||
self.msg_box.setStandardButtons(QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No)
|
self.msg_box.setStandardButtons(QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No)
|
||||||
self.msg_box.setIcon(QMessageBox.Icon.Information)
|
self.msg_box.setIcon(QMessageBox.Icon.Information)
|
||||||
self.msg_box.setText("Job successfully submitted to server. Submit another?")
|
self.msg_box.setText("Job successfully submitted to server. Submit another?")
|
||||||
@@ -400,7 +400,7 @@ class NewRenderJobForm(QWidget):
|
|||||||
else:
|
else:
|
||||||
self.msg_box.setStandardButtons(QMessageBox.StandardButton.Ok)
|
self.msg_box.setStandardButtons(QMessageBox.StandardButton.Ok)
|
||||||
self.msg_box.setIcon(QMessageBox.Icon.Critical)
|
self.msg_box.setIcon(QMessageBox.Icon.Critical)
|
||||||
self.msg_box.setText(result.text or "Unknown error")
|
self.msg_box.setText(error_string)
|
||||||
self.msg_box.setWindowTitle("Error")
|
self.msg_box.setWindowTitle("Error")
|
||||||
self.msg_box.exec()
|
self.msg_box.exec()
|
||||||
|
|
||||||
@@ -431,7 +431,7 @@ class NewRenderJobForm(QWidget):
|
|||||||
class SubmitWorker(QThread):
|
class SubmitWorker(QThread):
|
||||||
"""Worker class called to submit all the jobs to the server and update the UI accordingly"""
|
"""Worker class called to submit all the jobs to the server and update the UI accordingly"""
|
||||||
|
|
||||||
message_signal = pyqtSignal(Response)
|
message_signal = pyqtSignal(str)
|
||||||
update_ui_signal = pyqtSignal(str, str)
|
update_ui_signal = pyqtSignal(str, str)
|
||||||
|
|
||||||
def __init__(self, window):
|
def __init__(self, window):
|
||||||
@@ -447,58 +447,69 @@ class SubmitWorker(QThread):
|
|||||||
self.update_ui_signal.emit(hostname, percent)
|
self.update_ui_signal.emit(hostname, percent)
|
||||||
return callback
|
return callback
|
||||||
|
|
||||||
hostname = self.window.server_input.currentText()
|
try:
|
||||||
job_json = {'owner': psutil.Process().username() + '@' + socket.gethostname(),
|
hostname = self.window.server_input.currentText()
|
||||||
'renderer': self.window.renderer_type.currentText().lower(),
|
job_json = {'owner': psutil.Process().username() + '@' + socket.gethostname(),
|
||||||
'engine_version': self.window.renderer_version_combo.currentText(),
|
'renderer': self.window.renderer_type.currentText().lower(),
|
||||||
'args': {'raw': self.window.raw_args.text()},
|
'engine_version': self.window.renderer_version_combo.currentText(),
|
||||||
'output_path': self.window.output_path_input.text(),
|
'args': {'raw': self.window.raw_args.text(),
|
||||||
'start_frame': self.window.start_frame_input.value(),
|
'export_format': self.window.file_format_combo.currentText()},
|
||||||
'end_frame': self.window.end_frame_input.value(),
|
'output_path': self.window.render_name_input.text(),
|
||||||
'priority': self.window.priority_input.currentIndex() + 1,
|
'start_frame': self.window.start_frame_input.value(),
|
||||||
'notes': self.window.notes_input.toPlainText(),
|
'end_frame': self.window.end_frame_input.value(),
|
||||||
'enable_split_jobs': self.window.enable_splitjobs.isChecked(),
|
'priority': self.window.priority_input.currentIndex() + 1,
|
||||||
'split_jobs_same_os': self.window.splitjobs_same_os.isChecked()}
|
'notes': self.window.notes_input.toPlainText(),
|
||||||
|
'enable_split_jobs': self.window.enable_splitjobs.isChecked(),
|
||||||
|
'split_jobs_same_os': self.window.splitjobs_same_os.isChecked(),
|
||||||
|
'name': self.window.render_name_input.text()}
|
||||||
|
|
||||||
# get the dynamic args
|
# get the dynamic args
|
||||||
for i in range(self.window.renderer_options_layout.count()):
|
for i in range(self.window.renderer_options_layout.count()):
|
||||||
item = self.window.renderer_options_layout.itemAt(i)
|
item = self.window.renderer_options_layout.itemAt(i)
|
||||||
layout = item.layout() # get the layout
|
layout = item.layout() # get the layout
|
||||||
for x in range(layout.count()):
|
for x in range(layout.count()):
|
||||||
z = layout.itemAt(x)
|
z = layout.itemAt(x)
|
||||||
widget = z.widget()
|
widget = z.widget()
|
||||||
if isinstance(widget, QComboBox):
|
if isinstance(widget, QComboBox):
|
||||||
job_json['args'][self.window.current_engine_options[i]['name']] = widget.currentText()
|
job_json['args'][self.window.current_engine_options[i]['name']] = widget.currentText()
|
||||||
elif isinstance(widget, QLineEdit):
|
elif isinstance(widget, QLineEdit):
|
||||||
job_json['args'][self.window.current_engine_options[i]['name']] = widget.text()
|
job_json['args'][self.window.current_engine_options[i]['name']] = widget.text()
|
||||||
|
|
||||||
# determine if any cameras are checked
|
# determine if any cameras are checked
|
||||||
selected_cameras = []
|
selected_cameras = []
|
||||||
if self.window.cameras_list.count() and not self.window.cameras_group.isHidden():
|
if self.window.cameras_list.count() and not self.window.cameras_group.isHidden():
|
||||||
for index in range(self.window.cameras_list.count()):
|
for index in range(self.window.cameras_list.count()):
|
||||||
item = self.window.cameras_list.item(index)
|
item = self.window.cameras_list.item(index)
|
||||||
if item.checkState() == Qt.CheckState.Checked:
|
if item.checkState() == Qt.CheckState.Checked:
|
||||||
selected_cameras.append(item.text().rsplit('-', 1)[0].strip()) # cleanup to just camera name
|
selected_cameras.append(item.text().rsplit('-', 1)[0].strip()) # cleanup to just camera name
|
||||||
|
|
||||||
# process cameras into nested format
|
# process cameras into nested format
|
||||||
input_path = self.window.scene_file_input.text()
|
input_path = self.window.scene_file_input.text()
|
||||||
if selected_cameras:
|
if selected_cameras:
|
||||||
job_list = []
|
job_list = []
|
||||||
for cam in selected_cameras:
|
for cam in selected_cameras:
|
||||||
job_copy = copy.deepcopy(job_json)
|
job_copy = copy.deepcopy(job_json)
|
||||||
job_copy['args']['camera'] = cam
|
job_copy['args']['camera'] = cam
|
||||||
job_copy['name'] = pathlib.Path(input_path).stem.replace(' ', '_') + "-" + cam.replace(' ', '')
|
job_copy['name'] = job_copy['name'].replace(' ', '-') + "_" + cam.replace(' ', '')
|
||||||
job_list.append(job_copy)
|
job_copy['output_path'] = job_copy['name']
|
||||||
else:
|
job_list.append(job_copy)
|
||||||
job_list = [job_json]
|
else:
|
||||||
|
job_list = [job_json]
|
||||||
|
|
||||||
# presubmission tasks
|
# presubmission tasks
|
||||||
engine = EngineManager.engine_with_name(self.window.renderer_type.currentText().lower())
|
engine = EngineManager.engine_with_name(self.window.renderer_type.currentText().lower())
|
||||||
input_path = engine().perform_presubmission_tasks(input_path)
|
input_path = engine().perform_presubmission_tasks(input_path)
|
||||||
# submit
|
# submit
|
||||||
result = self.window.server_proxy.post_job_to_server(file_path=input_path, job_list=job_list,
|
err_msg = ""
|
||||||
callback=create_callback)
|
result = self.window.server_proxy.post_job_to_server(file_path=input_path, job_list=job_list,
|
||||||
self.message_signal.emit(result)
|
callback=create_callback)
|
||||||
|
if not (result and result.ok):
|
||||||
|
err_msg = "Error posting job to server."
|
||||||
|
|
||||||
|
self.message_signal.emit(err_msg)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
self.message_signal.emit(str(e))
|
||||||
|
|
||||||
|
|
||||||
class GetProjectInfoWorker(QThread):
|
class GetProjectInfoWorker(QThread):
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import sys
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from PyQt6.QtGui import QFont
|
from PyQt6.QtGui import QFont
|
||||||
@@ -16,7 +15,10 @@ class QSignalHandler(logging.Handler, QObject):
|
|||||||
|
|
||||||
def emit(self, record):
|
def emit(self, record):
|
||||||
msg = self.format(record)
|
msg = self.format(record)
|
||||||
self.new_record.emit(msg) # Emit signal
|
try:
|
||||||
|
self.new_record.emit(msg) # Emit signal
|
||||||
|
except RuntimeError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ConsoleWindow(QMainWindow):
|
class ConsoleWindow(QMainWindow):
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
''' app/ui/main_window.py '''
|
''' app/ui/main_window.py '''
|
||||||
|
import ast
|
||||||
import datetime
|
import datetime
|
||||||
import io
|
import io
|
||||||
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import subprocess
|
|
||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
@@ -16,20 +17,22 @@ from PyQt6.QtWidgets import QMainWindow, QWidget, QHBoxLayout, QListWidget, QTab
|
|||||||
QTableWidgetItem, QLabel, QVBoxLayout, QHeaderView, QMessageBox, QGroupBox, QPushButton, QListWidgetItem, \
|
QTableWidgetItem, QLabel, QVBoxLayout, QHeaderView, QMessageBox, QGroupBox, QPushButton, QListWidgetItem, \
|
||||||
QFileDialog
|
QFileDialog
|
||||||
|
|
||||||
|
from src.api.api_server import API_VERSION
|
||||||
from src.render_queue import RenderQueue
|
from src.render_queue import RenderQueue
|
||||||
from src.utilities.misc_helper import get_time_elapsed, resources_dir, is_localhost
|
from src.utilities.misc_helper import get_time_elapsed, resources_dir, is_localhost
|
||||||
from src.utilities.status_utils import RenderStatus
|
from src.utilities.status_utils import RenderStatus
|
||||||
from src.utilities.zeroconf_server import ZeroconfServer
|
from src.utilities.zeroconf_server import ZeroconfServer
|
||||||
from .add_job import NewRenderJobForm
|
from src.ui.add_job import NewRenderJobForm
|
||||||
from .console import ConsoleWindow
|
from src.ui.console import ConsoleWindow
|
||||||
from .engine_browser import EngineBrowserWindow
|
from src.ui.engine_browser import EngineBrowserWindow
|
||||||
from .log_viewer import LogViewer
|
from src.ui.log_viewer import LogViewer
|
||||||
from .widgets.menubar import MenuBar
|
from src.ui.widgets.menubar import MenuBar
|
||||||
from .widgets.proportional_image_label import ProportionalImageLabel
|
from src.ui.widgets.proportional_image_label import ProportionalImageLabel
|
||||||
from .widgets.statusbar import StatusBar
|
from src.ui.widgets.statusbar import StatusBar
|
||||||
from .widgets.toolbar import ToolBar
|
from src.ui.widgets.toolbar import ToolBar
|
||||||
from src.api.serverproxy_manager import ServerProxyManager
|
from src.api.serverproxy_manager import ServerProxyManager
|
||||||
from src.utilities.misc_helper import launch_url
|
from src.utilities.misc_helper import launch_url, iso_datestring_to_formatted_datestring
|
||||||
|
from src.version import APP_NAME
|
||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
|
|
||||||
@@ -53,6 +56,7 @@ class MainWindow(QMainWindow):
|
|||||||
self.server_info_ram = None
|
self.server_info_ram = None
|
||||||
self.server_info_cpu = None
|
self.server_info_cpu = None
|
||||||
self.server_info_os = None
|
self.server_info_os = None
|
||||||
|
self.server_info_gpu = None
|
||||||
self.server_info_hostname = None
|
self.server_info_hostname = None
|
||||||
self.engine_browser_window = None
|
self.engine_browser_window = None
|
||||||
self.server_info_group = None
|
self.server_info_group = None
|
||||||
@@ -63,7 +67,7 @@ class MainWindow(QMainWindow):
|
|||||||
self.buffer_handler = None
|
self.buffer_handler = None
|
||||||
|
|
||||||
# Window-Settings
|
# Window-Settings
|
||||||
self.setWindowTitle("Zordon")
|
self.setWindowTitle(APP_NAME)
|
||||||
self.setGeometry(100, 100, 900, 800)
|
self.setGeometry(100, 100, 900, 800)
|
||||||
central_widget = QWidget(self)
|
central_widget = QWidget(self)
|
||||||
self.setCentralWidget(central_widget)
|
self.setCentralWidget(central_widget)
|
||||||
@@ -121,6 +125,7 @@ class MainWindow(QMainWindow):
|
|||||||
self.server_info_os = QLabel()
|
self.server_info_os = QLabel()
|
||||||
self.server_info_cpu = QLabel()
|
self.server_info_cpu = QLabel()
|
||||||
self.server_info_ram = QLabel()
|
self.server_info_ram = QLabel()
|
||||||
|
self.server_info_gpu = QLabel()
|
||||||
server_info_engines_button = QPushButton("Render Engines")
|
server_info_engines_button = QPushButton("Render Engines")
|
||||||
server_info_engines_button.clicked.connect(self.engine_browser)
|
server_info_engines_button.clicked.connect(self.engine_browser)
|
||||||
server_info_layout = QVBoxLayout()
|
server_info_layout = QVBoxLayout()
|
||||||
@@ -128,6 +133,7 @@ class MainWindow(QMainWindow):
|
|||||||
server_info_layout.addWidget(self.server_info_os)
|
server_info_layout.addWidget(self.server_info_os)
|
||||||
server_info_layout.addWidget(self.server_info_cpu)
|
server_info_layout.addWidget(self.server_info_cpu)
|
||||||
server_info_layout.addWidget(self.server_info_ram)
|
server_info_layout.addWidget(self.server_info_ram)
|
||||||
|
server_info_layout.addWidget(self.server_info_gpu)
|
||||||
server_info_layout.addWidget(server_info_engines_button)
|
server_info_layout.addWidget(server_info_engines_button)
|
||||||
server_info_group.setLayout(server_info_layout)
|
server_info_group.setLayout(server_info_layout)
|
||||||
|
|
||||||
@@ -183,8 +189,13 @@ class MainWindow(QMainWindow):
|
|||||||
|
|
||||||
def __background_update(self):
|
def __background_update(self):
|
||||||
while True:
|
while True:
|
||||||
self.update_servers()
|
try:
|
||||||
self.fetch_jobs()
|
self.update_servers()
|
||||||
|
self.fetch_jobs()
|
||||||
|
except RuntimeError:
|
||||||
|
pass
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Uncaught exception in background update: {e}")
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
|
|
||||||
def closeEvent(self, event):
|
def closeEvent(self, event):
|
||||||
@@ -232,15 +243,42 @@ class MainWindow(QMainWindow):
|
|||||||
|
|
||||||
def update_server_info_display(self, hostname):
|
def update_server_info_display(self, hostname):
|
||||||
"""Updates the server information section of the UI."""
|
"""Updates the server information section of the UI."""
|
||||||
self.server_info_hostname.setText(hostname or "unknown")
|
self.server_info_hostname.setText(f"Name: {hostname}")
|
||||||
server_info = ZeroconfServer.get_hostname_properties(hostname)
|
server_info = ZeroconfServer.get_hostname_properties(hostname)
|
||||||
|
|
||||||
# Use the get method with defaults to avoid KeyError
|
# Use the get method with defaults to avoid KeyError
|
||||||
os_info = f"OS: {server_info.get('system_os', 'Unknown')} {server_info.get('system_os_version', '')}"
|
os_info = f"OS: {server_info.get('system_os', 'Unknown')} {server_info.get('system_os_version', '')}"
|
||||||
cpu_info = f"CPU: {server_info.get('system_cpu', 'Unknown')} - {server_info.get('system_cpu_cores', 'Unknown')} cores"
|
cleaned_cpu_name = server_info.get('system_cpu_brand', 'Unknown').replace(' CPU','').replace('(TM)','').replace('(R)', '')
|
||||||
|
cpu_info = f"CPU: {cleaned_cpu_name} ({server_info.get('system_cpu_cores', 'Unknown')} cores)"
|
||||||
|
memory_info = f"RAM: {server_info.get('system_memory', 'Unknown')} GB"
|
||||||
|
|
||||||
|
# Get and format GPU info
|
||||||
|
try:
|
||||||
|
gpu_list = ast.literal_eval(server_info.get('gpu_info', []))
|
||||||
|
|
||||||
|
# Format all GPUs
|
||||||
|
gpu_info_parts = []
|
||||||
|
for gpu in gpu_list:
|
||||||
|
gpu_name = gpu.get('name', 'Unknown').replace('(TM)','').replace('(R)', '')
|
||||||
|
gpu_memory = gpu.get('memory', 'Unknown')
|
||||||
|
|
||||||
|
# Add " GB" suffix if memory is a number
|
||||||
|
if isinstance(gpu_memory, (int, float)) or (isinstance(gpu_memory, str) and gpu_memory.isdigit()):
|
||||||
|
gpu_memory_str = f"{gpu_memory} GB"
|
||||||
|
else:
|
||||||
|
gpu_memory_str = str(gpu_memory)
|
||||||
|
|
||||||
|
gpu_info_parts.append(f"{gpu_name} ({gpu_memory_str})")
|
||||||
|
|
||||||
|
gpu_info = f"GPU: {', '.join(gpu_info_parts)}" if gpu_info_parts else "GPU: Unknown"
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error parsing GPU info: {e}")
|
||||||
|
gpu_info = "GPU: Unknown"
|
||||||
|
|
||||||
self.server_info_os.setText(os_info.strip())
|
self.server_info_os.setText(os_info.strip())
|
||||||
self.server_info_cpu.setText(cpu_info)
|
self.server_info_cpu.setText(cpu_info)
|
||||||
|
self.server_info_ram.setText(memory_info)
|
||||||
|
self.server_info_gpu.setText(gpu_info)
|
||||||
|
|
||||||
def fetch_jobs(self, clear_table=False):
|
def fetch_jobs(self, clear_table=False):
|
||||||
|
|
||||||
@@ -251,7 +289,7 @@ class MainWindow(QMainWindow):
|
|||||||
self.job_list_view.clear()
|
self.job_list_view.clear()
|
||||||
self.refresh_job_headers()
|
self.refresh_job_headers()
|
||||||
|
|
||||||
job_fetch = self.current_server_proxy.get_all_jobs(ignore_token=clear_table)
|
job_fetch = self.current_server_proxy.get_all_jobs(ignore_token=False)
|
||||||
if job_fetch:
|
if job_fetch:
|
||||||
num_jobs = len(job_fetch)
|
num_jobs = len(job_fetch)
|
||||||
self.job_list_view.setRowCount(num_jobs)
|
self.job_list_view.setRowCount(num_jobs)
|
||||||
@@ -271,10 +309,11 @@ class MainWindow(QMainWindow):
|
|||||||
renderer = f"{job.get('renderer', '')}-{job.get('renderer_version')}"
|
renderer = f"{job.get('renderer', '')}-{job.get('renderer_version')}"
|
||||||
priority = str(job.get('priority', ''))
|
priority = str(job.get('priority', ''))
|
||||||
total_frames = str(job.get('total_frames', ''))
|
total_frames = str(job.get('total_frames', ''))
|
||||||
|
date_created_string = iso_datestring_to_formatted_datestring(job['date_created'])
|
||||||
|
|
||||||
items = [QTableWidgetItem(job['id']), QTableWidgetItem(name), QTableWidgetItem(renderer),
|
items = [QTableWidgetItem(job['id']), QTableWidgetItem(name), QTableWidgetItem(renderer),
|
||||||
QTableWidgetItem(priority), QTableWidgetItem(display_status), QTableWidgetItem(time_elapsed),
|
QTableWidgetItem(priority), QTableWidgetItem(display_status), QTableWidgetItem(time_elapsed),
|
||||||
QTableWidgetItem(total_frames), QTableWidgetItem(job['date_created'])]
|
QTableWidgetItem(total_frames), QTableWidgetItem(date_created_string)]
|
||||||
|
|
||||||
for col, item in enumerate(items):
|
for col, item in enumerate(items):
|
||||||
self.job_list_view.setItem(row, col, item)
|
self.job_list_view.setItem(row, col, item)
|
||||||
@@ -320,7 +359,7 @@ class MainWindow(QMainWindow):
|
|||||||
current_status = self.job_list_view.item(selected_row.row(), 4).text()
|
current_status = self.job_list_view.item(selected_row.row(), 4).text()
|
||||||
|
|
||||||
# show / hide the stop button
|
# show / hide the stop button
|
||||||
show_stop_button = current_status.lower() == 'running'
|
show_stop_button = "%" in current_status
|
||||||
self.topbar.actions_call['Stop Job'].setEnabled(show_stop_button)
|
self.topbar.actions_call['Stop Job'].setEnabled(show_stop_button)
|
||||||
self.topbar.actions_call['Stop Job'].setVisible(show_stop_button)
|
self.topbar.actions_call['Stop Job'].setVisible(show_stop_button)
|
||||||
self.topbar.actions_call['Delete Job'].setEnabled(not show_stop_button)
|
self.topbar.actions_call['Delete Job'].setEnabled(not show_stop_button)
|
||||||
@@ -372,33 +411,41 @@ class MainWindow(QMainWindow):
|
|||||||
|
|
||||||
def load_image_path(self, image_path):
|
def load_image_path(self, image_path):
|
||||||
# Load and set the image using QPixmap
|
# Load and set the image using QPixmap
|
||||||
pixmap = QPixmap(image_path)
|
try:
|
||||||
if not pixmap:
|
pixmap = QPixmap(image_path)
|
||||||
logger.error("Error loading image")
|
if not pixmap:
|
||||||
return
|
logger.error("Error loading image")
|
||||||
self.image_label.setPixmap(pixmap)
|
return
|
||||||
|
self.image_label.setPixmap(pixmap)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error loading image path: {e}")
|
||||||
|
|
||||||
def load_image_data(self, pillow_image):
|
def load_image_data(self, pillow_image):
|
||||||
# Convert the Pillow Image to a QByteArray (byte buffer)
|
try:
|
||||||
byte_array = QByteArray()
|
# Convert the Pillow Image to a QByteArray (byte buffer)
|
||||||
buffer = QBuffer(byte_array)
|
byte_array = QByteArray()
|
||||||
buffer.open(QIODevice.OpenModeFlag.WriteOnly)
|
buffer = QBuffer(byte_array)
|
||||||
pillow_image.save(buffer, "PNG")
|
buffer.open(QIODevice.OpenModeFlag.WriteOnly)
|
||||||
buffer.close()
|
pillow_image.save(buffer, "PNG")
|
||||||
|
buffer.close()
|
||||||
|
|
||||||
# Create a QImage from the QByteArray
|
# Create a QImage from the QByteArray
|
||||||
image = QImage.fromData(byte_array)
|
image = QImage.fromData(byte_array)
|
||||||
|
|
||||||
# Create a QPixmap from the QImage
|
# Create a QPixmap from the QImage
|
||||||
pixmap = QPixmap.fromImage(image)
|
pixmap = QPixmap.fromImage(image)
|
||||||
|
|
||||||
if not pixmap:
|
if not pixmap:
|
||||||
logger.error("Error loading image")
|
logger.error("Error loading image")
|
||||||
return
|
return
|
||||||
self.image_label.setPixmap(pixmap)
|
self.image_label.setPixmap(pixmap)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error loading image data: {e}")
|
||||||
|
|
||||||
def update_servers(self):
|
def update_servers(self):
|
||||||
found_servers = list(set(ZeroconfServer.found_hostnames() + self.added_hostnames))
|
found_servers = list(set(ZeroconfServer.found_hostnames() + self.added_hostnames))
|
||||||
|
found_servers = [x for x in found_servers if ZeroconfServer.get_hostname_properties(x)['api_version'] == API_VERSION]
|
||||||
|
|
||||||
# Always make sure local hostname is first
|
# Always make sure local hostname is first
|
||||||
if found_servers and not is_localhost(found_servers[0]):
|
if found_servers and not is_localhost(found_servers[0]):
|
||||||
for hostname in found_servers:
|
for hostname in found_servers:
|
||||||
@@ -501,7 +548,7 @@ class MainWindow(QMainWindow):
|
|||||||
|
|
||||||
def stop_job(self, event):
|
def stop_job(self, event):
|
||||||
"""
|
"""
|
||||||
Event handler for the "Exit" button. Closes the application.
|
Event handler for the Stop Job button
|
||||||
"""
|
"""
|
||||||
job_ids = self.selected_job_ids()
|
job_ids = self.selected_job_ids()
|
||||||
if not job_ids:
|
if not job_ids:
|
||||||
@@ -511,14 +558,14 @@ class MainWindow(QMainWindow):
|
|||||||
job = next((job for job in self.current_server_proxy.get_all_jobs() if job.get('id') == job_ids[0]), None)
|
job = next((job for job in self.current_server_proxy.get_all_jobs() if job.get('id') == job_ids[0]), None)
|
||||||
if job:
|
if job:
|
||||||
display_name = job.get('name', os.path.basename(job.get('input_path', '')))
|
display_name = job.get('name', os.path.basename(job.get('input_path', '')))
|
||||||
message = f"Are you sure you want to delete the job:\n{display_name}?"
|
message = f"Are you sure you want to stop the job:\n{display_name}?"
|
||||||
else:
|
else:
|
||||||
return # Job not found, handle this case as needed
|
return # Job not found, handle this case as needed
|
||||||
else:
|
else:
|
||||||
message = f"Are you sure you want to delete these {len(job_ids)} jobs?"
|
message = f"Are you sure you want to stop these {len(job_ids)} jobs?"
|
||||||
|
|
||||||
# Display the message box and check the response in one go
|
# Display the message box and check the response in one go
|
||||||
msg_box = QMessageBox(QMessageBox.Icon.Warning, "Delete Job", message,
|
msg_box = QMessageBox(QMessageBox.Icon.Warning, "Stop Job", message,
|
||||||
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No, self)
|
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No, self)
|
||||||
|
|
||||||
if msg_box.exec() == QMessageBox.StandardButton.Yes:
|
if msg_box.exec() == QMessageBox.StandardButton.Yes:
|
||||||
@@ -554,7 +601,15 @@ class MainWindow(QMainWindow):
|
|||||||
self.fetch_jobs(clear_table=True)
|
self.fetch_jobs(clear_table=True)
|
||||||
|
|
||||||
def download_files(self, event):
|
def download_files(self, event):
|
||||||
pass
|
|
||||||
|
job_ids = self.selected_job_ids()
|
||||||
|
if not job_ids:
|
||||||
|
return
|
||||||
|
|
||||||
|
import webbrowser
|
||||||
|
download_url = (f"http://{self.current_server_proxy.hostname}:{self.current_server_proxy.port}"
|
||||||
|
f"/api/job/{job_ids[0]}/download_all")
|
||||||
|
webbrowser.open(download_url)
|
||||||
|
|
||||||
def open_files(self, event):
|
def open_files(self, event):
|
||||||
job_ids = self.selected_job_ids()
|
job_ids = self.selected_job_ids()
|
||||||
@@ -572,3 +627,21 @@ class MainWindow(QMainWindow):
|
|||||||
if file_name:
|
if file_name:
|
||||||
self.new_job_window = NewRenderJobForm(file_name)
|
self.new_job_window = NewRenderJobForm(file_name)
|
||||||
self.new_job_window.show()
|
self.new_job_window.show()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
# lazy load GUI frameworks
|
||||||
|
from PyQt6.QtWidgets import QApplication
|
||||||
|
|
||||||
|
# load application
|
||||||
|
# QtCore.QCoreApplication.setAttribute(QtCore.Qt.ApplicationAttribute.AA_MacDontSwapCtrlAndMeta)
|
||||||
|
app: QApplication = QApplication(sys.argv)
|
||||||
|
|
||||||
|
# configure main main_window
|
||||||
|
main_window = MainWindow()
|
||||||
|
# main_window.buffer_handler = buffer_handler
|
||||||
|
app.setActiveWindow(main_window)
|
||||||
|
|
||||||
|
main_window.show()
|
||||||
|
|
||||||
|
sys.exit(app.exec())
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
''' app/ui/widgets/menubar.py '''
|
''' app/ui/widgets/menubar.py '''
|
||||||
from PyQt6.QtWidgets import QMenuBar
|
from PyQt6.QtGui import QAction
|
||||||
|
from PyQt6.QtWidgets import QMenuBar, QApplication, QMessageBox, QDialog, QVBoxLayout, QLabel, QPushButton
|
||||||
|
|
||||||
|
|
||||||
class MenuBar(QMenuBar):
|
class MenuBar(QMenuBar):
|
||||||
@@ -12,12 +13,89 @@ class MenuBar(QMenuBar):
|
|||||||
|
|
||||||
def __init__(self, parent=None) -> None:
|
def __init__(self, parent=None) -> None:
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
|
|
||||||
|
# setup menus
|
||||||
file_menu = self.addMenu("File")
|
file_menu = self.addMenu("File")
|
||||||
# edit_menu = self.addMenu("Edit")
|
# edit_menu = self.addMenu("Edit")
|
||||||
# view_menu = self.addMenu("View")
|
# view_menu = self.addMenu("View")
|
||||||
# help_menu = self.addMenu("Help")
|
help_menu = self.addMenu("Help")
|
||||||
|
|
||||||
# Add actions to the menus
|
# --file menu--
|
||||||
# file_menu.addAction(self.parent().topbar.actions_call["Open"]) # type: ignore
|
# new job
|
||||||
# file_menu.addAction(self.parent().topbar.actions_call["Save"]) # type: ignore
|
new_job_action = QAction("New Job...", self)
|
||||||
# file_menu.addAction(self.parent().topbar.actions_call["Exit"]) # type: ignore
|
new_job_action.setShortcut(f'Ctrl+N')
|
||||||
|
new_job_action.triggered.connect(self.new_job)
|
||||||
|
file_menu.addAction(new_job_action)
|
||||||
|
# settings
|
||||||
|
settings_action = QAction("Settings...", self)
|
||||||
|
settings_action.triggered.connect(self.show_settings)
|
||||||
|
settings_action.setShortcut(f'Ctrl+,')
|
||||||
|
# file_menu.addAction(settings_action) # todo: enable once we have a setting screen
|
||||||
|
# exit
|
||||||
|
exit_action = QAction('&Exit', self)
|
||||||
|
exit_action.setShortcut('Ctrl+Q')
|
||||||
|
exit_action.triggered.connect(QApplication.instance().quit)
|
||||||
|
file_menu.addAction(exit_action)
|
||||||
|
|
||||||
|
# --help menu--
|
||||||
|
about_action = QAction("About", self)
|
||||||
|
about_action.triggered.connect(self.show_about)
|
||||||
|
help_menu.addAction(about_action)
|
||||||
|
update_action = QAction("Check for Updates...", self)
|
||||||
|
update_action.triggered.connect(self.check_for_updates)
|
||||||
|
help_menu.addAction(update_action)
|
||||||
|
|
||||||
|
def new_job(self):
|
||||||
|
self.parent().new_job()
|
||||||
|
|
||||||
|
def show_settings(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def show_about():
|
||||||
|
from src.ui.about_window import AboutDialog
|
||||||
|
dialog = AboutDialog()
|
||||||
|
dialog.exec()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def check_for_updates():
|
||||||
|
from src.utilities.misc_helper import check_for_updates
|
||||||
|
from src.version import APP_NAME, APP_VERSION, APP_REPO_NAME, APP_REPO_OWNER
|
||||||
|
found_update = check_for_updates(APP_REPO_NAME, APP_REPO_OWNER, APP_NAME, APP_VERSION)
|
||||||
|
if found_update:
|
||||||
|
dialog = UpdateDialog(found_update, APP_VERSION)
|
||||||
|
dialog.exec()
|
||||||
|
else:
|
||||||
|
QMessageBox.information(None, "No Update", "No updates available.")
|
||||||
|
|
||||||
|
|
||||||
|
class UpdateDialog(QDialog):
|
||||||
|
def __init__(self, release_info, current_version, parent=None):
|
||||||
|
super().__init__(parent)
|
||||||
|
self.setWindowTitle(f"Update Available ({current_version} -> {release_info['tag_name']})")
|
||||||
|
|
||||||
|
layout = QVBoxLayout()
|
||||||
|
label = QLabel(f"A new version ({release_info['tag_name']}) is available! Current version: {current_version}")
|
||||||
|
layout.addWidget(label)
|
||||||
|
|
||||||
|
# Label to show the release notes
|
||||||
|
description = QLabel(release_info["body"])
|
||||||
|
layout.addWidget(description)
|
||||||
|
|
||||||
|
# Button to download the latest version
|
||||||
|
download_button = QPushButton(f"Download Latest Version ({release_info['tag_name']})")
|
||||||
|
download_button.clicked.connect(lambda: self.open_url(release_info["html_url"]))
|
||||||
|
layout.addWidget(download_button)
|
||||||
|
|
||||||
|
# OK button to dismiss the dialog
|
||||||
|
ok_button = QPushButton("Dismiss")
|
||||||
|
ok_button.clicked.connect(self.accept) # Close the dialog when clicked
|
||||||
|
layout.addWidget(ok_button)
|
||||||
|
|
||||||
|
self.setLayout(layout)
|
||||||
|
|
||||||
|
def open_url(self, url):
|
||||||
|
from PyQt6.QtCore import QUrl
|
||||||
|
from PyQt6.QtGui import QDesktopServices
|
||||||
|
QDesktopServices.openUrl(QUrl(url))
|
||||||
|
self.accept()
|
||||||
|
|||||||
@@ -32,20 +32,23 @@ class StatusBar(QStatusBar):
|
|||||||
|
|
||||||
# Check for status change every 1s on background thread
|
# Check for status change every 1s on background thread
|
||||||
while True:
|
while True:
|
||||||
new_status = proxy.status()
|
try:
|
||||||
new_image_name = image_names.get(new_status, 'Synchronize.png')
|
# update status label - get download status
|
||||||
image_path = os.path.join(resources_dir(), new_image_name)
|
new_status = proxy.status()
|
||||||
self.label.setPixmap((QPixmap(image_path).scaled(16, 16, Qt.AspectRatioMode.KeepAspectRatio)))
|
if EngineManager.download_tasks:
|
||||||
|
if len(EngineManager.download_tasks) == 1:
|
||||||
|
task = EngineManager.download_tasks[0]
|
||||||
|
new_status = f"{new_status} | Downloading {task.engine.capitalize()} {task.version}..."
|
||||||
|
else:
|
||||||
|
new_status = f"{new_status} | Downloading {len(EngineManager.download_tasks)} engines"
|
||||||
|
self.messageLabel.setText(new_status)
|
||||||
|
|
||||||
# add download status
|
# update status image
|
||||||
if EngineManager.download_tasks:
|
new_image_name = image_names.get(new_status, 'Synchronize.png')
|
||||||
if len(EngineManager.download_tasks) == 1:
|
new_image_path = os.path.join(resources_dir(), new_image_name)
|
||||||
task = EngineManager.download_tasks[0]
|
self.label.setPixmap((QPixmap(new_image_path).scaled(16, 16, Qt.AspectRatioMode.KeepAspectRatio)))
|
||||||
new_status = f"{new_status} | Downloading {task.engine.capitalize()} {task.version}..."
|
except RuntimeError: # ignore runtime errors during shutdown
|
||||||
else:
|
pass
|
||||||
new_status = f"{new_status} | Downloading {len(EngineManager.download_tasks)} engines"
|
|
||||||
|
|
||||||
self.messageLabel.setText(new_status)
|
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
background_thread = threading.Thread(target=background_update,)
|
background_thread = threading.Thread(target=background_update,)
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ class Config:
|
|||||||
max_content_path = 100000000
|
max_content_path = 100000000
|
||||||
server_log_level = 'debug'
|
server_log_level = 'debug'
|
||||||
log_buffer_length = 250
|
log_buffer_length = 250
|
||||||
subjob_connection_timeout = 120
|
worker_process_timeout = 120
|
||||||
flask_log_level = 'error'
|
flask_log_level = 'error'
|
||||||
flask_debug_enable = False
|
flask_debug_enable = False
|
||||||
queue_eval_seconds = 1
|
queue_eval_seconds = 1
|
||||||
@@ -28,7 +28,7 @@ class Config:
|
|||||||
cls.max_content_path = cfg.get('max_content_path', cls.max_content_path)
|
cls.max_content_path = cfg.get('max_content_path', cls.max_content_path)
|
||||||
cls.server_log_level = cfg.get('server_log_level', cls.server_log_level)
|
cls.server_log_level = cfg.get('server_log_level', cls.server_log_level)
|
||||||
cls.log_buffer_length = cfg.get('log_buffer_length', cls.log_buffer_length)
|
cls.log_buffer_length = cfg.get('log_buffer_length', cls.log_buffer_length)
|
||||||
cls.subjob_connection_timeout = cfg.get('subjob_connection_timeout', cls.subjob_connection_timeout)
|
cls.worker_process_timeout = cfg.get('worker_process_timeout', cls.worker_process_timeout)
|
||||||
cls.flask_log_level = cfg.get('flask_log_level', cls.flask_log_level)
|
cls.flask_log_level = cfg.get('flask_log_level', cls.flask_log_level)
|
||||||
cls.flask_debug_enable = cfg.get('flask_debug_enable', cls.flask_debug_enable)
|
cls.flask_debug_enable = cfg.get('flask_debug_enable', cls.flask_debug_enable)
|
||||||
cls.queue_eval_seconds = cfg.get('queue_eval_seconds', cls.queue_eval_seconds)
|
cls.queue_eval_seconds = cfg.get('queue_eval_seconds', cls.queue_eval_seconds)
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import logging
|
import logging
|
||||||
|
import json
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
import socket
|
import socket
|
||||||
import string
|
import string
|
||||||
@@ -159,6 +161,33 @@ def copy_directory_contents(src_dir, dst_dir):
|
|||||||
shutil.copy2(src_path, dst_path)
|
shutil.copy2(src_path, dst_path)
|
||||||
|
|
||||||
|
|
||||||
|
def check_for_updates(repo_name, repo_owner, app_name, current_version):
|
||||||
|
def get_github_releases(owner, repo):
|
||||||
|
import requests
|
||||||
|
url = f"https://api.github.com/repos/{owner}/{repo}/releases"
|
||||||
|
try:
|
||||||
|
response = requests.get(url, timeout=3)
|
||||||
|
response.raise_for_status()
|
||||||
|
releases = response.json()
|
||||||
|
return releases
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error checking for updates: {e}")
|
||||||
|
return []
|
||||||
|
|
||||||
|
releases = get_github_releases(repo_owner, repo_name)
|
||||||
|
if not releases:
|
||||||
|
return
|
||||||
|
|
||||||
|
latest_version = releases[0]
|
||||||
|
latest_version_tag = latest_version['tag_name']
|
||||||
|
|
||||||
|
from packaging import version
|
||||||
|
if version.parse(latest_version_tag) > version.parse(current_version):
|
||||||
|
logger.info(f"Newer version of {app_name} available. "
|
||||||
|
f"Latest: {latest_version_tag}, Current: {current_version}")
|
||||||
|
return latest_version
|
||||||
|
|
||||||
|
|
||||||
def is_localhost(comparison_hostname):
|
def is_localhost(comparison_hostname):
|
||||||
# this is necessary because socket.gethostname() does not always include '.local' - This is a sanitized comparison
|
# this is necessary because socket.gethostname() does not always include '.local' - This is a sanitized comparison
|
||||||
try:
|
try:
|
||||||
@@ -183,3 +212,136 @@ def num_to_alphanumeric(num):
|
|||||||
result += characters[remainder]
|
result += characters[remainder]
|
||||||
|
|
||||||
return result[::-1] # Reverse the result to get the correct alphanumeric string
|
return result[::-1] # Reverse the result to get the correct alphanumeric string
|
||||||
|
|
||||||
|
|
||||||
|
def iso_datestring_to_formatted_datestring(iso_date_string):
|
||||||
|
from dateutil import parser
|
||||||
|
import pytz
|
||||||
|
|
||||||
|
# Parse the ISO date string into a datetime object and convert timezones
|
||||||
|
date = parser.isoparse(iso_date_string).astimezone(pytz.UTC)
|
||||||
|
local_timezone = datetime.now().astimezone().tzinfo
|
||||||
|
date_local = date.astimezone(local_timezone)
|
||||||
|
|
||||||
|
# Format the date to the desired readable yet sortable format with 12-hour time
|
||||||
|
formatted_date = date_local.strftime('%Y-%m-%d %I:%M %p')
|
||||||
|
|
||||||
|
return formatted_date
|
||||||
|
|
||||||
|
def get_gpu_info():
|
||||||
|
"""Cross-platform GPU information retrieval"""
|
||||||
|
|
||||||
|
def get_windows_gpu_info():
|
||||||
|
"""Get GPU info on Windows"""
|
||||||
|
try:
|
||||||
|
result = subprocess.run(
|
||||||
|
['wmic', 'path', 'win32_videocontroller', 'get', 'name,AdapterRAM', '/format:list'],
|
||||||
|
capture_output=True, text=True, timeout=5
|
||||||
|
)
|
||||||
|
|
||||||
|
# Virtual adapters to exclude
|
||||||
|
virtual_adapters = [
|
||||||
|
'virtual', 'rdp', 'hyper-v', 'microsoft basic', 'basic display',
|
||||||
|
'vga compatible', 'dummy', 'nvfbc', 'nvencode'
|
||||||
|
]
|
||||||
|
|
||||||
|
gpus = []
|
||||||
|
current_gpu = None
|
||||||
|
|
||||||
|
for line in result.stdout.strip().split('\n'):
|
||||||
|
line = line.strip()
|
||||||
|
if not line:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if line.startswith('Name='):
|
||||||
|
if current_gpu and current_gpu.get('name'):
|
||||||
|
gpus.append(current_gpu)
|
||||||
|
gpu_name = line.replace('Name=', '').strip()
|
||||||
|
|
||||||
|
# Skip virtual adapters
|
||||||
|
if any(virtual in gpu_name.lower() for virtual in virtual_adapters):
|
||||||
|
current_gpu = None
|
||||||
|
else:
|
||||||
|
current_gpu = {'name': gpu_name, 'memory': 'Integrated'}
|
||||||
|
|
||||||
|
elif line.startswith('AdapterRAM=') and current_gpu:
|
||||||
|
vram_bytes_str = line.replace('AdapterRAM=', '').strip()
|
||||||
|
if vram_bytes_str and vram_bytes_str != '0':
|
||||||
|
try:
|
||||||
|
vram_gb = int(vram_bytes_str) / (1024**3)
|
||||||
|
current_gpu['memory'] = round(vram_gb, 2)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if current_gpu and current_gpu.get('name'):
|
||||||
|
gpus.append(current_gpu)
|
||||||
|
|
||||||
|
return gpus if gpus else [{'name': 'Unknown GPU', 'memory': 'Unknown'}]
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Failed to get Windows GPU info: {e}")
|
||||||
|
return [{'name': 'Unknown GPU', 'memory': 'Unknown'}]
|
||||||
|
|
||||||
|
def get_macos_gpu_info():
|
||||||
|
"""Get GPU info on macOS (works with Apple Silicon)"""
|
||||||
|
try:
|
||||||
|
result = subprocess.run(['system_profiler', 'SPDisplaysDataType', '-json'],
|
||||||
|
capture_output=True, text=True, timeout=5)
|
||||||
|
data = json.loads(result.stdout)
|
||||||
|
|
||||||
|
gpus = []
|
||||||
|
displays = data.get('SPDisplaysDataType', [])
|
||||||
|
for display in displays:
|
||||||
|
if 'sppci_model' in display:
|
||||||
|
gpus.append({
|
||||||
|
'name': display.get('sppci_model', 'Unknown GPU'),
|
||||||
|
'memory': display.get('sppci_vram', 'Integrated'),
|
||||||
|
})
|
||||||
|
return gpus if gpus else [{'name': 'Apple Silicon GPU', 'memory': 'Integrated'}]
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Failed to get macOS GPU info: {e}")
|
||||||
|
return [{'name': 'Unknown GPU', 'memory': 'Unknown'}]
|
||||||
|
|
||||||
|
def get_linux_gpu_info():
|
||||||
|
gpus = []
|
||||||
|
try:
|
||||||
|
# Run plain lspci and filter for GPU-related lines
|
||||||
|
output = subprocess.check_output(
|
||||||
|
["lspci"], universal_newlines=True, stderr=subprocess.DEVNULL
|
||||||
|
)
|
||||||
|
for line in output.splitlines():
|
||||||
|
if any(keyword in line.lower() for keyword in ["vga", "3d", "display"]):
|
||||||
|
# Extract the part after the colon (vendor + model)
|
||||||
|
if ":" in line:
|
||||||
|
name_part = line.split(":", 1)[1].strip()
|
||||||
|
# Clean up common extras like (rev xx) or (prog-if ...)
|
||||||
|
name = name_part.split("(")[0].split("controller:")[-1].strip()
|
||||||
|
vendor = "Unknown"
|
||||||
|
if "nvidia" in name.lower():
|
||||||
|
vendor = "NVIDIA"
|
||||||
|
elif "amd" in name.lower() or "ati" in name.lower():
|
||||||
|
vendor = "AMD"
|
||||||
|
elif "intel" in name.lower():
|
||||||
|
vendor = "Intel"
|
||||||
|
|
||||||
|
gpus.append({
|
||||||
|
"name": name,
|
||||||
|
"vendor": vendor,
|
||||||
|
"memory": "Unknown"
|
||||||
|
})
|
||||||
|
except FileNotFoundError:
|
||||||
|
print("lspci not found. Install pciutils: sudo apt install pciutils")
|
||||||
|
return []
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error running lspci: {e}")
|
||||||
|
return []
|
||||||
|
|
||||||
|
return gpus
|
||||||
|
|
||||||
|
system = platform.system()
|
||||||
|
|
||||||
|
if system == 'Darwin': # macOS
|
||||||
|
return get_macos_gpu_info()
|
||||||
|
elif system == 'Windows':
|
||||||
|
return get_windows_gpu_info()
|
||||||
|
else: # Assume Linux or other
|
||||||
|
return get_linux_gpu_info()
|
||||||
|
|||||||
@@ -1,47 +1,200 @@
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import zipfile
|
||||||
import threading
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
|
|
||||||
from src.utilities.ffmpeg_helper import generate_thumbnail, save_first_frame
|
import requests
|
||||||
|
|
||||||
|
from src.api.server_proxy import RenderServerProxy
|
||||||
|
from src.utilities.misc_helper import get_file_size_human
|
||||||
|
from src.utilities.zeroconf_server import ZeroconfServer
|
||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
def generate_thumbnail_for_job(job, thumb_video_path, thumb_image_path, max_width=320):
|
def download_missing_frames_from_subjob(local_job, subjob_id, subjob_hostname):
|
||||||
|
success = True
|
||||||
|
try:
|
||||||
|
local_files = [os.path.basename(x) for x in local_job.file_list()]
|
||||||
|
subjob_proxy = RenderServerProxy(subjob_hostname)
|
||||||
|
subjob_files = subjob_proxy.get_job_files_list(job_id=subjob_id) or []
|
||||||
|
|
||||||
# Simple thread to generate thumbs in background
|
for subjob_filename in subjob_files:
|
||||||
def generate_thumb_thread(source):
|
if subjob_filename not in local_files:
|
||||||
in_progress_path = thumb_video_path + '_IN-PROGRESS'
|
try:
|
||||||
subprocess.run(['touch', in_progress_path])
|
logger.debug(f"Downloading new file '{subjob_filename}' from {subjob_hostname}")
|
||||||
try:
|
local_save_path = os.path.join(os.path.dirname(local_job.output_path), subjob_filename)
|
||||||
logger.debug(f"Generating video thumbnail for {source}")
|
subjob_proxy.download_job_file(job_id=subjob_id, job_filename=subjob_filename,
|
||||||
generate_thumbnail(source_path=source, dest_path=thumb_video_path, max_width=max_width)
|
save_path=local_save_path)
|
||||||
except subprocess.CalledProcessError as err:
|
logger.debug(f'Downloaded successfully - {local_save_path}')
|
||||||
logger.error(f"Error generating video thumbnail for {source}: {err}")
|
except Exception as e:
|
||||||
|
logger.error(f"Error downloading file '{subjob_filename}' from {subjob_hostname}: {e}")
|
||||||
|
success = False
|
||||||
|
except Exception as e:
|
||||||
|
logger.exception(f'Uncaught exception while trying to download from subjob: {e}')
|
||||||
|
success = False
|
||||||
|
return success
|
||||||
|
|
||||||
try:
|
|
||||||
os.remove(in_progress_path)
|
|
||||||
except FileNotFoundError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
# Determine best source file to use for thumbs
|
def download_all_from_subjob(local_job, subjob_id, subjob_hostname):
|
||||||
source_files = job.file_list() or [job.input_path]
|
"""
|
||||||
if source_files:
|
Downloads and extracts files from a completed subjob on a remote server.
|
||||||
video_formats = ['.mp4', '.mov', '.avi', '.mpg', '.mpeg', '.mxf', '.m4v', 'mkv']
|
|
||||||
image_formats = ['.jpg', '.png', '.exr']
|
|
||||||
|
|
||||||
image_files = [f for f in source_files if os.path.splitext(f)[-1].lower() in image_formats]
|
Parameters:
|
||||||
video_files = [f for f in source_files if os.path.splitext(f)[-1].lower() in video_formats]
|
local_job (BaseRenderWorker): The local parent job worker.
|
||||||
|
subjob_id (str or int): The ID of the subjob.
|
||||||
|
subjob_hostname (str): The hostname of the remote server where the subjob is located.
|
||||||
|
|
||||||
if (video_files or image_files) and not os.path.exists(thumb_image_path):
|
Returns:
|
||||||
|
bool: True if the files have been downloaded and extracted successfully, False otherwise.
|
||||||
|
"""
|
||||||
|
|
||||||
|
child_key = f'{subjob_id}@{subjob_hostname}'
|
||||||
|
logname = f"{local_job.id}:{child_key}"
|
||||||
|
zip_file_path = local_job.output_path + f'_{subjob_hostname}_{subjob_id}.zip'
|
||||||
|
|
||||||
|
# download zip file from server
|
||||||
|
try:
|
||||||
|
local_job.children[child_key]['download_status'] = 'working'
|
||||||
|
logger.info(f"Downloading completed subjob files from {subjob_hostname} to localhost")
|
||||||
|
RenderServerProxy(subjob_hostname).download_all_job_files(subjob_id, zip_file_path)
|
||||||
|
logger.info(f"File transfer complete for {logname} - Transferred {get_file_size_human(zip_file_path)}")
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error downloading files from remote server: {e}")
|
||||||
|
local_job.children[child_key]['download_status'] = 'failed'
|
||||||
|
return False
|
||||||
|
|
||||||
|
# extract zip
|
||||||
|
try:
|
||||||
|
logger.debug(f"Extracting zip file: {zip_file_path}")
|
||||||
|
extract_path = os.path.dirname(zip_file_path)
|
||||||
|
with zipfile.ZipFile(zip_file_path, 'r') as zip_ref:
|
||||||
|
zip_ref.extractall(extract_path)
|
||||||
|
logger.info(f"Successfully extracted zip to: {extract_path}")
|
||||||
|
os.remove(zip_file_path)
|
||||||
|
local_job.children[child_key]['download_status'] = 'complete'
|
||||||
|
except Exception as e:
|
||||||
|
logger.exception(f"Exception extracting zip file: {e}")
|
||||||
|
local_job.children[child_key]['download_status'] = 'failed'
|
||||||
|
|
||||||
|
return local_job.children[child_key].get('download_status', None) == 'complete'
|
||||||
|
|
||||||
|
|
||||||
|
def distribute_server_work(start_frame, end_frame, available_servers, method='evenly'):
|
||||||
|
"""
|
||||||
|
Splits the frame range among available servers proportionally based on their performance (CPU count).
|
||||||
|
|
||||||
|
Args:
|
||||||
|
start_frame (int): The start frame number of the animation to be rendered.
|
||||||
|
end_frame (int): The end frame number of the animation to be rendered.
|
||||||
|
available_servers (list): A list of available server dictionaries. Each server dictionary should include
|
||||||
|
'hostname' and 'cpu_count' keys (see find_available_servers).
|
||||||
|
method (str, optional): Specifies the distribution method. Possible values are 'cpu_benchmark', 'cpu_count'
|
||||||
|
and 'evenly'.
|
||||||
|
Defaults to 'cpu_benchmark'.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
list: A list of server dictionaries where each dictionary includes the frame range and total number of
|
||||||
|
frames to be rendered by the server.
|
||||||
|
"""
|
||||||
|
# Calculate respective frames for each server
|
||||||
|
def divide_frames_by_cpu_count(frame_start, frame_end, servers):
|
||||||
|
total_frames = frame_end - frame_start + 1
|
||||||
|
total_cpus = sum(server['cpu_count'] for server in servers)
|
||||||
|
|
||||||
|
frame_ranges = {}
|
||||||
|
current_frame = frame_start
|
||||||
|
allocated_frames = 0
|
||||||
|
|
||||||
|
for i, server in enumerate(servers):
|
||||||
|
if i == len(servers) - 1: # if it's the last server
|
||||||
|
# Give all remaining frames to the last server
|
||||||
|
num_frames = total_frames - allocated_frames
|
||||||
|
else:
|
||||||
|
num_frames = round((server['cpu_count'] / total_cpus) * total_frames)
|
||||||
|
allocated_frames += num_frames
|
||||||
|
|
||||||
|
frame_end_for_server = current_frame + num_frames - 1
|
||||||
|
|
||||||
|
if current_frame <= frame_end_for_server:
|
||||||
|
frame_ranges[server['hostname']] = (current_frame, frame_end_for_server)
|
||||||
|
current_frame = frame_end_for_server + 1
|
||||||
|
|
||||||
|
return frame_ranges
|
||||||
|
|
||||||
|
def divide_frames_by_benchmark(frame_start, frame_end, servers):
|
||||||
|
|
||||||
|
def fetch_benchmark(server):
|
||||||
try:
|
try:
|
||||||
path_of_source = image_files[0] if image_files else video_files[0]
|
benchmark = requests.get(f'http://{server["hostname"]}:{ZeroconfServer.server_port}'
|
||||||
logger.debug(f"Generating image thumbnail for {path_of_source}")
|
f'/api/cpu_benchmark').text
|
||||||
save_first_frame(source_path=path_of_source, dest_path=thumb_image_path, max_width=max_width)
|
server['cpu_benchmark'] = benchmark
|
||||||
except Exception as e:
|
logger.debug(f'Benchmark for {server["hostname"]}: {benchmark}')
|
||||||
logger.error(f"Exception saving first frame: {e}")
|
except requests.exceptions.RequestException as e:
|
||||||
|
logger.error(f'Error fetching benchmark for {server["hostname"]}: {e}')
|
||||||
|
|
||||||
if video_files and not os.path.exists(thumb_video_path):
|
# Number of threads to use (can adjust based on your needs or number of servers)
|
||||||
x = threading.Thread(target=generate_thumb_thread, args=(video_files[0],))
|
threads = len(servers)
|
||||||
x.start()
|
|
||||||
|
with ThreadPoolExecutor(max_workers=threads) as executor:
|
||||||
|
executor.map(fetch_benchmark, servers)
|
||||||
|
|
||||||
|
total_frames = frame_end - frame_start + 1
|
||||||
|
total_performance = sum(int(server['cpu_benchmark']) for server in servers)
|
||||||
|
|
||||||
|
frame_ranges = {}
|
||||||
|
current_frame = frame_start
|
||||||
|
allocated_frames = 0
|
||||||
|
|
||||||
|
for i, server in enumerate(servers):
|
||||||
|
if i == len(servers) - 1: # if it's the last server
|
||||||
|
# Give all remaining frames to the last server
|
||||||
|
num_frames = total_frames - allocated_frames
|
||||||
|
else:
|
||||||
|
num_frames = round((int(server['cpu_benchmark']) / total_performance) * total_frames)
|
||||||
|
allocated_frames += num_frames
|
||||||
|
|
||||||
|
frame_end_for_server = current_frame + num_frames - 1
|
||||||
|
|
||||||
|
if current_frame <= frame_end_for_server:
|
||||||
|
frame_ranges[server['hostname']] = (current_frame, frame_end_for_server)
|
||||||
|
current_frame = frame_end_for_server + 1
|
||||||
|
|
||||||
|
return frame_ranges
|
||||||
|
|
||||||
|
def divide_frames_equally(frame_start, frame_end, servers):
|
||||||
|
frame_range = frame_end - frame_start + 1
|
||||||
|
frames_per_server = frame_range // len(servers)
|
||||||
|
leftover_frames = frame_range % len(servers)
|
||||||
|
|
||||||
|
frame_ranges = {}
|
||||||
|
current_start = frame_start
|
||||||
|
for i, server in enumerate(servers):
|
||||||
|
current_end = current_start + frames_per_server - 1
|
||||||
|
if leftover_frames > 0:
|
||||||
|
current_end += 1
|
||||||
|
leftover_frames -= 1
|
||||||
|
if current_start <= current_end:
|
||||||
|
frame_ranges[server['hostname']] = (current_start, current_end)
|
||||||
|
current_start = current_end + 1
|
||||||
|
|
||||||
|
return frame_ranges
|
||||||
|
|
||||||
|
if len(available_servers) == 1:
|
||||||
|
breakdown = {available_servers[0]['hostname']: (start_frame, end_frame)}
|
||||||
|
else:
|
||||||
|
logger.debug(f'Splitting between {len(available_servers)} servers by {method} method')
|
||||||
|
if method == 'evenly':
|
||||||
|
breakdown = divide_frames_equally(start_frame, end_frame, available_servers)
|
||||||
|
elif method == 'cpu_benchmark':
|
||||||
|
breakdown = divide_frames_by_benchmark(start_frame, end_frame, available_servers)
|
||||||
|
elif method == 'cpu_count':
|
||||||
|
breakdown = divide_frames_by_cpu_count(start_frame, end_frame, available_servers)
|
||||||
|
else:
|
||||||
|
raise ValueError(f"Invalid distribution method: {method}")
|
||||||
|
|
||||||
|
server_breakdown = [server for server in available_servers if breakdown.get(server['hostname']) is not None]
|
||||||
|
for server in server_breakdown:
|
||||||
|
server['frame_range'] = breakdown[server['hostname']]
|
||||||
|
server['total_frames'] = breakdown[server['hostname']][-1] - breakdown[server['hostname']][0] + 1
|
||||||
|
return server_breakdown
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ import logging
|
|||||||
import socket
|
import socket
|
||||||
|
|
||||||
from pubsub import pub
|
from pubsub import pub
|
||||||
from zeroconf import Zeroconf, ServiceInfo, ServiceBrowser, ServiceStateChange, NonUniqueNameException
|
from zeroconf import Zeroconf, ServiceInfo, ServiceBrowser, ServiceStateChange, NonUniqueNameException, \
|
||||||
|
NotRunningException
|
||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
|
|
||||||
@@ -31,12 +32,16 @@ class ZeroconfServer:
|
|||||||
def start(cls, listen_only=False):
|
def start(cls, listen_only=False):
|
||||||
if not cls.service_type:
|
if not cls.service_type:
|
||||||
raise RuntimeError("The 'configure' method must be run before starting the zeroconf server")
|
raise RuntimeError("The 'configure' method must be run before starting the zeroconf server")
|
||||||
if not listen_only:
|
elif not listen_only:
|
||||||
|
logger.debug(f"Starting zeroconf service")
|
||||||
cls._register_service()
|
cls._register_service()
|
||||||
|
else:
|
||||||
|
logger.debug(f"Starting zeroconf service - Listen only mode")
|
||||||
cls._browse_services()
|
cls._browse_services()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def stop(cls):
|
def stop(cls):
|
||||||
|
logger.debug("Stopping zeroconf service")
|
||||||
cls._unregister_service()
|
cls._unregister_service()
|
||||||
cls.zeroconf.close()
|
cls.zeroconf.close()
|
||||||
|
|
||||||
@@ -73,15 +78,18 @@ class ZeroconfServer:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _on_service_discovered(cls, zeroconf, service_type, name, state_change):
|
def _on_service_discovered(cls, zeroconf, service_type, name, state_change):
|
||||||
info = zeroconf.get_service_info(service_type, name)
|
try:
|
||||||
hostname = name.split(f'.{cls.service_type}')[0]
|
info = zeroconf.get_service_info(service_type, name)
|
||||||
logger.debug(f"Zeroconf: {hostname} {state_change}")
|
hostname = name.split(f'.{cls.service_type}')[0]
|
||||||
if service_type == cls.service_type:
|
logger.debug(f"Zeroconf: {hostname} {state_change}")
|
||||||
if state_change == ServiceStateChange.Added or state_change == ServiceStateChange.Updated:
|
if service_type == cls.service_type:
|
||||||
cls.client_cache[hostname] = info
|
if state_change == ServiceStateChange.Added or state_change == ServiceStateChange.Updated:
|
||||||
else:
|
cls.client_cache[hostname] = info
|
||||||
cls.client_cache.pop(hostname)
|
else:
|
||||||
pub.sendMessage('zeroconf_state_change', hostname=hostname, state_change=state_change)
|
cls.client_cache.pop(hostname)
|
||||||
|
pub.sendMessage('zeroconf_state_change', hostname=hostname, state_change=state_change)
|
||||||
|
except NotRunningException:
|
||||||
|
pass
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def found_hostnames(cls):
|
def found_hostnames(cls):
|
||||||
@@ -104,9 +112,15 @@ class ZeroconfServer:
|
|||||||
|
|
||||||
# Example usage:
|
# Example usage:
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
import time
|
||||||
|
|
||||||
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
ZeroconfServer.configure("_zordon._tcp.local.", "foobar.local", 8080)
|
ZeroconfServer.configure("_zordon._tcp.local.", "foobar.local", 8080)
|
||||||
try:
|
try:
|
||||||
ZeroconfServer.start()
|
ZeroconfServer.start()
|
||||||
input("Server running - Press enter to end")
|
while True:
|
||||||
|
time.sleep(0.1)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
pass
|
||||||
finally:
|
finally:
|
||||||
ZeroconfServer.stop()
|
ZeroconfServer.stop()
|
||||||
|
|||||||
8
src/version.py
Normal file
8
src/version.py
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
APP_NAME = "Zordon"
|
||||||
|
APP_VERSION = "0.0.1"
|
||||||
|
APP_AUTHOR = "Brett Williams"
|
||||||
|
APP_DESCRIPTION = "Distributed Render Farm Tools"
|
||||||
|
APP_COPYRIGHT_YEAR = "2024"
|
||||||
|
APP_LICENSE = "MIT License"
|
||||||
|
APP_REPO_NAME = APP_NAME
|
||||||
|
APP_REPO_OWNER = "blw1138"
|
||||||
Reference in New Issue
Block a user