110 Commits

Author SHA1 Message Date
Brett Williams 44e6b4332f Fix create-executables.yml workflow to upload output to release page 2026-06-06 17:32:16 -05:00
brett c38213fb58 Update and modernize create-executables action (#138)
* Modernize create-executables.yml

* Update version numbers

* Fix API version in test
2026-06-06 17:10:53 -05:00
brett 3486feaaf4 Add timeouts and fix multi-camera render issue (#136)
* Fix issue where add job window always submits to localhost, regardless of selected hostname

* Add lots of timeouts

* Fix issue where multiple cameras would not render
2026-06-06 17:01:37 -05:00
brett 141843c916 Fix issue where jobs were not always deleted (#137)
* Better job deletion logic

* Cleanup UI after deleting runs
2026-06-06 16:08:02 -05:00
brett 472c7968b3 Fix issue where add job window always submits to localhost, regardless of selected hostname (#135) 2026-06-06 15:05:31 -05:00
brett b8b71d1e16 Add Blender plugin (#134)
* Unbind hostname to allow localhost submissions

* Fix issue where multiple cameras were outputting to the same directory

* Add Blender plugin
2026-06-06 14:32:48 -05:00
brett f0be78adcc REST API endpoint streamlining and cleanup (#133)
* Consolidate engine_info api calls

* Change api methods to use POST when possible

* Delete engine API cleanup

* Remove redundant installed_engines endpoint

* Update proxy to use similar named methods to new API calls

* More API cleanup

* Jobs API cleanup

* More jobs API cleanup

* Fix add jobs error due to null queue

* Remove unnecessary full_status and snapshot API endpoints

* Streamline add job POST endpoint

* Fix test after method name change
2026-06-06 12:04:52 -05:00
brett 24eb7b5616 Add Unit Tests (#132)
* Add tests and new github workflow

* Add new unit tests

* Add Github CI workflow

* Workflow fix

* Add pytest install to workflow file

* More CI / test updates

* More test cleanup

* Whitespace cleanup and link complexity override

* More whitespace cleanup

* Make lint less strict

* More lint tweaks
2026-06-06 00:02:01 -05:00
Brett Williams 7bf5fb554e Merge remote-tracking branch 'origin/master'
# Conflicts:
#	server.py
2026-06-05 22:05:42 -05:00
brett fa4a97f6fa Refactor: ApplicationContext DI wiring (#131)
* refactor: wire all services through ApplicationContext

- Created src/application_context.py as DI container with TYPE_CHECKING imports
- server.py now instantiates all services in dependency order via ApplicationContext
- Fixed infinite recursion bug: 48 instance methods renamed with underscore prefix
  to avoid shadowing by same-named @classmethod forwarders
- ZeroconfServer: instantiate Zeroconf() in __init__, add _sync_class() to
  configure forwarder, direct _configure/_start calls during wiring
- Config, EngineManager, PreviewManager: all forwarders and _sync_class() intact
- RenderQueue: load_state and subscribe moved to __init__, threading.Lock retained
- DistributedJobManager: subscribe_to_listener moved to __init__

* fix: greedy regex in get_render_devices swallows BlenderKit log output

Changed regex from greedy [\s\S]* to non-greedy .*? with re.DOTALL
so it stops at the first ] (the end of the GPU data JSON array)
instead of matching through timestamped log lines like
[19:36:22.109, __init__.py:2881] that contain trailing brackets.

* fix: AttributeError on .enabled in update_job_count prevents options from rendering

* refactor: log silent AttributeError catches, add _sync_class to remaining services, drop dead ctx slot
2026-06-05 22:01:20 -05:00
Brett Williams b7ba1201e4 refactor: log silent AttributeError catches, add _sync_class to remaining services, drop dead ctx slot 2026-06-05 21:27:02 -05:00
Brett Williams c592236c98 fix: AttributeError on .enabled in update_job_count prevents options from rendering 2026-06-05 20:12:14 -05:00
Brett Williams 0c62f454a7 fix: greedy regex in get_render_devices swallows BlenderKit log output
Changed regex from greedy [\s\S]* to non-greedy .*? with re.DOTALL
so it stops at the first ] (the end of the GPU data JSON array)
instead of matching through timestamped log lines like
[19:36:22.109, __init__.py:2881] that contain trailing brackets.
2026-06-05 19:37:12 -05:00
Brett Williams 552c791207 refactor: wire all services through ApplicationContext
- Created src/application_context.py as DI container with TYPE_CHECKING imports
- server.py now instantiates all services in dependency order via ApplicationContext
- Fixed infinite recursion bug: 48 instance methods renamed with underscore prefix
  to avoid shadowing by same-named @classmethod forwarders
- ZeroconfServer: instantiate Zeroconf() in __init__, add _sync_class() to
  configure forwarder, direct _configure/_start calls during wiring
- Config, EngineManager, PreviewManager: all forwarders and _sync_class() intact
- RenderQueue: load_state and subscribe moved to __init__, threading.Lock retained
- DistributedJobManager: subscribe_to_listener moved to __init__
2026-06-05 05:34:32 -05:00
brett e8992fc91a Add missing docstrings and pylint improvements (#130) 2026-01-20 23:13:38 -06:00
brett 74dce5cc3d Windows path fixes (#129)
* Change uses of os.path to use Pathlib

* Add return types and type hints

* Add more docstrings

* Add missing import to api_server
2026-01-18 00:18:43 -06:00
brett ee9f44e4c4 Mix bad imports 2026-01-16 01:07:34 -06:00
Brett Williams 0a69c184eb Fix pyinstaller spec files 2026-01-12 09:08:35 -06:00
brett 8b3fdd14b5 Add Job Window Redesign (#128)
* Initial refactor of add_job_window

* Improved project naming and fixed Blender engine issue

* Improve time representation in main window

* Cleanup Blender job creation

* Send resolution / fps data in job submission

* More window improvements

* EngineManager renaming and refactoring

* FFMPEG path fixes for ffprobe

* More backend refactoring / improvements

* Performance improvements / API refactoring

* Show current job count in add window UI before submission

* Move some UI update code out of background thread

* Move some main window UI update code out of background thread
2026-01-12 09:06:53 -06:00
brett d8af7c878e Job submission code and API cleanup (#127)
* Refactor add jobs and make add_job api only be one job (instead of a list)

* Renamed to JobImportHandler and misc cleanup

* Dont bury exceptions in server proxy post_job

* Update code to create child jobs in a cleaner manner
2025-12-31 23:14:28 -06:00
brett e335328530 Improve server shutdown (#126)
* Cleaned up server shutdown process

* Fix exception on shutdown in Windows
2025-12-30 17:46:53 -06:00
brett f9b19587ba Ignore aerender in pytests until ready (#125)
* Ignore aerender in pytests until ready
* Disable pytest step in GitHub Actions workflow
2025-12-28 15:00:01 -06:00
brett 4704806472 Settings Window (#124)
* Initial commit for settings window

* More WIP for the Settings panel

* Added Local Files section to Settings

* More WIP on Settings

* Add ability to ignore system builds

* Improvements to Launch and Delete buttons

* Fix issue where icons were not loading

* Network password settings WIP

* Update label

* Import and naming fixes

* Speed improvements to launch

* Update requirements.txt

* Update Windows CPU name lookup

* Add missing default values to a few settings

* More settings fixes

* Fix Windows Path issue

* Added hard types for getting settings values

* More UI cleanup

* Correctly refresh Engines list after downloading new engine

* Improve downloader with UI progress

* More download improvements

* Add Settings Button to Toolbar
2025-12-28 12:33:29 -06:00
brett daf445ee9e Rename renderers to engines (#123)
* Bulk rename
* Fix build issues
2025-12-27 18:53:09 -06:00
brett 574c6f0755 Job Submission CLI (#122)
* Initial commit of job submission cli tool, with minor fixes in API code

* Refactored and further decoupled server / client code

* Clean up ServerProxy to not use hardcoded loopback addresses
2025-12-27 18:36:34 -06:00
brett 6bfa5629d5 GPU Reporting in UI (#120)
* Add basic GPU info reporting to UI

* Update GPU display to showcase multiple GPUs, if available

* Add fallback for Windows for fetching GPU info

* Improve Windows GPU lookup. Add GPUtil to requirements.txt

* Clean up GPU and CPU naming in UI

* Update Linux GPU fetching

* Update misc_helper.py

Fix getting GPU names on Linux

* Update .gitignore
2025-12-18 17:47:30 -06:00
Brett Williams 05cd0470dd Fix build issues using pyinstaller 2025-03-13 14:17:50 -05:00
Brett Williams 7827f73530 Show CPU brand in UI instead of arch. Resolves #110. 2025-02-28 19:54:58 -06:00
brett 562cb23da3 Feature/112 api version (#119)
* Add api_version to status api and server_proxy.py

* Add api_version to Zeroconf and filter out incompatible versions when finding available servers

* Filter incompatible versions from the UI
2025-02-28 19:39:32 -06:00
Brett Williams 6b68d42b93 Misc minor fixes 2025-02-28 18:50:44 -06:00
Brett Williams cdf4b2bbe1 Update the README.md with an app screenshot 2025-02-28 18:43:40 -06:00
Brett Williams dc8f4d3e2a Use Fusion Qt style on non-Mac platforms 2025-02-28 18:40:59 -06:00
brett 2548280dcc Add check for available software updates (#118)
* Add feature to check github repo for available updates

* Add Check for Updates to Help menu
2024-08-24 12:12:30 -05:00
Brett Williams 98ab837057 Fix issue where API server could fail to start 2024-08-24 03:00:57 -05:00
Brett Williams 3fda87935e Only prevent launch if we find unrelated processes 2024-08-24 02:22:38 -05:00
Brett Williams e35a5a689c Make sure only one instance is running at a time 2024-08-24 01:35:50 -05:00
brett dea7574888 Rename create_executables.yml to create-executables.yml 2024-08-23 19:52:41 -05:00
brett a19db9fcf7 Fix issue with create_executables.yml 2024-08-23 19:51:56 -05:00
brett 80b0adb2ad Create executables for all platforms, not just Windows 2024-08-23 19:46:35 -05:00
brett 18873cec6f Only generate Windows binaries when releases are created 2024-08-23 19:37:34 -05:00
brett af6d6e1525 Document all the things! (#117)
Add lots of docstrings everywhere
2024-08-23 19:26:05 -05:00
brett 8bbf19cb30 Fix accidental readme rename 2024-08-23 19:17:03 -05:00
brett 6bdb488ce1 Add "Create Executable" GitHub action for Windows (#116) 2024-08-23 18:36:14 -05:00
brett e792698480 Merge pull request #114
* Better exception handling / error reporting for add job screen

* Don't supress exceptions for potentially long running functions in bl…

* Increase Blender pack_project_file timeout to 120s
2024-08-20 15:20:24 -05:00
Brett Williams 751d74ced3 Fix issue where Stop Job button would never show 2024-08-15 23:20:04 -05:00
brett e8a4692e0f Update README.md 2024-08-15 15:10:37 -05:00
brett 49ae5a55d9 Add About window and basic commands to MenuBar (#113)
* Initial commit for about_window.py

* Add some basic actions to the MenuBar

* Fix keyboard shortcuts

* Fix path to icon for Windows
2024-08-15 14:27:29 -05:00
Brett Williams d04d14446b Update main.spec to include version numbers on Windows 2024-08-15 11:41:36 -05:00
brett 81e79a1996 Prevent subprocesses from constantly opening windows on Windows (#109)
* Add subprocess.CREATE_NO_WINDOW to blender_engine.py

* Convert ffmpeg_engine.py to use CREATE_NO_WINDOW

* Cleanup Blender implementation

* Cleanup subprocesses in base_worker.py

* Cleanup subprocesses in base_engine.py

* Fix main.spec for Windows (optimize=2 broke it)
2024-08-13 22:16:03 -05:00
Brett Williams d30978bef0 Update main.spec for Windows support 2024-08-13 18:02:40 -05:00
brett e2333c4451 Fix processes not ending when stopped (#98)
* Fix processes not ending when stopped

* Fix error when removing a job

* Better error handling

* Refactored killprocess code and fixed windows support

* Improved error handling

* Add try to code that deletes project files

* Wait for the thread to finish after killing the process

* Don't try to stop process multiple times

* Misc cleanup
2024-08-13 11:16:31 -05:00
brett 94a40c46dc Add output file count validation (#97)
* Worker file_list ignores hidden files

* Add frame-count validation logic
2024-08-11 13:00:54 -05:00
Brett Williams 8104bd4e86 Add logic to download button in main window 2024-08-11 11:59:40 -05:00
Brett Williams 33adcac592 Code refactoring 2024-08-11 11:54:15 -05:00
Brett Williams d38e10ae9f Add tga, bmp, webp and webm to PreviewManager support 2024-08-10 21:23:06 -05:00
Brett Williams 19b01446ea Make renderer_info threaded again 2024-08-10 21:20:47 -05:00
brett e757506787 Parent creates local subjobs instead of truncating original (#95)
* Parent worker now creates subjob on local host and waits for it

* Improve wait_for_subjobs logic

* Fix setting end_time for base_worker

* API cleanup

* Code refactoring

* Cleanup
2024-08-10 21:19:01 -05:00
brett f9b51886ab Bugfix: Filter out corrupt engines by default (#94)
* Add main.spec

* Fix issue where fetching supported extensions would crash with no default installation

* Engines return version as 'error' if cannot determine version

* EngineManager will now filter out corrupted engine installs by default
2024-08-10 15:00:47 -05:00
brett 3b33649f2d Pyinstaller support (#93)
* Add main.spec

* Fix issue where fetching supported extensions would crash with no default installation
2024-08-10 14:58:41 -05:00
brett 51a5a63944 Use pubsub messages instead of a background thread to process changes (#92)
* Use pubsub messages instead of a background thread to process changes to the RenderQueue

* Misc logging improvements
2024-08-08 23:01:26 -05:00
brett 3600eeb21b Refactor: Move all initialization logic out of api_server and into init (#91)
* Zeroconf logging improvements

* Ignore RuntimeErrors in background threads - Prevents issues during shutdown

* Migrate start up code from api_server.py to init.py

* Add error handlers to the API server to handle detached instances

* Integrate RenderQueue eval loop into RenderQueue object

* Silently catch RuntimeErrors on evaluate_queue

* Stop background queue updates in prepare_for_shutdown
2024-08-08 04:47:22 -05:00
brett 6afb6e65a6 Integrate watchdog into render worker (#88)
* Add a watchdog to base_worker

* Logging cleanup

* Prevent multiple watchdogs from running if render process restarts

* Add process timeout parameter to Config

* Refactor

* Add error handling to process output parsing

* Fix issue where start_time was not getting set consistently
2024-08-06 10:48:24 -05:00
Brett Williams 90d5e9b7af Misc logging cleanup 2024-08-05 10:57:56 -05:00
brett 4df41a2079 Download frames from subjobs as frames are completed (#87)
* Add a frame complete notification to BaseWorker and distributed_job_manager.py

* Add API to download individual files to API server and ServerProxy

* Rename subjob notification API and add download_missing_frames_from_subjob

* Subjobs will now notify parent when a frame is complete

* Fix missed rename

* Add some misc logging

* Better error handling

* Fix frame download file path issue

* Download missing frames at job completion and misc cleanup

* Misc cleanup

* Code cleanup
2024-08-04 21:30:10 -05:00
brett 1cdb7810bf New PreviewManager to handle generating previews asynchronously (#86)
* Add PreviewManager

* Refactoring and better error handling

* Integrate PreviewManager into api_server.py

* Integrate PreviewManager into distributed_job_manager.py

* Add method to preview_manager.py to delete previews and integrate it into api_server

* Misc logging improvements

* Misc code cleanup

* Replace existing preview on job completion - Minor code fixes
2024-08-04 16:45:46 -05:00
Brett Williams 21011e47ca Fix issue where tests would never complete correctly 2024-08-04 11:48:36 -05:00
Brett Williams 86977b9d6d Fix issue where custom job name was being ignored 2024-08-04 11:47:56 -05:00
Brett Williams 220b3fcc25 Streamline job runtime - improve logging 2024-08-03 20:55:22 -05:00
brett 82613c3963 Persist args in db and return args in job json (#82) 2024-08-03 18:42:21 -05:00
Brett Williams abc9724f01 Quickfix: Forgot to commit one rename 2024-08-03 18:28:33 -05:00
brett ef4fc0e42e Blender GPU / CPU Render (#81)
* Add script to get GPU information from Blender

* Change run_python_script to allow it to run without a project file

* Simplify run_python_script code

* Fix mistake

* Add system_info to engine classes and api_server. /api/renderer_info now supports standard and full response modes.

* Get full renderer_info response for add job UI

* Enable setting specific Blender render_device using args

* Add Blender render device options to UI
2024-08-03 18:26:56 -05:00
Brett Williams 9bc490acae Misc cleanup / renaming 2024-08-03 14:04:17 -05:00
brett 21de69ca4f Improve performance on several API calls (#80)
* Streamline fetching renderer_info from API - use threading for performance improvements

* Use concurrent.futures instead of Threading

* Fix timeout issue with server proxy

* Minor fixes to code that handles proxy server online / offline status
2024-08-03 11:02:40 -05:00
Brett Williams 47770c4fdd Update blender worker to get current frame from filepath output 2024-07-30 20:00:07 -05:00
brett 8a3e74660c Create subjobs after submission - #54 (#79)
* Force start in render queue only starts NOT_STARTED and SCHEDULED jobs

* Refactor adding jobs / subjobs

* Remove dead code

* Fixed issue with bulk job submission

* Cancel job now cancels all subjobs

* Misc fixes

* JSON now returns job hostname

* Add hostname as optional column in DB

* Misc fixes

* Error handling for removing zip file after download

* Clean up imports

* Fixed issue where worker child information would not be saved
2024-07-30 19:22:38 -05:00
Brett Williams 6d33f262b3 Better error handling when posting a new job 2024-07-29 14:50:14 -05:00
brett a0729d71f1 Add long_polling_jobs to API (#78) 2024-02-13 13:11:56 -06:00
brett ecf836c235 Zeroconf offline-handling improvements (#77)
* Add benchmark.py

* Add cpu / disk benchmark APIs

* Add cpu_benchmark method to distributed_job_manager.py

* Do a better job of storing hostnames =

* Remove hostname from Zeroconf cache if server goes offline

* Add cpu / disk benchmark APIs

* Add cpu_benchmark method to distributed_job_manager.py

* Do a better job of storing hostnames =

* Remove hostname from Zeroconf cache if server goes offline

* Wrap main code in try finally block to always stop zeroconf

* Add missing import
2024-02-12 14:57:00 -06:00
brett a31fe98964 Cpu benchmarks #48 (#76)
* Add benchmark.py

* Add cpu / disk benchmark APIs

* Add cpu_benchmark method to distributed_job_manager.py

* Make sure cpu_benchmark is an int

* Improve distributed_job_manager test
2024-02-11 05:19:24 -06:00
Brett Williams 79db960383 Add MIT license 2024-01-28 20:54:12 -06:00
brett 85785d9167 Check engine permissions and chmod it to executable if not already (#75) 2024-01-28 10:53:14 -06:00
brett 9757ba9276 Pylint cleanup (#74)
* Misc fixes

* Misc cleanup

* Add all_versions to blender_downloader.py

* More cleanup

* Fix issue with status not reporting engine info

* Misc fixes

* Misc cleanup

* Add all_versions to blender_downloader.py

* More cleanup

* Fix issue with status not reporting engine info
2024-01-28 10:30:57 -06:00
brett d673d7d4bf Misc cleanup (#73)
* Stop previously running zeroconf instances

* Lots of formatting fixes

* Use f-strings for time delta

* More line fixes

* Update requirements.txt

* More misc cleanup

* Simplify README.md
2024-01-27 22:56:33 -06:00
Brett Williams d216ae822e Merge remote-tracking branch 'origin/master' 2023-12-25 17:47:03 -06:00
Brett Williams dabe46bdda Add .pylintrc 2023-12-25 17:46:45 -06:00
brett 2c82c65305 Update pylint.yml
Update python versions
2023-12-25 17:40:55 -06:00
Brett Williams 4004ad893b Update .gitignore 2023-12-21 20:47:38 -06:00
Brett Williams 685297e2f2 Use alphanumeric API tokens instead of ints 2023-12-21 20:46:55 -06:00
brett d55f6a5187 Remove web components (#70)
* Remove old web code

* Add back missing gears file

* Client fetches thumbnails instead of being sent by server
2023-12-17 12:07:10 -06:00
Brett Williams 8863a38904 Add more docstrings 2023-12-16 22:23:02 -06:00
brett f663430984 Fix py2app (#69)
* Initial commit of py2app code

* Use environment variable RESOURCE_PATH when running as a bundle

* Move config files to system config location
2023-12-16 22:20:24 -06:00
brett 525fd99a58 Ffmpeg versioning issues (#68)
* FFMPEG version cleanup

* Make sure attempts don't go on forever

* Use latest version when version not defined. Add latest to UI
2023-11-22 08:47:47 -08:00
Brett Williams 4847338fc2 Fix FFMPEG version regex 2023-11-22 07:48:28 -08:00
brett c0d0ec64a8 Dynamic engine options in UI for blender / ffmpeg (#66)
* Make sure progress UI updates occur on main thread

* Cleanup unnecessary code in FFMPEG

* Cleanup extension matching

* Make sure supported_extensions is now called as a method everywhere

* Fix add_job crashing

* Update the renderer to reflect the current file type

* Sort engine versions from newest to oldest

* Consolidate Project Group and Server Group

* Split UI options into its own file for easier updating

* Add ffmpeg ui stem
2023-11-21 01:31:56 -08:00
brett 32afcf945d Use loopback address for local host (fixes issue with locked down networks) (#65) 2023-11-21 01:16:26 -08:00
brett e9f9521924 Report Engine Download Status in UI (#64)
* Report downloads in status bar

* Update engine_browser.py UI with any active downloads
2023-11-20 19:58:31 -08:00
Brett Williams 0e0eba7b22 Close the session properly - part 2 2023-11-11 10:59:39 -06:00
Brett Williams 86c5d4cc15 Properly close the renderqueue when shutting down 2023-11-11 10:58:21 -06:00
brett da61bf72f8 Add job polish (#63)
* Remove legacy client

* Misc cleanup

* Add message box after submission success / fail

* Use a new is_localhost method to handle localhost not including '.local'

* Code cleanup

* Fix issue where engine browser would think we're downloading forever

* Add message box after submission success / fail

* Use a new is_localhost method to handle localhost not including '.local'

* Code cleanup

* Fix issue where engine browser would think we're downloading forever

* Add pubsub messages to serverproxy_manager.py

* Add resolution, fps and renderer versions to add_job.py

* Add cameras to add_job.py

* Add message box after submission success / fail

* Use a new is_localhost method to handle localhost not including '.local'

* Code cleanup

* Fix issue where engine browser would think we're downloading forever

* Add message box after submission success / fail

* Code cleanup

* Add cameras to add_job.py

* Add dynamic engine options and output format

* Move UI work out of BG threads and add engine presubmission tasks

* Submit dynamic args when creating a new job

* Hide groups and show messagebox after submission

* Choose file when pressing New Job in main window now
2023-11-11 07:35:56 -06:00
brett 0271abf705 Serverproxy manager (#61)
* Create serverproxy_manager.py

* Replace use of direct RenderServerProxy with ServerProxyManager method
2023-11-05 01:00:36 -05:00
brett c3b446be8e Don't create empty output directories in the source path (#60) 2023-11-04 23:58:08 -05:00
brett 06a613fcc4 Zeroconf reports system properties (#59)
* Zeroconf.found_clients() now returns dicts of clients, not just hostnames

* Adjustments to distributed_job_manager.py

* Undo config change

* Report system metrics (cpu, os, etc) via zeroconf_server.py

* Zeroconf.found_clients() now returns dicts of clients, not just hostnames

* Adjustments to distributed_job_manager.py

* Undo config change

* Zeroconf.found_clients() now returns dicts of clients, not just hostnames

* Adjustments to distributed_job_manager.py

* Undo config change

* Adjustments to distributed_job_manager.py

* Undo config change

* Rename ZeroconfServer.found_clients() to found_hostnames()
2023-11-04 20:46:27 -05:00
brett d3b84c6212 Remove legacy client (#58)
* Remove legacy client

* Misc cleanup
2023-11-04 16:13:40 -05:00
Brett Williams 014489e3bf Add engine_help_viewer.py 2023-11-04 10:41:33 -05:00
brett 65c256b641 New UI Redesign in pyqt6 (#56)
* Initial commit for new UI

* Initial commit for new UI

* WIP

* Status bar updates and has an icon for online / offline

* Add log_viewer.py

* Use JSON for delete_engine_download API

* Fix class issue with Downloaders

* Move Config class to new ui

* Add engine_browser.py

* Add a close event handler to the main window

* Fix issue with engine manager not deleting engines properly

* Rearrange all the files

* Add icons and resources

* Cache system info in RenderServerProxy

* Toolbar polish

* Fix resource path in status bar

* Add config_dir to misc_helper.py

* Add try block to zeroconf setup

* Add add_job.py

* Add raw args to add_job.py
2023-11-04 09:52:15 -05:00
brett bc8e88ea59 Config class (#51)
* Add new Config class to handle loading config files

* Use new config class in api_server.py
2023-10-29 22:22:40 -05:00
brett 6ce69c8d35 Thread Safe Downloads for Renderers (#49)
* Make engines download on another thread

* Fix merge issues
2023-10-29 22:22:29 -05:00
brett dcc0504d3c Engine and downloader refactoring (#50)
* Make downloaders subclass of base_downloader.py

* Link engines and downloaders together for all engines

* Replace / merge worker_factory.py with engine_manager.py
2023-10-29 20:57:26 -05:00
Brett Williams 22aaa82da7 Simplify database.db logic 2023-10-27 02:41:31 -05:00
Brett Williams 951bebb3a8 Save database.db to upload dir, not code dir 2023-10-27 02:35:21 -05:00
119 changed files with 11050 additions and 3190 deletions
+11
View File
@@ -0,0 +1,11 @@
[flake8]
exclude =
src/engines/aerender
.git
build
dist
*.egg
venv
.venv
max-complexity = 10
max-line-length = 127
+45
View File
@@ -0,0 +1,45 @@
name: CI
on:
push:
branches: [master]
pull_request:
branches: [master]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install system deps
run: sudo apt-get update && sudo apt-get install -y libxcb-cursor0 libxcb-xinerama0 blender
- name: Install Python deps
run: |
pip install -r requirements.txt
pip install pytest flake8 pylint
- name: Test
run: python -m pytest tests/ --ignore=tests/job_creation_tests.py -v
- name: Lint — bugs (flake8)
# Fails on syntax errors only. Ignored: ~100+ pre-existing
# style issues (E/W), star-import false positives (F403/F405),
# unused imports (F401), unused vars (F841), f-string debt (F541).
run: flake8 --select=E9 --exclude=src/engines/aerender,build,dist,.git,__pycache__,venv --max-line-length=127 --max-complexity=35
- name: Lint — style (flake8)
# Reports style issues but never fails the build.
# TODO: resolve ~100+ pre-existing style issues
run: flake8 --exit-zero --exclude=src/engines/aerender,build,dist,.git,__pycache__,venv --max-line-length=127 --max-complexity=35
- name: Lint (pylint)
# Reports all issues but never fails the build.
# TODO: resolve pre-existing debt (current score 7.73/10)
run: pylint src/ --max-line-length=120 --ignore-paths=^src/engines/aerender/ --fail-under=0
+104
View File
@@ -0,0 +1,104 @@
name: Create Executables
on:
workflow_dispatch:
release:
types: [published]
permissions:
contents: write
jobs:
build:
name: Build executables (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: windows-latest
artifact_suffix: windows
- os: ubuntu-latest
artifact_suffix: linux
- os: macos-latest
artifact_suffix: macos
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install Linux system dependencies
if: runner.os == 'Linux'
run: sudo apt-get update && sudo apt-get install -y libxcb-cursor0 libxcb-xinerama0
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip wheel setuptools
python -m pip install -r requirements.txt
python -m pip install pyinstaller pyinstaller_versionfile
- name: Build client
run: pyinstaller --clean client.spec
- name: Build server
run: pyinstaller --clean server.spec
- name: Package build outputs
shell: bash
env:
ARTIFACT_SUFFIX: ${{ matrix.artifact_suffix }}
run: |
python - <<'PY'
from pathlib import Path
import os
import zipfile
suffix = os.environ['ARTIFACT_SUFFIX']
dist_dir = Path('dist')
asset_dir = Path('release-assets')
asset_dir.mkdir(exist_ok=True)
for app_name in ('Zordon-client', 'Zordon-server'):
source = next(
(
path for path in (
dist_dir / f'{app_name}.exe',
dist_dir / f'{app_name}.app',
dist_dir / app_name,
)
if path.exists()
),
None,
)
if source is None:
raise FileNotFoundError(f'Could not find PyInstaller output for {app_name}')
zip_path = asset_dir / f'{app_name}-{suffix}.zip'
with zipfile.ZipFile(zip_path, 'w', compression=zipfile.ZIP_DEFLATED) as zip_file:
if source.is_dir():
for file_path in source.rglob('*'):
if file_path.is_file():
zip_file.write(file_path, source.name / file_path.relative_to(source))
else:
zip_file.write(source, source.name)
PY
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: Zordon-build-${{ matrix.artifact_suffix }}
path: release-assets/*.zip
if-no-files-found: error
- name: Attach assets to release
if: github.event_name == 'release'
shell: bash
env:
GH_TOKEN: ${{ github.token }}
run: gh release upload "${{ github.event.release.tag_name }}" release-assets/*.zip --clobber
-23
View File
@@ -1,23 +0,0 @@
name: Pylint
on: [push]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]
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')
-39
View File
@@ -1,39 +0,0 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
name: Python application
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
+11 -3
View File
@@ -1,8 +1,16 @@
/job_history.json
*.icloud
*.fcpxml
/uploads
*.pyc
/server_state.json
/.scheduler_prefs
*.db
/dist/
/build/
/.github/
*.idea
.DS_Store
/venv/
.env
venv/
/.eggs/
/.ai/
/.github/
+5
View File
@@ -0,0 +1,5 @@
[MASTER]
max-line-length = 120
ignore-paths=^src/engines/aerender/
[MESSAGES CONTROL]
disable = missing-docstring, invalid-name, import-error, logging-fstring-interpolation
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2024 Brett Williams
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+209 -12
View File
@@ -1,23 +1,220 @@
# 🎬 Zordon - Render Management Tools 🎬
![Zordon Screenshot](docs/screenshot.png)
Welcome to Zordon! This is a hobby project written with fellow filmmakers in mind. It's a local network render farm manager, aiming to streamline and simplify the rendering process across multiple home computers.
---
## 📦 Installation
# Zordon
Make sure to install the necessary dependencies: `pip3 install -r requirements.txt`
A Python-based distributed rendering management tool that supports Blender, FFmpeg, and other render engines. Zordon efficiently manages render jobs across multiple machines, making it ideal for small render farms in home studios or small businesses.
## 🚀 How to Use
## What is Zordon?
Zordon has two main files: `start_server.py` and `start_client.py`.
Zordon is a 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.
- **start_server.py**: Run this on any computer you want to render jobs. It manages the incoming job queue and kicks off the appropriate render jobs when ready.
- **start_client.py**: Run this to administer your render servers. It lets you manage and submit jobs.
The system works by:
- **Server**: Central coordinator that manages job queues and distributes tasks to available workers
- **Clients**: Lightweight workers that run on rendering machines and execute assigned jobs
- **API**: RESTful endpoints for programmatic job submission and monitoring
When the server is running, the job queue can be accessed via a web browser on the server's hostname (default port is 8080). You can also access it via the GUI client or a simple view-only dashboard.
## Features
## 🎨 Supported Renderers
- **Distributed Rendering**: Queue and distribute render jobs across multiple machines
- **Multi-Engine Support**: Compatible with Blender, FFmpeg, and extensible to other render engines
- **Desktop UI**: PyQt6 interface for job management and monitoring
- **REST API**: Flask-based API for programmatic access
- **Cross-Platform**: Runs on Windows, macOS, and Linux
- **Zero-Install Clients**: Lightweight client executables for worker machines
Zordon currently supports the following renderers:
## Installation
### Prerequisites
- Python 3.11 or later
- Git
### Setup
1. Clone the repository:
```bash
git clone https://github.com/blw1138/Zordon.git
cd Zordon
```
2. Install dependencies:
```bash
pip install -r requirements.txt
```
3. (Optional) Install PyInstaller for building executables:
```bash
pip install pyinstaller pyinstaller_versionfile
```
## Usage
### Quick Start
1. **Start the Server**: Run the central server to coordinate jobs.
```bash
python server.py
```
2. **Launch Clients**: On each rendering machine, run the client to connect to the server.
```bash
python client.py
```
### Detailed Workflow
#### Setting Up a Render Farm
1. Choose one machine as the server (preferably a dedicated machine with good network connectivity).
2. Build and distribute client executables to worker machines:
```bash
pyinstaller client.spec
```
Copy the generated executable to each worker machine.
3. Ensure all machines can communicate via network (same subnet recommended).
#### Submitting Render Jobs
Jobs can be submitted via the desktop UI or programmatically via the API:
- **Via UI**: Use the desktop interface to upload project files, specify render settings, and queue jobs.
- **Via API**: Send `POST` requests to `/api/jobs` with job configuration in JSON format.
Example API request:
```bash
curl -X POST http://localhost:8080/api/jobs \
-H "Content-Type: application/json" \
-d '{
"name": "example-render",
"engine_name": "blender",
"local_path": "/path/to/project.blend",
"output_path": "example-output",
"start_frame": 1,
"end_frame": 100,
"args": {
"export_format": "PNG",
"resolution": [1920, 1080]
},
"enable_split_jobs": false
}'
```
#### Monitoring and Managing Jobs
- **UI**: View job status, progress, logs, and worker availability in real-time.
- **API Endpoints**:
- `GET /api/jobs`: List all jobs
- `POST /api/jobs`: Submit a new job
- `GET /api/jobs/<job_id>`: Get job details
- `POST /api/jobs/<job_id>/cancel`: Cancel a job
- `POST /api/jobs/<job_id>/delete`: Delete a job
- `GET /api/status`: Get server and queue status
- `GET /api/engines`: List engine information
For the full endpoint reference, see [`docs/api.html`](docs/api.html) or
[`docs/API.md`](docs/API.md).
#### Blender Add-on
Zordon includes a Blender add-on for submitting the current `.blend` file
directly from Blender.
- Source: [`addons/blender/zordon_blender`](addons/blender/zordon_blender)
- Installable zip: [`addons/blender/zordon_blender.zip`](addons/blender/zordon_blender.zip)
After installing the add-on, use `Properties > Render > Zordon` to discover or
choose a server, test the connection, upload the current file, and submit
camera-specific jobs from the active Blender scene.
#### Worker Management
Workers automatically connect to the server when started. You can:
- View worker status and capabilities in the dashboard
- Configure worker priorities and resource limits
- Monitor CPU/GPU usage per worker
### Development Mode
For development and testing:
Run the server:
```bash
python server.py
```
Run a client (can run multiple for testing):
```bash
python client.py
```
### Building Executables
Build server executable:
```bash
pyinstaller server.spec
```
Build client executable:
```bash
pyinstaller client.spec
```
## Configuration
Settings are stored in `src/utilities/config.py`. Supports YAML/JSON for data serialization and environment-specific configurations.
## Architecture
Zordon follows a modular architecture with the following key components:
- **API Server** (`src/api/`): Flask-based REST API
- **Engine System** (`src/engines/`): Pluggable render engines (Blender, FFmpeg, etc.)
- **UI** (`src/ui/`): PyQt6-based interface
- **Job Management** (`src/render_queue.py`): Distributed job queue
Design patterns include Factory Pattern for engine creation, Observer Pattern for status updates, and Strategy Pattern for different worker implementations.
## Contributing
1. Fork the repository
2. Create a feature branch: `git checkout -b feature/your-feature`
3. Follow the code style guidelines in `AGENTS.md`
4. Test the build: `pyinstaller server.spec`
5. Submit a pull request
### Commit Message Format
```
feat: add support for new render engine
fix: resolve crash when engine path is invalid
docs: update API documentation
refactor: simplify job status handling
```
## Supported Render Engines
- **Blender**
- **FFMPEG**
- **FFmpeg**
- **Adobe After Effects** (planned)
- **Cinema 4D** (planned)
- **Autodesk Maya** (planned)
## System Requirements
- Windows 10 or later
- macOS Ventura (13.0) or later
- Linux (supported versions TBD)
## License
Zordon is licensed under the MIT License. See the [LICENSE](LICENSE.txt) file for more details.
## Notice
This software is in beta and intended for casual/hobbyist use. Not recommended for mission-critical environments.
+131
View File
@@ -0,0 +1,131 @@
#!/usr/bin/env python3
import argparse
import logging
import os
import socket
import sys
import time
from server import ZordonServer
from src.api.serverproxy_manager import ServerProxyManager
logger = logging.getLogger()
def main():
parser = argparse.ArgumentParser(
description="Zordon CLI tool for preparing/submitting a render job",
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
# Required arguments
parser.add_argument("scene_file", help="Path to the scene file (e.g., .blend, .max, .mp4)")
parser.add_argument("engine", help="Desired render engine", choices=['blender', 'ffmpeg'])
# Frame range
parser.add_argument("--start", type=int, default=1, help="Start frame")
parser.add_argument("--end", type=int, default=1, help="End frame")
# Job metadata
parser.add_argument("--name", default=None, help="Job name")
# Output
parser.add_argument("--output", default="", help="Output path/pattern (e.g., /renders/frame_####.exr)")
# Target OS and Engine Version
parser.add_argument(
"--os",
choices=["any", "windows", "linux", "macos"],
default="any",
help="Target operating system for render workers"
)
parser.add_argument(
"--engine-version",
default="latest",
help="Required renderer/engine version number (e.g., '4.2', '5.0')"
)
# Optional flags
parser.add_argument("--dry-run", action="store_true", help="Print job details without submitting")
args = parser.parse_args()
# Basic validation
if not os.path.exists(args.scene_file):
print(f"Error: Scene file '{args.scene_file}' not found!", file=sys.stderr)
sys.exit(1)
if args.start > args.end:
print("Error: Start frame cannot be greater than end frame!", file=sys.stderr)
sys.exit(1)
# Calculate total frames
total_frames = len(range(args.start, args.end + 1))
job_name = args.name or os.path.basename(args.scene_file)
file_path = os.path.abspath(args.scene_file)
# Print job summary
print("Render Job Summary:")
print(f" Job Name : {job_name}")
print(f" Scene File : {file_path}")
print(f" Engine : {args.engine}")
print(f" Frames : {args.start}-{args.end}{total_frames} frames")
print(f" Output Path : {args.output or '(default from scene)'}")
print(f" Target OS : {args.os}")
print(f" Engine Version : {args.engine_version}")
if args.dry_run:
print("\nDry run complete (no submission performed).")
return
local_hostname = socket.gethostname()
local_hostname = local_hostname + (".local" if not local_hostname.endswith(".local") else "")
found_proxy = ServerProxyManager.get_proxy_for_hostname(local_hostname)
is_connected = found_proxy.check_connection()
adhoc_server = None
if not is_connected:
adhoc_server = ZordonServer()
adhoc_server.start_server()
found_proxy = ServerProxyManager.get_proxy_for_hostname(adhoc_server.server_hostname)
while not is_connected:
# todo: add timeout
is_connected = found_proxy.check_connection()
time.sleep(1)
new_job = {"name": job_name, "engine_name": args.engine}
try:
response = found_proxy.create_job(file_path, new_job)
except Exception as e:
print(f"Error creating job: {e}")
exit(1)
if response and response.ok:
print(f"Uploaded to {found_proxy.hostname} successfully!")
running_job_data = response.json()
job_id = running_job_data.get('id')
print(f"Job {job_id} Summary:")
print(f" Status : {running_job_data.get('status')}")
print(f" Engine : {running_job_data.get('engine_name')}-{running_job_data.get('engine_version')}")
print("\nWaiting for render to complete...")
percent_complete = 0.0
while percent_complete < 1.0:
# add checks for errors
time.sleep(1)
running_job_data = found_proxy.get_job(job_id)
percent_complete = running_job_data['percent_complete']
sys.stdout.write("\x1b[1A") # Move up 1
sys.stdout.write("\x1b[0J") # Clear from cursor to end of screen (optional)
print(f"Percent Complete: {percent_complete:.2%}")
sys.stdout.flush()
print("Finished rendering successfully!")
else:
print(f"Failed to upload job. {response.text} !")
if adhoc_server:
adhoc_server.stop_server()
if __name__ == "__main__":
main()
Binary file not shown.
+153
View File
@@ -0,0 +1,153 @@
# Zordon Blender Add-on
Submit the current Blender file to a Zordon render server from Blender's Render
properties panel.
## Features
- Submit the current `.blend` file directly to `POST /api/jobs`.
- Choose a configured Zordon server from Blender.
- Test the server connection before submitting.
- Save the current file before upload.
- Default job and output names to the `.blend` filename.
- Use the current scene frame range, render resolution, FPS, and image format.
- Select one or more cameras for submission.
- Submit multiple selected cameras as camera-specific child jobs.
## Install
1. In Blender, open `Edit > Preferences > Add-ons`.
2. Click `Install...`.
3. Select `addons/blender/zordon_blender.zip`.
4. Enable `Zordon Render Submitter`.
## Configure Servers
Use `Discover Servers` to find Zordon servers advertised with Zeroconf.
Discovered servers are merged into the configured server list.
You can also open the add-on preferences and edit `Servers` manually.
Use a comma-separated list:
```text
localhost:8080, render-node.local:8080
```
The selected server appears in `Properties > Render > Zordon`.
If Blender is running on the same machine as Zordon, `localhost:8080` should
work. If Zordon is running on another machine, use that machine's hostname or IP
address.
Start the Zordon server before testing the connection:
```bash
python server.py
```
Discovery first tries Python's `zeroconf` package if it is available inside
Blender. If it is not available, the add-on falls back to the macOS `dns-sd`
command when present.
## Submit A Job
1. Open or save a `.blend` file.
2. Choose a Zordon server in `Properties > Render > Zordon`.
3. Click `Test Connection`.
4. Set the job name, output name, and notes if needed.
5. Choose one or more cameras. At least one camera is always required.
6. Click `Submit Current File`.
The addon uploads the current `.blend` to `POST /api/jobs` as multipart form
data. It uses the current scene frame range, render resolution, FPS, and image
format.
Job name and output name default to the current `.blend` filename.
If one camera is selected, the job renders that camera. If multiple cameras are
selected, the addon submits camera-specific child jobs so each camera renders as
its own Zordon job.
Use `All` to select every camera or `Active Only` to render just the active
scene camera.
## Camera Behavior
At least one camera must be selected. The add-on prevents unchecking the final
selected camera.
When one camera is selected, the add-on sends a single job with:
```json
{
"args": {
"camera": "Camera"
}
}
```
When multiple cameras are selected, the add-on sends `child_jobs`. Each child job
gets its own camera argument and output name suffix, such as:
```json
{
"name": "scene_Camera-001",
"output_path": "scene_Camera-001",
"args": {
"camera": "Camera.001"
}
}
```
## Troubleshooting
### Could Not Reach Zordon
Make sure the Zordon server is running and reachable from Blender.
Check from a terminal:
```bash
curl http://localhost:8080/api/heartbeat
```
If the server is remote, replace `localhost` with the server hostname or IP.
### No Cameras Found
Add at least one Blender camera to the scene before submitting.
### Output Files Already Exist
Multiple camera jobs should use camera-specific output names. If they collide,
make sure the Zordon server includes the output-path fix that preserves child
job `output_path` values.
## Packaging
The add-on source lives at:
```text
addons/blender/zordon_blender/
```
The installable archive is:
```text
addons/blender/zordon_blender.zip
```
Rebuild the archive from `addons/blender`:
```bash
python3 -m zipfile -c zordon_blender.zip zordon_blender
```
## Notes
- The add-on is dependency-free and uses Blender's bundled Python standard
library.
- Only `http://` Zordon servers are currently supported.
- `Save Before Submit` is enabled by default so the uploaded file matches the
current Blender state.
+621
View File
@@ -0,0 +1,621 @@
bl_info = {
'name': 'Zordon Render Submitter',
'author': 'Zordon',
'version': (0, 1, 0),
'blender': (3, 6, 0),
'location': 'Properties > Render > Zordon',
'description': 'Submit the current Blender file to a Zordon render server.',
'category': 'Render',
}
import getpass
import http.client
import json
import os
import re
import socket
import subprocess
import time
from urllib.parse import urlparse
from urllib.request import Request, urlopen
from urllib.error import HTTPError, URLError
import bpy
from bpy.props import BoolProperty, EnumProperty, IntProperty, StringProperty
from bpy.types import AddonPreferences, Operator, Panel, PropertyGroup
DEFAULT_SERVER = 'localhost:8080'
DEFAULT_TIMEOUT = 10
UPLOAD_TIMEOUT = 300
ZORDON_SERVICE_TYPE = '_zordon._tcp.local.'
def _addon_preferences(context):
return context.preferences.addons[__name__].preferences
def _configured_server_items(self, context):
preferences = _addon_preferences(context)
raw_servers = [server.strip() for server in preferences.servers.split(',')]
servers = [server for server in raw_servers if server]
if not servers:
servers = [DEFAULT_SERVER]
return [(server, server, '', index) for index, server in enumerate(servers)]
def _normalize_server_url(server, fallback_port):
if not server:
server = DEFAULT_SERVER
server = server.strip()
if not server.startswith(('http://', 'https://')):
server = f'http://{server}'
parsed = urlparse(server)
hostname = parsed.hostname or 'localhost'
scheme = parsed.scheme or 'http'
port = parsed.port or fallback_port or 8080
return scheme, hostname, int(port)
def _api_url(server, port, path):
scheme, hostname, parsed_port = _normalize_server_url(server, port)
return f'{scheme}://{hostname}:{parsed_port}{path}'
def _get_text(server, port, path, timeout=DEFAULT_TIMEOUT):
request = Request(_api_url(server, port, path), method='GET')
with urlopen(request, timeout=timeout) as response:
return response.status, response.read().decode('utf-8')
def _server_list_from_preferences(preferences):
return [server.strip() for server in preferences.servers.split(',') if server.strip()]
def _save_server_list(preferences, servers):
unique_servers = []
for server in servers:
if server and server not in unique_servers:
unique_servers.append(server)
preferences.servers = ', '.join(unique_servers)
def _discover_servers_with_zeroconf(timeout=3.0):
try:
from zeroconf import ServiceBrowser, Zeroconf
except ImportError:
return []
discovered = []
zeroconf = Zeroconf()
class Listener:
def add_service(self, zc, service_type, name):
info = zc.get_service_info(service_type, name, timeout=1000)
if info and info.server and info.port:
discovered.append(f'{info.server.rstrip(".")}:{info.port}')
def update_service(self, zc, service_type, name):
self.add_service(zc, service_type, name)
def remove_service(self, zc, service_type, name):
pass
try:
ServiceBrowser(zeroconf, ZORDON_SERVICE_TYPE, Listener())
time.sleep(timeout)
finally:
zeroconf.close()
return discovered
def _discover_service_names_with_dns_sd(timeout=2.0):
try:
process = subprocess.Popen(
['dns-sd', '-B', '_zordon', '_tcp', 'local'],
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL,
text=True,
)
except (FileNotFoundError, OSError):
return []
try:
stdout, _ = process.communicate(timeout=timeout)
except subprocess.TimeoutExpired:
process.terminate()
stdout, _ = process.communicate(timeout=1)
service_names = []
for line in stdout.splitlines():
if ' Add ' not in line:
continue
parts = line.split()
if len(parts) >= 7:
service_name = ' '.join(parts[6:])
if service_name and service_name not in service_names:
service_names.append(service_name)
return service_names
def _resolve_service_with_dns_sd(service_name, timeout=2.0):
try:
process = subprocess.Popen(
['dns-sd', '-L', service_name, '_zordon', '_tcp', 'local'],
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL,
text=True,
)
except (FileNotFoundError, OSError):
return None
try:
stdout, _ = process.communicate(timeout=timeout)
except subprocess.TimeoutExpired:
process.terminate()
stdout, _ = process.communicate(timeout=1)
for line in stdout.splitlines():
if ' can be reached at ' not in line:
continue
match = re.search(r'can be reached at\s+([^:\s]+):(\d+)', line)
if match:
hostname, port = match.groups()
return f'{hostname.rstrip(".")}:{port}'
return None
def _discover_servers_with_dns_sd():
servers = []
for service_name in _discover_service_names_with_dns_sd():
server = _resolve_service_with_dns_sd(service_name)
if server and server not in servers:
servers.append(server)
return servers
def _discover_zordon_servers():
discovered = _discover_servers_with_zeroconf()
if discovered:
return discovered
return _discover_servers_with_dns_sd()
def _send_multipart_job(server, port, job_data, file_path):
scheme, hostname, parsed_port = _normalize_server_url(server, port)
if scheme != 'http':
raise ValueError('Only http:// Zordon servers are currently supported.')
boundary = f'----ZordonBlender{int(time.time() * 1000)}'
json_payload = json.dumps(job_data).encode('utf-8')
file_name = os.path.basename(file_path)
file_size = os.path.getsize(file_path)
parts_before_file = [
f'--{boundary}\r\n',
'Content-Disposition: form-data; name="json"\r\n',
'Content-Type: application/json\r\n\r\n',
json_payload.decode('utf-8'),
'\r\n',
f'--{boundary}\r\n',
f'Content-Disposition: form-data; name="file"; filename="{file_name}"\r\n',
'Content-Type: application/octet-stream\r\n\r\n',
]
preamble = ''.join(parts_before_file).encode('utf-8')
closing = f'\r\n--{boundary}--\r\n'.encode('utf-8')
content_length = len(preamble) + file_size + len(closing)
connection = http.client.HTTPConnection(hostname, parsed_port, timeout=UPLOAD_TIMEOUT)
try:
connection.putrequest('POST', '/api/jobs')
connection.putheader('Content-Type', f'multipart/form-data; boundary={boundary}')
connection.putheader('Content-Length', str(content_length))
connection.endheaders()
connection.send(preamble)
with open(file_path, 'rb') as upload_file:
while True:
chunk = upload_file.read(1024 * 1024)
if not chunk:
break
connection.send(chunk)
connection.send(closing)
response = connection.getresponse()
response_body = response.read().decode('utf-8', errors='replace')
return response.status, response_body
finally:
connection.close()
def _current_file_path():
return bpy.data.filepath
def _default_job_name():
file_path = _current_file_path()
if file_path:
return os.path.splitext(os.path.basename(file_path))[0]
return 'Blender Render'
def _camera_objects():
return [obj for obj in bpy.data.objects if obj.type == 'CAMERA']
def _default_selected_camera_names(scene):
cameras = _camera_objects()
if not cameras:
return []
if scene.camera:
return [scene.camera.name]
if len(cameras) == 1:
return [cameras[0].name]
return []
def _selected_camera_names(props, scene=None):
if props.selected_cameras:
try:
names = json.loads(props.selected_cameras)
except json.JSONDecodeError:
names = []
existing_names = {camera.name for camera in _camera_objects()}
selected_names = [name for name in names if name in existing_names]
if selected_names:
return selected_names
if scene:
return _default_selected_camera_names(scene)
return []
def _set_selected_camera_names(props, camera_names):
props.selected_cameras = json.dumps(list(camera_names))
def _active_camera_names(scene):
if scene.camera:
return [scene.camera.name]
return _default_selected_camera_names(scene)
def _scene_export_format(scene):
file_format = scene.render.image_settings.file_format
return file_format or 'PNG'
class ZORDON_AddonPreferences(AddonPreferences):
bl_idname = __name__
servers: StringProperty(
name='Servers',
description='Comma-separated Zordon servers. Example: studio-render.local:8080, localhost:8080',
default=DEFAULT_SERVER,
)
def draw(self, context):
layout = self.layout
layout.prop(self, 'servers')
layout.operator('zordon.discover_servers', icon='VIEWZOOM')
class ZORDON_SubmissionProperties(PropertyGroup):
server: EnumProperty(
name='Server',
description='Zordon server to submit this file to',
items=_configured_server_items,
)
port: IntProperty(
name='Fallback Port',
description='Port used when the selected server does not include one',
default=8080,
min=1,
max=65535,
)
job_name: StringProperty(
name='Job Name',
description='Name shown in Zordon',
default='',
)
output_path: StringProperty(
name='Output Name',
description='Output name or path used by the Zordon job',
default='',
)
notes: StringProperty(
name='Notes',
description='Optional notes for the Zordon job',
default='',
)
save_before_submit: BoolProperty(
name='Save Before Submit',
description='Save the current .blend before uploading it',
default=True,
)
use_scene_frame_range: BoolProperty(
name='Use Scene Frame Range',
description='Submit the current scene frame start and end',
default=True,
)
selected_cameras: StringProperty(
name='Selected Cameras',
description='JSON encoded list of selected camera names',
default='',
options={'HIDDEN'},
)
class ZORDON_OT_DiscoverServers(Operator):
bl_idname = 'zordon.discover_servers'
bl_label = 'Discover Servers'
bl_description = 'Find Zordon servers advertised with Zeroconf'
def execute(self, context):
preferences = _addon_preferences(context)
existing_servers = _server_list_from_preferences(preferences)
discovered_servers = _discover_zordon_servers()
if not discovered_servers:
self.report({'WARNING'}, 'No Zordon servers found.')
return {'CANCELLED'}
merged_servers = existing_servers + discovered_servers
_save_server_list(preferences, merged_servers)
props = getattr(context.scene, 'zordon_submission', None)
if props:
try:
props.server = discovered_servers[0]
except (TypeError, ValueError):
pass
self.report({'INFO'}, f'Found {len(discovered_servers)} Zordon server(s).')
return {'FINISHED'}
class ZORDON_OT_TestConnection(Operator):
bl_idname = 'zordon.test_connection'
bl_label = 'Test Connection'
bl_description = 'Check whether the selected Zordon server is reachable'
def execute(self, context):
props = context.scene.zordon_submission
try:
status, body = _get_text(props.server, props.port, '/api/heartbeat')
except (HTTPError, URLError, TimeoutError, OSError) as error:
self.report({'ERROR'}, f'Could not reach Zordon: {error}')
return {'CANCELLED'}
if status == 200:
self.report({'INFO'}, f'Connected to Zordon: {body}')
return {'FINISHED'}
self.report({'ERROR'}, f'Unexpected response from Zordon: HTTP {status}')
return {'CANCELLED'}
class ZORDON_OT_RefreshCameras(Operator):
bl_idname = 'zordon.refresh_cameras'
bl_label = 'Refresh Cameras'
bl_description = 'Refresh the camera checklist from the current Blender scene'
def execute(self, context):
_set_selected_camera_names(
context.scene.zordon_submission,
_default_selected_camera_names(context.scene),
)
return {'FINISHED'}
class ZORDON_OT_ToggleCamera(Operator):
bl_idname = 'zordon.toggle_camera'
bl_label = 'Toggle Camera'
bl_description = 'Toggle whether this camera is submitted to Zordon'
camera_name: StringProperty(name='Camera Name')
def execute(self, context):
props = context.scene.zordon_submission
selected = set(_selected_camera_names(props, context.scene))
if self.camera_name in selected:
if len(selected) == 1:
self.report({'WARNING'}, 'At least one camera must be selected.')
return {'CANCELLED'}
selected.remove(self.camera_name)
else:
selected.add(self.camera_name)
_set_selected_camera_names(props, sorted(selected))
return {'FINISHED'}
class ZORDON_OT_SelectAllCameras(Operator):
bl_idname = 'zordon.select_all_cameras'
bl_label = 'All'
bl_description = 'Select all cameras for submission'
def execute(self, context):
props = context.scene.zordon_submission
_set_selected_camera_names(props, [camera.name for camera in _camera_objects()])
return {'FINISHED'}
class ZORDON_OT_SelectActiveCamera(Operator):
bl_idname = 'zordon.select_active_camera'
bl_label = 'Active Only'
bl_description = 'Select only the active scene camera'
def execute(self, context):
active_cameras = _active_camera_names(context.scene)
if not active_cameras:
self.report({'WARNING'}, 'No cameras found.')
return {'CANCELLED'}
_set_selected_camera_names(context.scene.zordon_submission, active_cameras)
return {'FINISHED'}
class ZORDON_OT_SubmitCurrentFile(Operator):
bl_idname = 'zordon.submit_current_file'
bl_label = 'Submit Current File'
bl_description = 'Upload the current Blender file to the selected Zordon server'
def execute(self, context):
props = context.scene.zordon_submission
scene = context.scene
file_path = _current_file_path()
if not file_path:
self.report({'ERROR'}, 'Save this Blender file before submitting it to Zordon.')
return {'CANCELLED'}
if props.save_before_submit:
bpy.ops.wm.save_as_mainfile(filepath=file_path)
job_name = props.job_name.strip() or _default_job_name()
output_path = props.output_path.strip() or job_name
selected_cameras = _selected_camera_names(props, scene)
if not selected_cameras:
self.report({'ERROR'}, 'Add at least one camera before submitting to Zordon.')
return {'CANCELLED'}
resolution = (
int(scene.render.resolution_x),
int(scene.render.resolution_y),
)
job_data = {
'owner': f'{getpass.getuser()}@{socket.gethostname()}',
'engine_name': 'blender',
'engine_version': 'latest',
'name': job_name,
'output_path': output_path,
'start_frame': int(scene.frame_start) if props.use_scene_frame_range else int(scene.frame_current),
'end_frame': int(scene.frame_end) if props.use_scene_frame_range else int(scene.frame_current),
'priority': 1,
'notes': props.notes,
'enable_split_jobs': False,
'split_jobs_same_os': False,
'args': {
'raw': '',
'export_format': _scene_export_format(scene),
'resolution': resolution,
'fps': scene.render.fps,
},
}
if len(selected_cameras) == 1:
job_data['args']['camera'] = selected_cameras[0]
elif len(selected_cameras) > 1:
child_jobs = []
for camera_name in selected_cameras:
camera_suffix = camera_name.replace(' ', '-')
child_args = dict(job_data['args'])
child_args['camera'] = camera_name
child_jobs.append({
'name': f'{job_name}_{camera_suffix}',
'output_path': f'{output_path}_{camera_suffix}',
'args': child_args,
})
job_data['child_jobs'] = child_jobs
try:
status, body = _send_multipart_job(props.server, props.port, job_data, file_path)
except (ValueError, TimeoutError, OSError) as error:
self.report({'ERROR'}, f'Error submitting to Zordon: {error}')
return {'CANCELLED'}
if 200 <= status < 300:
self.report({'INFO'}, f'Submitted "{job_name}" to Zordon.')
return {'FINISHED'}
self.report({'ERROR'}, f'Zordon returned HTTP {status}: {body}')
return {'CANCELLED'}
class ZORDON_PT_SubmitPanel(Panel):
bl_label = 'Zordon'
bl_idname = 'ZORDON_PT_submit_panel'
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = 'render'
def draw(self, context):
props = context.scene.zordon_submission
layout = self.layout
default_name = _default_job_name()
cameras = _camera_objects()
selected_cameras = set(_selected_camera_names(props, context.scene))
layout.prop(props, 'server')
layout.prop(props, 'port')
row = layout.row(align=True)
row.operator('zordon.discover_servers', icon='VIEWZOOM')
row.operator('zordon.test_connection', icon='LINKED')
layout.separator()
if not props.job_name:
layout.label(text=f'Job Name Default: {default_name}')
layout.prop(props, 'job_name')
if not props.output_path:
layout.label(text=f'Output Name Default: {default_name}')
layout.prop(props, 'output_path')
layout.prop(props, 'notes')
layout.prop(props, 'save_before_submit')
layout.prop(props, 'use_scene_frame_range')
if props.use_scene_frame_range:
layout.label(text=f'Frames: {context.scene.frame_start} - {context.scene.frame_end}')
else:
layout.label(text=f'Frame: {context.scene.frame_current}')
layout.label(text=f'Format: {_scene_export_format(context.scene)}')
layout.separator()
camera_header = layout.row(align=True)
camera_header.label(text='Cameras')
camera_header.operator('zordon.refresh_cameras', text='', icon='FILE_REFRESH')
camera_header.operator('zordon.select_all_cameras', text='All')
camera_header.operator('zordon.select_active_camera', text='Active Only')
if cameras:
for camera in cameras:
icon = 'CHECKBOX_HLT' if camera.name in selected_cameras else 'CHECKBOX_DEHLT'
label = f'{camera.name} - {camera.data.lens:g}mm'
row = layout.row()
op = row.operator('zordon.toggle_camera', text=label, icon=icon, depress=camera.name in selected_cameras)
op.camera_name = camera.name
else:
layout.label(text='No cameras found')
layout.operator('zordon.submit_current_file', icon='RENDER_ANIMATION')
classes = (
ZORDON_AddonPreferences,
ZORDON_SubmissionProperties,
ZORDON_OT_DiscoverServers,
ZORDON_OT_TestConnection,
ZORDON_OT_RefreshCameras,
ZORDON_OT_ToggleCamera,
ZORDON_OT_SelectAllCameras,
ZORDON_OT_SelectActiveCamera,
ZORDON_OT_SubmitCurrentFile,
ZORDON_PT_SubmitPanel,
)
def register():
for cls in classes:
bpy.utils.register_class(cls)
bpy.types.Scene.zordon_submission = bpy.props.PointerProperty(type=ZORDON_SubmissionProperties)
def unregister():
del bpy.types.Scene.zordon_submission
for cls in reversed(classes):
bpy.utils.unregister_class(cls)
if __name__ == '__main__':
register()
Executable
+77
View File
@@ -0,0 +1,77 @@
#!/usr/bin/env python3
import logging
import threading
from collections import deque
from server import ZordonServer
logger = logging.getLogger()
def __setup_buffer_handler():
# lazy load GUI frameworks
from PyQt6.QtCore import QObject, pyqtSignal
class BufferingHandler(logging.Handler, QObject):
new_record = pyqtSignal(str)
flushOnClose = True
def __init__(self, capacity=100):
logging.Handler.__init__(self)
QObject.__init__(self)
self.buffer = deque(maxlen=capacity) # Define a buffer with a fixed capacity
def emit(self, record):
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()
exit_code = app.exec()
# cleanup: remove and close the GUI logging handler before interpreter shutdown
root_logger = logging.getLogger()
if buffer_handler in root_logger.handlers:
root_logger.removeHandler(buffer_handler)
try:
buffer_handler.close()
except Exception:
# never let logging cleanup throw during shutdown
pass
return exit_code
if __name__ == '__main__':
import sys
server = ZordonServer()
server.start_server()
__show_gui(__setup_buffer_handler())
server.stop_server()
sys.exit()
+158
View File
@@ -0,0 +1,158 @@
# -*- mode: python ; coding: utf-8 -*-
from PyInstaller.utils.hooks import collect_all
from pathlib import Path
import os
import sys
import platform
# ------------------------------------------------------------
# Project paths
# ------------------------------------------------------------
project_root = Path(SPECPATH).resolve()
src_dir = project_root / "src"
# Ensure `src.*` imports work during analysis
sys.path.insert(0, str(project_root))
# ------------------------------------------------------------
# Import version info
# ------------------------------------------------------------
from src.version import APP_NAME, APP_VERSION, APP_AUTHOR
APP_NAME = f"{APP_NAME}-client"
# ------------------------------------------------------------
# PyInstaller data / imports
# ------------------------------------------------------------
datas = [
("resources", "resources"),
("src/engines/blender/scripts", "src/engines/blender/scripts"),
]
binaries = []
hiddenimports = ["zeroconf", "src.version"]
tmp_ret = collect_all("zeroconf")
datas += tmp_ret[0]
binaries += tmp_ret[1]
hiddenimports += tmp_ret[2]
# ------------------------------------------------------------
# Analysis
# ------------------------------------------------------------
a = Analysis(
["client.py"],
pathex=[str(project_root)],
binaries=binaries,
datas=datas,
hiddenimports=hiddenimports,
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
noarchive=False,
optimize=1, # optimize=2 breaks Windows builds
)
pyz = PYZ(a.pure)
# ------------------------------------------------------------
# Platform targets
# ------------------------------------------------------------
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,
)
+2
View File
@@ -2,6 +2,8 @@ upload_folder: "~/zordon-uploads/"
update_engines_on_launch: true
max_content_path: 100000000
server_log_level: info
log_buffer_length: 250
worker_process_timeout: 120
flask_log_level: error
flask_debug_enable: false
queue_eval_seconds: 1
Executable → Regular
+3 -4
View File
@@ -6,7 +6,6 @@ import threading
import time
import traceback
import requests
from rich import box
from rich.console import Console
from rich.layout import Layout
@@ -17,8 +16,8 @@ from rich.table import Table
from rich.text import Text
from rich.tree import Tree
from src.workers.base_worker import RenderStatus, string_to_status
from src.server_proxy import RenderServerProxy
from src.engines.core.base_worker import RenderStatus, string_to_status
from src.api.server_proxy import RenderServerProxy
from src.utilities.misc_helper import get_time_elapsed
from start_server import start_server
@@ -202,7 +201,7 @@ if __name__ == '__main__':
start_server_input = input("Local server not running. Start server? (y/n) ")
if start_server_input and start_server_input[0].lower() == "y":
# Startup the local server
start_server(background_thread=True)
start_server()
test = server_proxy.connect()
print(f"connected? {test}")
else:
+487
View File
@@ -0,0 +1,487 @@
# Zordon API Reference
Zordon exposes a Flask API from `src/api/api_server.py`. The server is started by
`start_api_server()` and listens on `Config.port_number` with all application
routes mounted under `/api`.
The in-repo client wrapper is `src/api/server_proxy.py`. Most UI and distributed
rendering code should prefer `RenderServerProxy` instead of constructing request
URLs directly.
## Versioning
- Current API version: `0.1`
- `RenderServerProxy.request()` sends `X-API-Version` with the current
`API_VERSION`, but the server does not currently validate this header.
## Response Conventions
- JSON endpoints return Flask-serialized dictionaries or lists.
- File endpoints return `send_file()` responses.
- Most error responses are plain text with HTTP `400`, `404`, `500`, or `503`.
- `JobNotFoundError` is mapped to HTTP `400`.
- Unhandled exceptions are mapped to HTTP `500` with a plain-text message.
## Jobs
### `GET /api/jobs`
Returns all render jobs and a cache token.
Response:
```json
{
"jobs": [
{
"id": "job-id",
"name": "job name",
"status": "running"
}
],
"token": "cache-token"
}
```
Known callers:
- `RenderServerProxy.get_jobs()`
- `src/ui/main_window.py`
### `GET /api/jobs/long_poll`
Long-polls the job list until the supplied cache token changes or 30 seconds
elapse.
Query parameters:
| Name | Required | Description |
| --- | --- | --- |
| `token` | No | Cache token returned by `/api/jobs`. |
Responses:
- `200` with the same shape as `/api/jobs` when jobs changed.
- `204` with an empty body when no changes arrive before timeout.
Known callers:
- `RenderServerProxy.get_jobs()` through the background cache updater.
### `GET /api/jobs/status/<status_val>`
Returns jobs matching a render status.
Path parameters:
| Name | Description |
| --- | --- |
| `status_val` | Status string converted by `string_to_status()`. |
Responses:
- `200` with a list of job JSON objects when matches exist.
- `400` when no jobs match the requested status.
Review note: this route is not currently wrapped by `RenderServerProxy` and no
in-repo callers were found.
### `GET /api/jobs/<job_id>`
Returns one job as JSON.
Known callers:
- `RenderServerProxy.get_job()`
- `add_job.py`
- `src/ui/main_window.py`
- `src/distributed_job_manager.py`
- `tests/job_creation_tests.py`
### `GET /api/jobs/<job_id>/logs`
Returns the job log file as `text/plain`.
Known callers:
- `src/ui/main_window.py` opens this URL directly.
### `GET /api/jobs/<job_id>/files`
Returns a list of output filenames for the job.
Known callers:
- `RenderServerProxy.get_job_files()`
- `src/utilities/server_helper.py`
### `GET /api/jobs/<job_id>/download`
Downloads one output file.
Query parameters:
| Name | Required | Description |
| --- | --- | --- |
| `filename` | Yes | Case-insensitive filename from the job file list. |
Responses:
- `200` with the requested file as an attachment.
- `400` when `filename` is missing.
- `404` when the file is not found.
Known callers:
- `RenderServerProxy.download_job_file()`
- `src/utilities/server_helper.py`
### `GET /api/jobs/<job_id>/download_all`
Creates a temporary zip of the job output directory and downloads it.
Known callers:
- `RenderServerProxy.download_all_job_files()`
- `src/ui/main_window.py`
- `src/utilities/server_helper.py`
### `GET /api/jobs/<job_id>/thumbnail`
Returns a generated preview image or video for a job.
Query parameters:
| Name | Required | Description |
| --- | --- | --- |
| `size` | No | `big` selects the larger preview path. Currently parsed but not applied. |
| `video_ok` | No | If truthy and a video preview exists, video can be returned. |
Responses:
- `200` with `image/jpeg` or `video/mp4`.
- `404` when no thumbnail is available.
- `500` on preview generation errors.
Known callers:
- `src/ui/main_window.py`
Review note: `size=big` is parsed into `big_thumb` but not used.
## Job Lifecycle
### `POST /api/jobs`
Adds one or more render jobs.
Request formats:
- JSON request body.
- Multipart form with a `json` field and optional `file` upload.
Common job fields include:
| Name | Description |
| --- | --- |
| `name` | Display name for the render job. |
| `renderer` | Render engine name such as `blender` or `ffmpeg`. |
| `start_frame` | First frame to render. |
| `end_frame` | Last frame to render. |
| `args` | Engine-specific render arguments. |
| `enable_split_jobs` | Whether distributed subjobs may be created. |
| `child_jobs` | Optional subjob definitions. |
| `local_path` | Local file path used when posting to localhost. |
Responses:
- `200` with created job data.
- `400` for invalid or missing job data.
- `500` for unexpected processing or creation errors.
Known callers:
- `RenderServerProxy.create_job()`
- `add_job.py`
- `src/ui/add_job_window.py`
- `src/distributed_job_manager.py`
- `tests/job_creation_tests.py`
### `POST /api/jobs/<job_id>/cancel`
Cancels a job.
Query parameters:
| Name | Required | Description |
| --- | --- | --- |
| `confirm` | Yes | Must be truthy or the request is rejected. |
| `redirect` | No | If truthy, redirects to `index`. |
Known callers:
- `RenderServerProxy.cancel_job()`
- `src/ui/main_window.py`
- `src/distributed_job_manager.py`
### `POST /api/jobs/<job_id>/delete`
Deletes a job, stops it first, deletes previews, and removes owned upload/output
directories when safe.
Query parameters:
| Name | Required | Description |
| --- | --- | --- |
| `confirm` | Yes | Must be truthy or the request is rejected. |
Known callers:
- `RenderServerProxy.delete_job()`
- `src/ui/main_window.py`
### `POST /api/jobs/<job_id>/subjob_update`
Notifies a parent job that a child/subjob changed state.
Request body:
- JSON representation of a subjob.
Known callers:
- `RenderServerProxy.send_subjob_update_notification()`
- `src/distributed_job_manager.py`
## Status and Environment
### `GET /api/heartbeat`
Returns the current timestamp as plain text. Used for fast connectivity checks.
Known callers:
- `RenderServerProxy.check_connection()`
### `GET /api/status`
Returns local system and queue status.
Response includes:
- timestamp
- operating system and version
- CPU brand, count, and current utilization
- memory totals and current utilization
- job counts
- hostname and port
- app and API versions
Known callers:
- `RenderServerProxy.get_status()`
### `GET /api/presets`
Returns `config/presets.yaml`.
Review note: no in-repo callers were found.
### `GET /api/cpu_benchmark`
Runs a CPU benchmark for 10 seconds and returns the score as plain text.
Known callers:
- `src/utilities/server_helper.py`
### `GET /api/disk_benchmark`
Runs a disk I/O benchmark and returns write/read speeds.
Review note: no in-repo callers were found.
## Engines
### `GET /api/engines/for_filename`
Returns the engine name suitable for a project filename.
Query parameters:
| Name | Required | Description |
| --- | --- | --- |
| `filename` | Yes | Project filename or path. The client currently sends only the basename. |
Known callers:
- `RenderServerProxy.get_engine_for_filename()`
- `src/ui/add_job_window.py`
### `GET /api/engines`
Returns installed engine data keyed by engine name.
Query parameters:
| Name | Required | Description |
| --- | --- | --- |
| `response_type` | No | `standard` or `full`; defaults to `standard`. |
`full` responses also include supported extensions, supported export formats,
system info, and UI options.
Known callers:
- `RenderServerProxy.get_engines()`
- `src/ui/settings_window.py`
- `src/ui/engine_browser.py`
### `GET /api/engines/names`
Returns installed engine names as a list without instantiating engine classes.
Use this for lightweight selection UIs that only need engine names.
Known callers:
- `RenderServerProxy.get_engine_names()`
- `src/ui/add_job_window.py`
### `GET /api/engines/<engine_name>`
Returns installed version data for a single engine.
Query parameters:
| Name | Required | Description |
| --- | --- | --- |
| `response_type` | No | `standard` or `full`; defaults to `standard`. |
`full` responses also include supported extensions, supported export formats,
system info, and UI options.
Known callers:
- `RenderServerProxy.get_engine()`
- `src/ui/add_job_window.py`
### `GET /api/engines/<engine_name>/availability`
Returns whether an engine can accept jobs on this server, plus CPU count,
installed versions, and hostname.
Known callers:
- `RenderServerProxy.get_engine_availability()`
- `src/distributed_job_manager.py`
### `GET /api/engines/<engine_name>/args`
Returns engine arguments.
Review note: no in-repo callers were found.
### `GET /api/engines/<engine_name>/help`
Returns engine help text.
Known callers:
- `src/ui/add_job_window.py` opens this URL directly.
### `GET /api/engines/download_available`
Checks whether a managed engine version is available to download.
Query parameters:
| Name | Required | Description |
| --- | --- | --- |
| `engine` | Yes | Engine name. |
| `version` | Yes | Engine version. |
| `system_os` | No | Target OS. |
| `cpu` | No | Target CPU architecture. |
Review note: no in-repo callers were found.
### `GET /api/engines/most_recent_version`
Finds the most recent downloadable version for an engine.
Query parameters:
| Name | Required | Description |
| --- | --- | --- |
| `engine` | Yes | Engine name. |
| `system_os` | No | Target OS. |
| `cpu` | No | Target CPU architecture. |
Review note: no in-repo callers were found.
### `POST /api/engines/download`
Downloads a managed engine version.
Query parameters:
| Name | Required | Description |
| --- | --- | --- |
| `engine` | Yes | Engine name. |
| `version` | Yes | Engine version. |
| `system_os` | No | Target OS. |
| `cpu` | No | Target CPU architecture. |
Review note: no in-repo callers were found. Settings currently calls
`EngineManager.download_engine()` directly instead of this API route.
### `POST /api/engines/delete`
Deletes a managed engine download.
JSON body:
| Name | Required | Description |
| --- | --- | --- |
| `engine` | Yes | Engine name. |
| `version` | Yes | Engine version. |
| `system_os` | No | Target OS. |
| `cpu` | No | Target CPU architecture. |
Known callers:
- `RenderServerProxy.delete_engine_download()`
- `src/ui/engine_browser.py`
## Debug
### `GET /api/_debug/detected_clients`
Returns hostnames detected by Zeroconf.
Review note: development/debug only, with an inline comment saying it probably
should not ship.
### `POST /api/_debug/clear_history`
Clears render queue history and returns `success`.
Review note: development/debug only.
## Redundancy and Cleanup Review
Routes with no in-repo callers found:
- `GET /api/jobs/status/<status_val>`
- `GET /api/presets`
- `GET /api/disk_benchmark`
- `GET /api/engines/<engine_name>/args`
- `GET /api/engines/download_available`
- `GET /api/engines/most_recent_version`
- `POST /api/engines/download`
- `GET /api/_debug/detected_clients`
- `POST /api/_debug/clear_history`
Routes or methods with cleanup risks:
- `job_thumbnail()` parses `size=big` but never uses the resulting `big_thumb`
value.
+577
View File
@@ -0,0 +1,577 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Zordon API Reference</title>
<style>
:root {
--bg: #0d1117;
--surface: #161b22;
--surface2: #1c2333;
--border: #30363d;
--text: #e6edf3;
--text-muted: #8b949e;
--blue: #58a6ff;
--green: #3fb950;
--orange: #d29922;
--red: #f85149;
--purple: #bc8cff;
--cyan: #39d2c0;
}
* { box-sizing: border-box; }
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
background: var(--bg);
color: var(--text);
line-height: 1.6;
}
header {
border-bottom: 1px solid var(--border);
padding: 56px 24px 36px;
text-align: center;
}
header h1 {
margin: 0 0 10px;
font-size: 2.7rem;
font-weight: 800;
color: var(--text);
}
header p {
max-width: 760px;
margin: 0 auto;
color: var(--text-muted);
font-size: 1.05rem;
}
main {
display: grid;
grid-template-columns: 250px minmax(0, 1fr);
gap: 32px;
max-width: 1180px;
margin: 0 auto;
padding: 36px 24px 56px;
}
nav {
position: sticky;
top: 18px;
align-self: start;
background: var(--surface);
border: 1px solid var(--border);
border-radius: 8px;
padding: 16px;
}
nav strong {
display: block;
margin-bottom: 8px;
color: var(--text);
}
nav a {
display: block;
padding: 5px 0;
color: var(--text-muted);
text-decoration: none;
font-size: .92rem;
}
nav a:hover { color: var(--blue); }
section { margin-bottom: 44px; }
h2 {
display: inline-block;
margin: 0 0 18px;
padding-bottom: 8px;
border-bottom: 2px solid var(--blue);
font-size: 1.45rem;
}
h3 {
margin: 0 0 10px;
color: var(--cyan);
font-size: 1.08rem;
}
p, li { color: var(--text-muted); }
code {
font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
background: var(--surface2);
border-radius: 4px;
padding: 2px 5px;
color: var(--cyan);
font-size: .9em;
}
pre {
margin: 12px 0;
padding: 14px;
overflow-x: auto;
background: var(--surface);
border: 1px solid var(--border);
border-radius: 8px;
color: var(--text);
}
pre code {
padding: 0;
background: transparent;
color: inherit;
}
table {
width: 100%;
margin: 12px 0;
border-collapse: collapse;
font-size: .92rem;
}
th, td {
padding: 9px 10px;
border: 1px solid var(--border);
text-align: left;
vertical-align: top;
}
th {
background: var(--surface2);
color: var(--text);
font-weight: 600;
}
td { color: var(--text-muted); }
.meta-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
gap: 14px;
margin-bottom: 24px;
}
.panel, .endpoint {
background: var(--surface);
border: 1px solid var(--border);
border-radius: 8px;
padding: 18px;
}
.panel h3 { color: var(--text); }
.panel ul { margin: 8px 0 0; padding-left: 20px; }
.endpoint {
margin-bottom: 16px;
}
.endpoint-header {
display: flex;
align-items: baseline;
gap: 10px;
flex-wrap: wrap;
margin-bottom: 8px;
}
.method {
display: inline-block;
min-width: 52px;
padding: 2px 8px;
border-radius: 4px;
text-align: center;
font-weight: 700;
font-size: .76rem;
letter-spacing: .02em;
}
.get { background: rgba(88, 166, 255, .16); color: var(--blue); border: 1px solid rgba(88, 166, 255, .35); }
.post { background: rgba(63, 185, 80, .16); color: var(--green); border: 1px solid rgba(63, 185, 80, .35); }
.multi { background: rgba(210, 153, 34, .16); color: var(--orange); border: 1px solid rgba(210, 153, 34, .35); }
.path {
color: var(--text);
font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
font-weight: 650;
overflow-wrap: anywhere;
}
.note {
margin-top: 12px;
padding: 10px 12px;
border-left: 3px solid var(--orange);
background: rgba(210, 153, 34, .08);
color: var(--text-muted);
}
.danger {
border-left-color: var(--red);
background: rgba(248, 81, 73, .08);
}
.callers {
margin: 10px 0 0;
padding-left: 20px;
}
.callers li { margin: 2px 0; }
@media (max-width: 820px) {
main { grid-template-columns: 1fr; }
nav { position: static; }
header h1 { font-size: 2.1rem; }
}
</style>
</head>
<body>
<header>
<h1>Zordon API Reference</h1>
<p>Flask endpoints exposed by <code>src/api/api_server.py</code>, with the in-repo client wrapper in <code>src/api/server_proxy.py</code>.</p>
</header>
<main>
<nav aria-label="API sections">
<strong>Sections</strong>
<a href="#overview">Overview</a>
<a href="#jobs">Jobs</a>
<a href="#job-lifecycle">Job Lifecycle</a>
<a href="#status">Status and Environment</a>
<a href="#engines">Engines</a>
<a href="#debug">Debug</a>
<a href="#cleanup">Cleanup Review</a>
</nav>
<div>
<section id="overview">
<h2>Overview</h2>
<div class="meta-grid">
<div class="panel">
<h3>Versioning</h3>
<ul>
<li>Current API version: <code>0.1</code></li>
<li><code>RenderServerProxy.request()</code> sends <code>X-API-Version</code>.</li>
<li>The server does not currently validate that header.</li>
</ul>
</div>
<div class="panel">
<h3>Response Conventions</h3>
<ul>
<li>JSON endpoints return Flask-serialized dictionaries or lists.</li>
<li>File endpoints return <code>send_file()</code> responses.</li>
<li>Most errors are plain text with <code>400</code>, <code>404</code>, <code>500</code>, or <code>503</code>.</li>
<li><code>JobNotFoundError</code> maps to HTTP <code>400</code>.</li>
</ul>
</div>
</div>
</section>
<section id="jobs">
<h2>Jobs</h2>
<article class="endpoint">
<div class="endpoint-header"><span class="method get">GET</span><span class="path">/api/jobs</span></div>
<p>Returns all render jobs and a cache token.</p>
<pre><code>{
"jobs": [{"id": "job-id", "name": "job name", "status": "running"}],
"token": "cache-token"
}</code></pre>
<p>Known callers:</p>
<ul class="callers">
<li><code>RenderServerProxy.get_jobs()</code></li>
<li><code>src/ui/main_window.py</code></li>
</ul>
</article>
<article class="endpoint">
<div class="endpoint-header"><span class="method get">GET</span><span class="path">/api/jobs/long_poll</span></div>
<p>Long-polls the job list until the supplied cache token changes or 30 seconds elapse.</p>
<table>
<tr><th>Query Parameter</th><th>Required</th><th>Description</th></tr>
<tr><td><code>token</code></td><td>No</td><td>Cache token returned by <code>/api/jobs</code>.</td></tr>
</table>
<p>Returns <code>200</code> with job data when changed, or <code>204</code> when no change arrives before timeout.</p>
</article>
<article class="endpoint">
<div class="endpoint-header"><span class="method get">GET</span><span class="path">/api/jobs/status/&lt;status_val&gt;</span></div>
<p>Returns jobs matching a render status converted by <code>string_to_status()</code>.</p>
<div class="note">No <code>RenderServerProxy</code> wrapper or in-repo caller was found.</div>
</article>
<article class="endpoint">
<div class="endpoint-header"><span class="method get">GET</span><span class="path">/api/jobs/&lt;job_id&gt;</span></div>
<p>Returns one job as JSON.</p>
<p>Known callers include <code>RenderServerProxy.get_job()</code>, <code>add_job.py</code>, <code>src/ui/main_window.py</code>, <code>src/distributed_job_manager.py</code>, and <code>tests/job_creation_tests.py</code>.</p>
</article>
<article class="endpoint">
<div class="endpoint-header"><span class="method get">GET</span><span class="path">/api/jobs/&lt;job_id&gt;/logs</span></div>
<p>Returns the job log file as <code>text/plain</code>. The main window opens this URL directly.</p>
</article>
<article class="endpoint">
<div class="endpoint-header"><span class="method get">GET</span><span class="path">/api/jobs/&lt;job_id&gt;/files</span></div>
<p>Returns a list of output filenames for the job.</p>
<p>Known callers: <code>RenderServerProxy.get_job_files()</code> and <code>src/utilities/server_helper.py</code>.</p>
</article>
<article class="endpoint">
<div class="endpoint-header"><span class="method get">GET</span><span class="path">/api/jobs/&lt;job_id&gt;/download</span></div>
<p>Downloads one output file.</p>
<table>
<tr><th>Query Parameter</th><th>Required</th><th>Description</th></tr>
<tr><td><code>filename</code></td><td>Yes</td><td>Case-insensitive filename from the job file list.</td></tr>
</table>
<p>Returns <code>200</code> with an attachment, <code>400</code> when <code>filename</code> is missing, or <code>404</code> when the file is not found.</p>
</article>
<article class="endpoint">
<div class="endpoint-header"><span class="method get">GET</span><span class="path">/api/jobs/&lt;job_id&gt;/download_all</span></div>
<p>Creates a temporary zip of the job output directory and downloads it.</p>
<p>Known callers: <code>RenderServerProxy.download_all_job_files()</code>, <code>src/ui/main_window.py</code>, and <code>src/utilities/server_helper.py</code>.</p>
</article>
<article class="endpoint">
<div class="endpoint-header"><span class="method get">GET</span><span class="path">/api/jobs/&lt;job_id&gt;/thumbnail</span></div>
<p>Returns a generated preview image or video for a job.</p>
<table>
<tr><th>Query Parameter</th><th>Required</th><th>Description</th></tr>
<tr><td><code>size</code></td><td>No</td><td><code>big</code> is parsed but not currently applied.</td></tr>
<tr><td><code>video_ok</code></td><td>No</td><td>If truthy and a video preview exists, video can be returned.</td></tr>
</table>
<div class="note">Cleanup note: <code>size=big</code> is parsed into <code>big_thumb</code> but not used.</div>
</article>
</section>
<section id="job-lifecycle">
<h2>Job Lifecycle</h2>
<article class="endpoint">
<div class="endpoint-header"><span class="method post">POST</span><span class="path">/api/jobs</span></div>
<p>Adds one or more render jobs. Accepts either a JSON request body or multipart form data with a <code>json</code> field and optional <code>file</code> upload.</p>
<table>
<tr><th>Common Field</th><th>Description</th></tr>
<tr><td><code>name</code></td><td>Display name for the render job.</td></tr>
<tr><td><code>renderer</code></td><td>Render engine name such as <code>blender</code> or <code>ffmpeg</code>.</td></tr>
<tr><td><code>start_frame</code></td><td>First frame to render.</td></tr>
<tr><td><code>end_frame</code></td><td>Last frame to render.</td></tr>
<tr><td><code>args</code></td><td>Engine-specific render arguments.</td></tr>
<tr><td><code>enable_split_jobs</code></td><td>Whether distributed subjobs may be created.</td></tr>
<tr><td><code>child_jobs</code></td><td>Optional subjob definitions.</td></tr>
<tr><td><code>local_path</code></td><td>Local file path used when posting to localhost.</td></tr>
</table>
<p>Known callers include <code>RenderServerProxy.create_job()</code>, <code>add_job.py</code>, <code>src/ui/add_job_window.py</code>, <code>src/distributed_job_manager.py</code>, and integration tests.</p>
</article>
<article class="endpoint">
<div class="endpoint-header"><span class="method post">POST</span><span class="path">/api/jobs/&lt;job_id&gt;/cancel</span></div>
<p>Cancels a job. Requires a truthy <code>confirm</code> query parameter.</p>
<table>
<tr><th>Query Parameter</th><th>Required</th><th>Description</th></tr>
<tr><td><code>confirm</code></td><td>Yes</td><td>Must be truthy or the request is rejected.</td></tr>
<tr><td><code>redirect</code></td><td>No</td><td>If truthy, redirects to <code>index</code>.</td></tr>
</table>
</article>
<article class="endpoint">
<div class="endpoint-header"><span class="method post">POST</span><span class="path">/api/jobs/&lt;job_id&gt;/delete</span></div>
<p>Deletes a job, stops it first, deletes previews, and removes owned upload/output directories when safe.</p>
<table>
<tr><th>Query Parameter</th><th>Required</th><th>Description</th></tr>
<tr><td><code>confirm</code></td><td>Yes</td><td>Must be truthy or the request is rejected.</td></tr>
</table>
</article>
<article class="endpoint">
<div class="endpoint-header"><span class="method post">POST</span><span class="path">/api/jobs/&lt;job_id&gt;/subjob_update</span></div>
<p>Notifies a parent job that a child/subjob changed state. The request body is the JSON representation of the subjob.</p>
</article>
</section>
<section id="status">
<h2>Status and Environment</h2>
<article class="endpoint">
<div class="endpoint-header"><span class="method get">GET</span><span class="path">/api/heartbeat</span></div>
<p>Returns the current timestamp as plain text. Used by <code>RenderServerProxy.check_connection()</code>.</p>
</article>
<article class="endpoint">
<div class="endpoint-header"><span class="method get">GET</span><span class="path">/api/status</span></div>
<p>Returns local system and queue status, including operating system, CPU, memory, job counts, hostname, port, app version, and API version.</p>
</article>
<article class="endpoint">
<div class="endpoint-header"><span class="method get">GET</span><span class="path">/api/presets</span></div>
<p>Returns <code>config/presets.yaml</code>.</p>
<div class="note">No in-repo callers were found.</div>
</article>
<article class="endpoint">
<div class="endpoint-header"><span class="method get">GET</span><span class="path">/api/cpu_benchmark</span></div>
<p>Runs a CPU benchmark for 10 seconds and returns the score as plain text. Used by <code>src/utilities/server_helper.py</code>.</p>
</article>
<article class="endpoint">
<div class="endpoint-header"><span class="method get">GET</span><span class="path">/api/disk_benchmark</span></div>
<p>Runs a disk I/O benchmark and returns write/read speeds.</p>
<div class="note">No in-repo callers were found.</div>
</article>
</section>
<section id="engines">
<h2>Engines</h2>
<article class="endpoint">
<div class="endpoint-header"><span class="method get">GET</span><span class="path">/api/engines/for_filename</span></div>
<p>Returns the engine name suitable for a project filename.</p>
<table>
<tr><th>Query Parameter</th><th>Required</th><th>Description</th></tr>
<tr><td><code>filename</code></td><td>Yes</td><td>Project filename or path. The client currently sends only the basename.</td></tr>
</table>
</article>
<article class="endpoint">
<div class="endpoint-header"><span class="method get">GET</span><span class="path">/api/engines</span></div>
<p>Returns installed engine data keyed by engine name.</p>
<table>
<tr><th>Query Parameter</th><th>Required</th><th>Description</th></tr>
<tr><td><code>response_type</code></td><td>No</td><td><code>standard</code> or <code>full</code>; defaults to <code>standard</code>.</td></tr>
</table>
<p><code>full</code> responses include supported extensions, supported export formats, system info, and UI options.</p>
<p>Known callers: <code>RenderServerProxy.get_engines()</code>, <code>src/ui/settings_window.py</code>, and <code>src/ui/engine_browser.py</code>.</p>
</article>
<article class="endpoint">
<div class="endpoint-header"><span class="method get">GET</span><span class="path">/api/engines/names</span></div>
<p>Returns installed engine names as a list without instantiating engine classes. Use this for lightweight selection UIs that only need engine names.</p>
<p>Known callers: <code>RenderServerProxy.get_engine_names()</code> and <code>src/ui/add_job_window.py</code>.</p>
</article>
<article class="endpoint">
<div class="endpoint-header"><span class="method get">GET</span><span class="path">/api/engines/&lt;engine_name&gt;</span></div>
<p>Returns installed version data for a single engine.</p>
<table>
<tr><th>Query Parameter</th><th>Required</th><th>Description</th></tr>
<tr><td><code>response_type</code></td><td>No</td><td><code>standard</code> or <code>full</code>; defaults to <code>standard</code>.</td></tr>
</table>
<p><code>full</code> responses include supported extensions, supported export formats, system info, and UI options.</p>
<p>Known caller: <code>RenderServerProxy.get_engine()</code> in the add-job window.</p>
</article>
<article class="endpoint">
<div class="endpoint-header"><span class="method get">GET</span><span class="path">/api/engines/&lt;engine_name&gt;/availability</span></div>
<p>Returns whether an engine can accept jobs on this server, plus CPU count, installed versions, and hostname.</p>
</article>
<article class="endpoint">
<div class="endpoint-header"><span class="method get">GET</span><span class="path">/api/engines/&lt;engine_name&gt;/args</span></div>
<p>Returns engine arguments.</p>
<div class="note">No in-repo callers were found.</div>
</article>
<article class="endpoint">
<div class="endpoint-header"><span class="method get">GET</span><span class="path">/api/engines/&lt;engine_name&gt;/help</span></div>
<p>Returns engine help text. The add-job window opens this URL directly.</p>
</article>
<article class="endpoint">
<div class="endpoint-header"><span class="method get">GET</span><span class="path">/api/engines/download_available</span></div>
<p>Checks whether a managed engine version is available to download.</p>
<table>
<tr><th>Query Parameter</th><th>Required</th><th>Description</th></tr>
<tr><td><code>engine</code></td><td>Yes</td><td>Engine name.</td></tr>
<tr><td><code>version</code></td><td>Yes</td><td>Engine version.</td></tr>
<tr><td><code>system_os</code></td><td>No</td><td>Target OS.</td></tr>
<tr><td><code>cpu</code></td><td>No</td><td>Target CPU architecture.</td></tr>
</table>
<div class="note">No in-repo callers were found.</div>
</article>
<article class="endpoint">
<div class="endpoint-header"><span class="method get">GET</span><span class="path">/api/engines/most_recent_version</span></div>
<p>Finds the most recent downloadable version for an engine.</p>
<table>
<tr><th>Query Parameter</th><th>Required</th><th>Description</th></tr>
<tr><td><code>engine</code></td><td>Yes</td><td>Engine name.</td></tr>
<tr><td><code>system_os</code></td><td>No</td><td>Target OS.</td></tr>
<tr><td><code>cpu</code></td><td>No</td><td>Target CPU architecture.</td></tr>
</table>
<div class="note">No in-repo callers were found.</div>
</article>
<article class="endpoint">
<div class="endpoint-header"><span class="method post">POST</span><span class="path">/api/engines/download</span></div>
<p>Downloads a managed engine version.</p>
<table>
<tr><th>Query Parameter</th><th>Required</th><th>Description</th></tr>
<tr><td><code>engine</code></td><td>Yes</td><td>Engine name.</td></tr>
<tr><td><code>version</code></td><td>Yes</td><td>Engine version.</td></tr>
<tr><td><code>system_os</code></td><td>No</td><td>Target OS.</td></tr>
<tr><td><code>cpu</code></td><td>No</td><td>Target CPU architecture.</td></tr>
</table>
<div class="note">Settings currently calls <code>EngineManager.download_engine()</code> directly instead of this API route.</div>
</article>
<article class="endpoint">
<div class="endpoint-header"><span class="method post">POST</span><span class="path">/api/engines/delete</span></div>
<p>Deletes a managed engine download.</p>
<table>
<tr><th>JSON Field</th><th>Required</th><th>Description</th></tr>
<tr><td><code>engine</code></td><td>Yes</td><td>Engine name.</td></tr>
<tr><td><code>version</code></td><td>Yes</td><td>Engine version.</td></tr>
<tr><td><code>system_os</code></td><td>No</td><td>Target OS.</td></tr>
<tr><td><code>cpu</code></td><td>No</td><td>Target CPU architecture.</td></tr>
</table>
</article>
</section>
<section id="debug">
<h2>Debug</h2>
<article class="endpoint">
<div class="endpoint-header"><span class="method get">GET</span><span class="path">/api/_debug/detected_clients</span></div>
<p>Returns hostnames detected by Zeroconf.</p>
<div class="note">Development/debug only, with an inline comment saying it probably should not ship.</div>
</article>
<article class="endpoint">
<div class="endpoint-header"><span class="method post">POST</span><span class="path">/api/_debug/clear_history</span></div>
<p>Clears render queue history and returns <code>success</code>.</p>
<div class="note">Development/debug only.</div>
</article>
</section>
<section id="cleanup">
<h2>Cleanup Review</h2>
<div class="panel">
<h3>Routes With No In-Repo Callers Found</h3>
<ul>
<li><code>GET /api/jobs/status/&lt;status_val&gt;</code></li>
<li><code>GET /api/presets</code></li>
<li><code>GET /api/disk_benchmark</code></li>
<li><code>GET /api/engines/&lt;engine_name&gt;/args</code></li>
<li><code>GET /api/engines/download_available</code></li>
<li><code>GET /api/engines/most_recent_version</code></li>
<li><code>POST /api/engines/download</code></li>
<li><code>GET /api/_debug/detected_clients</code></li>
<li><code>POST /api/_debug/clear_history</code></li>
</ul>
</div>
<div class="panel" style="margin-top: 14px;">
<h3>Cleanup Risks</h3>
<ul>
<li><code>job_thumbnail()</code> parses <code>size=big</code> but never uses the resulting <code>big_thumb</code> value.</li>
</ul>
</div>
</section>
</div>
</main>
</body>
</html>
Binary file not shown.

After

Width:  |  Height:  |  Size: 838 KiB

+4
View File
@@ -0,0 +1,4 @@
[pytest]
norecursedirs = src/engines/aerender .git build dist *.egg venv .venv env .env __pycache__ .pytest_cache
testpaths = tests
python_files = test_*.py job_creation_tests.py
+20 -17
View File
@@ -1,17 +1,20 @@
requests==2.31.0
requests_toolbelt==1.0.0
psutil==5.9.6
PyYAML==6.0.1
Flask==3.0.0
rich==13.6.0
Werkzeug==3.0.0
future==0.18.3
json2html~=1.3.0
SQLAlchemy~=2.0.15
Pillow==10.1.0
zeroconf==0.119.0
Pypubsub~=4.0.3
tqdm==4.66.1
dmglib==0.9.4
plyer==2.1.0
pyobjus==1.2.3
PyQt6>=6.7.0
psutil>=5.9.8
requests>=2.32.2
Pillow>=10.3.0
PyYAML>=6.0.1
flask>=3.0.3
tqdm>=4.66.4
werkzeug>=3.0.3
Pypubsub>=4.0.3
zeroconf>=0.132.2
SQLAlchemy>=2.0.30
plyer>=2.1.0
rich>=13.7.1
setuptools>=70.0.0
py-cpuinfo>=9.0.0
requests-toolbelt>=1.0.0
PyQt6-sip>=13.6.0
humanize>=4.12.1
macholib>=1.16.3
altgraph>=0.17.4
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 921 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 476 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 979 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 450 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 694 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 816 B

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Before

Width:  |  Height:  |  Size: 995 B

After

Width:  |  Height:  |  Size: 995 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

Before

Width:  |  Height:  |  Size: 81 KiB

After

Width:  |  Height:  |  Size: 81 KiB

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

Before

Width:  |  Height:  |  Size: 66 KiB

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 806 B

Executable
+155
View File
@@ -0,0 +1,155 @@
import logging
import multiprocessing
import os
import socket
import threading
from pathlib import Path
import psutil
from src.api.api_server import API_VERSION
from src.api.api_server import start_api_server
from src.api.preview_manager import PreviewManager
from src.api.serverproxy_manager import ServerProxyManager
from src.application_context import ApplicationContext
from src.distributed_job_manager import DistributedJobManager
from src.engines.engine_manager import EngineManager
from src.render_queue import RenderQueue
from src.utilities.config import Config
from src.utilities.misc_helper import (get_gpu_info, current_system_cpu, current_system_os,
current_system_os_version, current_system_cpu_brand)
from src.utilities.zeroconf_server import ZeroconfServer
from src.version import APP_NAME, APP_VERSION
logger = logging.getLogger()
class ZordonServer:
def __init__(self):
self.ctx = ApplicationContext()
# 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)
# ---- Bootstrap Config ----
Config.setup_config_dir()
config_path = Path(Config.config_dir()) / "config.yaml"
self.ctx.config = Config()
self.ctx.config.load(config_path)
Config._default_instance = self.ctx.config
Config._sync_class()
# ---- Engine Manager ----
self.ctx.engine_manager = EngineManager()
self.ctx.engine_manager.engines_path = Path(Config.upload_folder).expanduser() / "engines"
os.makedirs(self.ctx.engine_manager.engines_path, exist_ok=True)
EngineManager._default_instance = self.ctx.engine_manager
EngineManager._sync_class()
# ---- Preview Manager ----
self.ctx.preview_manager = PreviewManager()
self.ctx.preview_manager.storage_path = Path(Config.upload_folder).expanduser() / "previews"
PreviewManager._default_instance = self.ctx.preview_manager
PreviewManager._sync_class()
# ---- Render Queue ----
self.ctx.render_queue = RenderQueue()
RenderQueue._default_instance = self.ctx.render_queue
RenderQueue._sync_class()
RenderQueue.load_state(database_directory=Path(Config.upload_folder).expanduser())
# ---- Distributed Job Manager ----
self.ctx.distributed_job_manager = DistributedJobManager()
DistributedJobManager._default_instance = self.ctx.distributed_job_manager
DistributedJobManager._sync_class()
DistributedJobManager.subscribe_to_listener()
self.api_server = None
self.server_hostname: str = socket.gethostname()
def start_server(self):
def existing_process(process_name):
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
# check for existing instance
existing_proc = existing_process(APP_NAME)
if existing_proc:
err_msg = f"Another instance of {APP_NAME} is already running (pid: {existing_proc.pid})"
logger.fatal(err_msg)
raise ProcessLookupError(err_msg)
# main start
logger.info(f"Starting {APP_NAME} Render Server ({APP_VERSION})")
logger.debug(f"Upload directory: {Path(Config.upload_folder).expanduser()}")
logger.debug(f"Thumbs directory: {PreviewManager.storage_path}")
logger.debug(f"Engines directory: {EngineManager.engines_path}")
ServerProxyManager.subscribe_to_listener()
# update hostname
self.server_hostname = socket.gethostname()
# configure and start API server
self.api_server = threading.Thread(target=start_api_server, args=(self.server_hostname,))
self.api_server.daemon = True
self.api_server.start()
# start zeroconf server
ctx = self.ctx
ctx.zeroconf_server = ZeroconfServer()
ctx.zeroconf_server._configure(f"_{APP_NAME.lower()}._tcp.local.", self.server_hostname, Config.port_number)
ctx.zeroconf_server.properties = {'system_cpu': current_system_cpu(),
'system_cpu_brand': current_system_cpu_brand(),
'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)),
'gpu_info': get_gpu_info(),
'api_version': API_VERSION}
ZeroconfServer._default_instance = ctx.zeroconf_server
ZeroconfServer._sync_class()
ctx.zeroconf_server._start()
logger.info(f"{APP_NAME} Render Server started - Hostname: {self.server_hostname}")
RenderQueue.start() # Start evaluating the render queue
def is_running(self):
return self.api_server and self.api_server.is_alive()
def stop_server(self):
logger.info(f"{APP_NAME} Render Server is preparing to stop")
try:
ZeroconfServer.stop()
RenderQueue.prepare_for_shutdown()
except Exception as e:
logger.exception(f"Exception during prepare for shutdown: {e}")
logger.info(f"{APP_NAME} Render Server has shut down")
if __name__ == '__main__':
server = ZordonServer()
try:
server.start_server()
server.api_server.join()
except KeyboardInterrupt:
pass
except Exception as e:
logger.fatal(f"Unhandled exception: {e}")
finally:
server.stop_server()
+158
View File
@@ -0,0 +1,158 @@
# -*- mode: python ; coding: utf-8 -*-
from PyInstaller.utils.hooks import collect_all
from pathlib import Path
import os
import sys
import platform
# ------------------------------------------------------------
# Project paths
# ------------------------------------------------------------
project_root = Path(SPECPATH).resolve()
src_dir = project_root / "src"
# Ensure `src.*` imports work during analysis
sys.path.insert(0, str(project_root))
# ------------------------------------------------------------
# Import version info
# ------------------------------------------------------------
from src.version import APP_NAME, APP_VERSION, APP_AUTHOR
APP_NAME = f"{APP_NAME}-server"
# ------------------------------------------------------------
# PyInstaller data / imports
# ------------------------------------------------------------
datas = [
("resources", "resources"),
("src/engines/blender/scripts", "src/engines/blender/scripts"),
]
binaries = []
hiddenimports = ["zeroconf", "src.version"]
tmp_ret = collect_all("zeroconf")
datas += tmp_ret[0]
binaries += tmp_ret[1]
hiddenimports += tmp_ret[2]
# ------------------------------------------------------------
# Analysis
# ------------------------------------------------------------
a = Analysis(
["server.py"],
pathex=[str(project_root)],
binaries=binaries,
datas=datas,
hiddenimports=hiddenimports,
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
noarchive=False,
optimize=1, # optimize=2 breaks Windows builds
)
pyz = PYZ(a.pure)
# ------------------------------------------------------------
# Platform targets
# ------------------------------------------------------------
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,
)
-184
View File
@@ -1,184 +0,0 @@
#!/usr/bin/env python3
import logging
import os
import shutil
import tempfile
import zipfile
from datetime import datetime
import requests
from tqdm import tqdm
from werkzeug.utils import secure_filename
from src.distributed_job_manager import DistributedJobManager
from src.engines.core.worker_factory import RenderWorkerFactory
from src.render_queue import RenderQueue
logger = logging.getLogger()
def handle_uploaded_project_files(request, jobs_list, upload_directory):
# Initialize default values
loaded_project_local_path = None
uploaded_project = request.files.get('file', None)
project_url = jobs_list[0].get('url', None)
local_path = jobs_list[0].get('local_path', None)
renderer = jobs_list[0].get('renderer')
downloaded_file_url = None
if uploaded_project and uploaded_project.filename:
referred_name = os.path.basename(uploaded_project.filename)
elif project_url:
referred_name, downloaded_file_url = download_project_from_url(project_url)
if not referred_name:
raise ValueError(f"Error downloading file from URL: {project_url}")
elif local_path and os.path.exists(local_path):
referred_name = os.path.basename(local_path)
else:
raise ValueError("Cannot find any valid project paths")
# Prepare the local filepath
cleaned_path_name = os.path.splitext(referred_name)[0].replace(' ', '_')
job_dir = os.path.join(upload_directory, '-'.join(
[datetime.now().strftime("%Y.%m.%d_%H.%M.%S"), renderer, cleaned_path_name]))
os.makedirs(job_dir, exist_ok=True)
project_source_dir = os.path.join(job_dir, 'source')
os.makedirs(project_source_dir, exist_ok=True)
# Move projects to their work directories
if uploaded_project and uploaded_project.filename:
loaded_project_local_path = os.path.join(project_source_dir, secure_filename(uploaded_project.filename))
uploaded_project.save(loaded_project_local_path)
logger.info(f"Transfer complete for {loaded_project_local_path.split(upload_directory)[-1]}")
elif project_url:
loaded_project_local_path = os.path.join(project_source_dir, referred_name)
shutil.move(downloaded_file_url, loaded_project_local_path)
logger.info(f"Download complete for {loaded_project_local_path.split(upload_directory)[-1]}")
elif local_path:
loaded_project_local_path = os.path.join(project_source_dir, referred_name)
shutil.copy(local_path, loaded_project_local_path)
logger.info(f"Import complete for {loaded_project_local_path.split(upload_directory)[-1]}")
return loaded_project_local_path, referred_name
def download_project_from_url(project_url):
# This nested function is to handle downloading from a URL
logger.info(f"Downloading project from url: {project_url}")
referred_name = os.path.basename(project_url)
downloaded_file_url = None
try:
response = requests.get(project_url, stream=True)
if response.status_code == 200:
# Get the total file size from the "Content-Length" header
file_size = int(response.headers.get("Content-Length", 0))
# Create a progress bar using tqdm
progress_bar = tqdm(total=file_size, unit="B", unit_scale=True)
# Open a file for writing in binary mode
downloaded_file_url = os.path.join(tempfile.gettempdir(), referred_name)
with open(downloaded_file_url, "wb") as file:
for chunk in response.iter_content(chunk_size=1024):
if chunk:
# Write the chunk to the file
file.write(chunk)
# Update the progress bar
progress_bar.update(len(chunk))
# Close the progress bar
progress_bar.close()
else:
return None, None
except Exception as e:
logger.error(f"Error downloading file: {e}")
return None, None
return referred_name, downloaded_file_url
def process_zipped_project(zip_path):
# Given a zip path, extract its content, and return the main project file path
work_path = os.path.dirname(zip_path)
try:
with zipfile.ZipFile(zip_path, 'r') as myzip:
myzip.extractall(work_path)
project_files = [x for x in os.listdir(work_path) if os.path.isfile(os.path.join(work_path, x))]
project_files = [x for x in project_files if '.zip' not in x]
logger.debug(f"Zip files: {project_files}")
# supported_exts = RenderWorkerFactory.class_for_name(renderer).engine.supported_extensions
# if supported_exts:
# project_files = [file for file in project_files if any(file.endswith(ext) for ext in supported_exts)]
# If there's more than 1 project file or none, raise an error
if len(project_files) != 1:
raise ValueError(f'Cannot find a valid project file in {os.path.basename(zip_path)}')
extracted_project_path = os.path.join(work_path, project_files[0])
logger.info(f"Extracted zip file to {extracted_project_path}")
except (zipfile.BadZipFile, zipfile.LargeZipFile) as e:
logger.error(f"Error processing zip file: {e}")
raise ValueError(f"Error processing zip file: {e}")
return extracted_project_path
def create_render_jobs(jobs_list, loaded_project_local_path, job_dir, enable_split_jobs=False):
results = []
for job_data in jobs_list:
try:
# prepare output paths
output_dir = os.path.join(job_dir, job_data.get('name') if len(jobs_list) > 1 else 'output')
os.makedirs(output_dir, exist_ok=True)
# get new output path in output_dir
output_path = job_data.get('output_path')
if not output_path:
loaded_project_filename = os.path.basename(loaded_project_local_path)
output_filename = os.path.splitext(loaded_project_filename)[0]
else:
output_filename = os.path.basename(output_path)
output_path = os.path.join(os.path.dirname(os.path.dirname(loaded_project_local_path)), 'output',
output_filename)
logger.debug(f"New job output path: {output_path}")
# create & configure jobs
worker = RenderWorkerFactory.create_worker(renderer=job_data['renderer'],
input_path=loaded_project_local_path,
output_path=output_path,
engine_version=job_data.get('engine_version'),
args=job_data.get('args', {}))
worker.status = job_data.get("initial_status", worker.status)
worker.parent = job_data.get("parent", worker.parent)
worker.name = job_data.get("name", worker.name)
worker.priority = int(job_data.get('priority', worker.priority))
worker.start_frame = int(job_data.get("start_frame", worker.start_frame))
worker.end_frame = int(job_data.get("end_frame", worker.end_frame))
# determine if we can / should split the job
if enable_split_jobs and (worker.total_frames > 1) and not worker.parent:
DistributedJobManager.split_into_subjobs(worker, job_data, loaded_project_local_path)
else:
logger.debug("Not splitting into subjobs")
RenderQueue.add_to_render_queue(worker, force_start=job_data.get('force_start', False))
if not worker.parent:
from src.api.api_server import make_job_ready
make_job_ready(worker.id)
results.append(worker.json())
except FileNotFoundError as e:
err_msg = f"Cannot create job: {e}"
logger.error(err_msg)
results.append({'error': err_msg})
except Exception as e:
err_msg = f"Exception creating render job: {e}"
logger.exception(err_msg)
results.append({'error': err_msg})
return results
+490 -398
View File
File diff suppressed because it is too large Load Diff
+222
View File
@@ -0,0 +1,222 @@
#!/usr/bin/env python3
import logging
import os
import shutil
import tempfile
import zipfile
from datetime import datetime
from pathlib import Path
import requests
from tqdm import tqdm
from werkzeug.utils import secure_filename
from src.distributed_job_manager import DistributedJobManager
logger = logging.getLogger()
class JobImportHandler:
"""Handles job import operations for rendering projects.
This class provides functionality to validate, download, and process
job data and project files for the rendering queue system.
"""
@classmethod
def create_jobs_from_processed_data(cls, processed_job_data: dict) -> list[dict]:
""" Takes processed job data and creates new jobs
Args: processed_job_data: Dictionary containing job information"""
loaded_project_local_path = processed_job_data['__loaded_project_local_path']
# prepare child job data
job_data_to_create = []
if processed_job_data.get("child_jobs"):
for child_job_diffs in processed_job_data["child_jobs"]:
processed_child_job_data = processed_job_data.copy()
processed_child_job_data.pop("child_jobs")
processed_child_job_data.update(child_job_diffs)
processed_child_job_data['__use_output_subdir'] = True
job_data_to_create.append(processed_child_job_data)
else:
job_data_to_create.append(processed_job_data)
# create the jobs
created_jobs = []
for job_data in job_data_to_create:
new_job = DistributedJobManager.create_render_job(job_data, loaded_project_local_path)
created_jobs.append(new_job)
# Save notes to .txt
if processed_job_data.get("notes"):
parent_dir = Path(loaded_project_local_path).parent.parent
notes_name = processed_job_data['name'] + "-notes.txt"
with (Path(parent_dir) / notes_name).open("w") as f:
f.write(processed_job_data["notes"])
return [x.json() for x in created_jobs]
@classmethod
def validate_job_data(cls, new_job_data: dict, upload_directory: Path, uploaded_file=None) -> dict:
"""Validates and prepares job data for import.
This method validates the job data dictionary, handles project file
acquisition (upload, download, or local copy), and prepares the job
directory structure.
Args:
new_job_data: Dictionary containing job information including
'name', 'engine_name', and optionally 'url' or 'local_path'.
upload_directory: Base directory for storing uploaded jobs.
uploaded_file: Optional uploaded file object from the request.
Returns:
The validated job data dictionary with additional metadata.
Raises:
KeyError: If required fields 'name' or 'engine_name' are missing.
FileNotFoundError: If no valid project file can be found.
"""
loaded_project_local_path = None
# check for required keys
job_name = new_job_data.get('name')
engine_name = new_job_data.get('engine_name')
if not job_name:
raise KeyError("Missing job name")
if not engine_name:
raise KeyError("Missing engine name")
project_url = new_job_data.get('url', None)
local_path = new_job_data.get('local_path', None)
downloaded_file_url = None
if uploaded_file and uploaded_file.filename:
referred_name = os.path.basename(uploaded_file.filename)
elif project_url:
referred_name, downloaded_file_url = cls.download_project_from_url(project_url)
if not referred_name:
raise FileNotFoundError(f"Error downloading file from URL: {project_url}")
elif local_path and os.path.exists(local_path):
referred_name = os.path.basename(local_path)
else:
raise FileNotFoundError("Cannot find any valid project paths")
# Prepare the local filepath
cleaned_path_name = job_name.replace(' ', '-')
folder_name = f"{cleaned_path_name}-{engine_name}-{datetime.now().strftime('%Y.%m.%d_%H.%M.%S')}"
job_dir = Path(upload_directory) / folder_name
os.makedirs(job_dir, exist_ok=True)
project_source_dir = Path(job_dir) / 'source'
os.makedirs(project_source_dir, exist_ok=True)
# Move projects to their work directories
if uploaded_file and uploaded_file.filename:
# Handle file uploading
filename = secure_filename(uploaded_file.filename)
loaded_project_local_path = Path(project_source_dir) / filename
uploaded_file.save(str(loaded_project_local_path))
logger.info(f"Transfer complete for {loaded_project_local_path.relative_to(upload_directory)}")
elif project_url:
# Handle downloading project from a URL
loaded_project_local_path = Path(project_source_dir) / referred_name
shutil.move(str(downloaded_file_url), str(loaded_project_local_path))
logger.info(f"Download complete for {loaded_project_local_path.relative_to(upload_directory)}")
elif local_path:
# Handle local files
loaded_project_local_path = Path(project_source_dir) / referred_name
shutil.copy(str(local_path), str(loaded_project_local_path))
logger.info(f"Import complete for {loaded_project_local_path.relative_to(upload_directory)}")
if loaded_project_local_path.suffix == ".zip":
loaded_project_local_path = cls.process_zipped_project(loaded_project_local_path)
new_job_data["__loaded_project_local_path"] = loaded_project_local_path
return new_job_data
@staticmethod
def download_project_from_url(project_url: str):
"""Downloads a project file from the given URL.
Downloads the file from the specified URL to a temporary directory
with progress tracking. Returns the filename and temporary path.
Args:
project_url: The URL to download the project file from.
Returns:
A tuple of (filename, temp_file_path) if successful,
(None, None) if download fails.
"""
# This nested function is to handle downloading from a URL
logger.info(f"Downloading project from url: {project_url}")
referred_name = os.path.basename(project_url)
try:
response = requests.get(project_url, stream=True, timeout=300)
if response.status_code == 200:
# Get the total file size from the "Content-Length" header
file_size = int(response.headers.get("Content-Length", 0))
# Create a progress bar using tqdm
progress_bar = tqdm(total=file_size, unit="B", unit_scale=True)
# Open a file for writing in binary mode
downloaded_file_url = os.path.join(tempfile.gettempdir(), referred_name)
with open(downloaded_file_url, "wb") as file:
for chunk in response.iter_content(chunk_size=1024):
if chunk:
# Write the chunk to the file
file.write(chunk)
# Update the progress bar
progress_bar.update(len(chunk))
# Close the progress bar
progress_bar.close()
return referred_name, downloaded_file_url
except Exception as e:
logger.error(f"Error downloading file: {e}")
return None, None
@staticmethod
def process_zipped_project(zip_path: Path) -> Path:
"""
Processes a zipped project.
This method takes a path to a zip file, extracts its contents, and returns the path to the extracted project
file. If the zip file contains more than one project file or none, an error is raised.
Args:
zip_path (Path): The path to the zip file.
Raises:
ValueError: If there's more than 1 project file or none in the zip file.
Returns:
Path: The path to the main project file.
"""
work_path = zip_path.parent
try:
with zipfile.ZipFile(zip_path, 'r') as myzip:
myzip.extractall(str(work_path))
project_files = [p for p in work_path.iterdir() if p.is_file() and p.suffix.lower() != ".zip"]
logger.debug(f"Zip files: {project_files}")
# supported_exts = RenderWorkerFactory.class_for_name(engine).engine.supported_extensions
# if supported_exts:
# project_files = [file for file in project_files if any(file.endswith(ext) for ext in supported_exts)]
# If there's more than 1 project file or none, raise an error
if len(project_files) != 1:
raise ValueError(f'Cannot find a valid project file in {zip_path.name}')
extracted_project_path = work_path / project_files[0]
logger.info(f"Extracted zip file to {extracted_project_path}")
except (zipfile.BadZipFile, zipfile.LargeZipFile) as e:
logger.error(f"Error processing zip file: {e}")
raise ValueError(f'Error processing zip file: {e}') from e
return extracted_project_path
+137
View File
@@ -0,0 +1,137 @@
import logging
import os
import subprocess
import threading
from pathlib import Path
from typing import Dict, Optional
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:
_default_instance: Optional['PreviewManager'] = None
storage_path: Optional[str] = None
def __init__(self) -> None:
self.storage_path = None
self._running_jobs: Dict = {}
@classmethod
def _sync_class(cls) -> None:
if cls._default_instance is not None:
cls.storage_path = cls._default_instance.storage_path
def _generate_job_preview_worker(self, 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(self.storage_path, exist_ok=True)
base_path = os.path.join(self.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}")
def _update_previews_for_job(self, job, replace_existing=False, wait_until_completion=False, timeout=None):
job_thread = self._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=self._generate_job_preview_worker, args=(job, replace_existing,))
job_thread.start()
self._running_jobs[job.id] = job_thread
if wait_until_completion:
job_thread.join(timeout=timeout)
def _get_previews_for_job(self, job):
results = {}
try:
directory_path = Path(self.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
def _delete_previews_for_job(self, job):
all_previews = self.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}")
# --- Forwarders for backward compatibility ---
@classmethod
def update_previews_for_job(cls, job, replace_existing=False, wait_until_completion=False, timeout=None):
if cls._default_instance is not None:
cls._default_instance._update_previews_for_job(job, replace_existing, wait_until_completion, timeout)
@classmethod
def get_previews_for_job(cls, job):
if cls._default_instance is not None:
return cls._default_instance._get_previews_for_job(job)
return {}
@classmethod
def delete_previews_for_job(cls, job):
if cls._default_instance is not None:
cls._default_instance._delete_previews_for_job(job)
+234 -60
View File
@@ -1,13 +1,15 @@
import json
import logging
import os
import socket
import threading
import time
from pathlib import Path
import requests
from requests_toolbelt.multipart import MultipartEncoder, MultipartEncoderMonitor
from urllib.parse import urljoin
from src.utilities.misc_helper import is_localhost
from src.utilities.status_utils import RenderStatus
status_colors = {RenderStatus.ERROR: "red", RenderStatus.CANCELLED: 'orange1', RenderStatus.COMPLETED: 'green',
@@ -15,14 +17,20 @@ status_colors = {RenderStatus.ERROR: "red", RenderStatus.CANCELLED: 'orange1', R
RenderStatus.RUNNING: 'cyan', RenderStatus.WAITING_FOR_SUBJOBS: 'blue'}
categories = [RenderStatus.RUNNING, RenderStatus.WAITING_FOR_SUBJOBS, RenderStatus.ERROR, RenderStatus.NOT_STARTED,
RenderStatus.SCHEDULED, RenderStatus.COMPLETED, RenderStatus.CANCELLED, RenderStatus.UNDEFINED]
RenderStatus.SCHEDULED, RenderStatus.COMPLETED, RenderStatus.CANCELLED, RenderStatus.UNDEFINED,
RenderStatus.CONFIGURING]
logger = logging.getLogger()
OFFLINE_MAX = 2
OFFLINE_MAX = 4
JOB_UPLOAD_TIMEOUT = (10, 1800)
FILE_DOWNLOAD_TIMEOUT = (10, 1800)
class RenderServerProxy:
"""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.
"""
def __init__(self, hostname, server_port="8080"):
self.hostname = hostname
self.port = server_port
@@ -33,28 +41,51 @@ class RenderServerProxy:
self.__background_thread = None
self.__offline_flags = 0
self.update_cadence = 5
self.is_localhost = bool(is_localhost(hostname))
def connect(self):
status = self.request_data('status')
return status
# Cache some basic server info
self.system_cpu = None
self.system_cpu_count = None
self.system_os = None
self.system_os_version = None
self.system_api_version = None
# --------------------------------------------
# Basics / Connection:
# --------------------------------------------
def __repr__(self):
return f"<RenderServerProxy - {self.hostname}>"
def check_connection(self):
try:
return self.request("heartbeat").ok
except Exception:
pass
return False
def is_online(self):
if self.__update_in_background:
return self.__offline_flags < OFFLINE_MAX
else:
return self.connect() is not None
return self.check_connection()
def status(self):
if not self.is_online():
return "Offline"
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 "Available"
return f"{len(running_jobs)} running" if running_jobs else "Ready"
# --------------------------------------------
# Requests:
# --------------------------------------------
def request_data(self, payload, timeout=5):
try:
req = self.request(payload, timeout)
if req.ok and req.status_code == 200:
if req.ok:
self.__offline_flags = 0
if req.status_code == 200:
return req.json()
except json.JSONDecodeError as e:
logger.debug(f"JSON decode error: {e}")
@@ -66,36 +97,52 @@ class RenderServerProxy:
self.__offline_flags = self.__offline_flags + 1
except Exception as e:
logger.exception(f"Uncaught exception: {e}")
# If server unexpectedly drops off the network, stop background updates
if self.__offline_flags > OFFLINE_MAX:
try:
self.stop_background_update()
except KeyError:
pass
return None
def request(self, payload, timeout=5):
return requests.get(f'http://{self.hostname}:{self.port}/api/{payload}', timeout=timeout)
from src.api.api_server import API_VERSION
return requests.get(f'http://{self.hostname}:{self.port}/api/{payload}', timeout=timeout,
headers={"X-API-Version": str(API_VERSION)})
def _post(self, payload, timeout=5, **kwargs):
from src.api.api_server import API_VERSION
return requests.post(f'http://{self.hostname}:{self.port}/api/{payload}', timeout=timeout,
headers={"X-API-Version": str(API_VERSION)}, **kwargs)
# --------------------------------------------
# Background Updates:
# --------------------------------------------
def start_background_update(self):
if self.__update_in_background:
return
self.__update_in_background = True
def thread_worker():
logger.debug(f'Starting background updates for {self.hostname}')
while self.__update_in_background:
self.__update_job_cache()
time.sleep(self.update_cadence)
logger.debug(f'Stopping background updates for {self.hostname}')
self.__background_thread = threading.Thread(target=thread_worker)
self.__background_thread.daemon = True
self.__background_thread.start()
def stop_background_update(self):
self.__update_in_background = False
def __update_job_cache(self, timeout=40, ignore_token=False):
def get_job_info(self, job_id, timeout=5):
return self.request_data(f'job/{job_id}', timeout=timeout)
if self.__offline_flags: # if we're offline, don't bother with the long poll
ignore_token = True
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=5, ignore_token=False):
url = f'jobs?token={self.__jobs_cache_token}' if self.__jobs_cache_token and not ignore_token else 'jobs'
url = f'jobs/long_poll?token={self.__jobs_cache_token}' if (self.__jobs_cache_token and
not ignore_token) else 'jobs'
status_result = self.request_data(url, timeout=timeout)
if status_result is not None:
sorted_jobs = []
@@ -106,57 +153,184 @@ class RenderServerProxy:
self.__jobs_cache = sorted_jobs
self.__jobs_cache_token = status_result['token']
def get_data(self, timeout=5):
all_data = self.request_data('full_status', timeout=timeout)
return all_data
def stop_background_update(self):
self.__update_in_background = False
def cancel_job(self, job_id, confirm=False):
return self.request_data(f'job/{job_id}/cancel?confirm={confirm}')
# --------------------------------------------
# Get System Info:
# --------------------------------------------
def get_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()
def get_status(self):
return self.request_data('status')
status = self.request_data('status')
if status and not self.system_cpu:
self.system_cpu = status['system_cpu']
self.system_cpu_count = status['cpu_count']
self.system_os = status['system_os']
self.system_os_version = status['system_os_version']
self.system_api_version = status['api_version']
return status
def is_engine_available(self, engine_name):
return self.request_data(f'{engine_name}/is_available')
# --------------------------------------------
# Get Job Info:
# --------------------------------------------
def notify_parent_of_status_change(self, parent_id, subjob):
return requests.post(f'http://{self.hostname}:{self.port}/api/job/{parent_id}/notify_parent_of_status_change',
json=subjob.json())
def get_job(self, job_id, timeout=5):
return self.request_data(f'jobs/{job_id}', timeout=timeout)
def post_job_to_server(self, file_path, job_list, callback=None):
def get_job_files(self, job_id):
return self.request_data(f'jobs/{job_id}/files')
# bypass uploading file if posting to localhost
if self.hostname == socket.gethostname():
jobs_with_path = [{**item, "local_path": file_path} for item in job_list]
return requests.post(f'http://{self.hostname}:{self.port}/api/add_job', data=json.dumps(jobs_with_path),
headers={'Content-Type': 'application/json'})
# --------------------------------------------
# Job Lifecycle:
# --------------------------------------------
# Prepare the form data
encoder = MultipartEncoder({
'file': (os.path.basename(file_path), open(file_path, 'rb'), 'application/octet-stream'),
'json': (None, json.dumps(job_list), 'application/json'),
})
def create_job(self, file_path: Path, job_data, callback=None, timeout=JOB_UPLOAD_TIMEOUT):
"""
Posts a job to the server.
# Create a monitor that will track the upload progress
if callback:
monitor = MultipartEncoderMonitor(encoder, callback(encoder))
else:
monitor = MultipartEncoderMonitor(encoder)
Args:
file_path (Path): The path to the file to upload.
job_data (dict): A dict of jobs data.
callback (function, optional): A callback function to call during the upload. Defaults to None.
timeout (float | tuple, optional): Requests timeout. Defaults to a 10-second connect timeout and
30-minute read timeout for large uploads.
# Send the request
headers = {'Content-Type': monitor.content_type}
return requests.post(f'http://{self.hostname}:{self.port}/api/add_job', data=monitor, headers=headers)
Returns:
Response: The response from the server.
"""
# Check if file exists
if not file_path.exists():
raise FileNotFoundError(f"File not found: {file_path}")
def get_job_files(self, job_id, save_path):
url = f"http://{self.hostname}:{self.port}/api/job/{job_id}/download_all"
return self.download_file(url, filename=save_path)
# Bypass uploading file if posting to localhost
if self.is_localhost:
job_data['local_path'] = str(file_path)
url = urljoin(f'http://{self.hostname}:{self.port}', '/api/jobs')
headers = {'Content-Type': 'application/json'}
return requests.post(url, data=json.dumps(job_data), headers=headers, timeout=timeout)
# Prepare the form data for remote host
with open(file_path, 'rb') as file:
encoder = MultipartEncoder({
'file': (file_path.name, file, 'application/octet-stream'),
'json': (None, json.dumps(job_data), 'application/json'),
})
# Create a monitor that will track the upload progress
monitor = MultipartEncoderMonitor(encoder, callback) if callback else MultipartEncoderMonitor(encoder)
headers = {'Content-Type': monitor.content_type}
url = urljoin(f'http://{self.hostname}:{self.port}', '/api/jobs')
# Send the request with proper resource management
with requests.post(url, data=monitor, headers=headers, timeout=timeout) as response:
return response
def cancel_job(self, job_id, confirm=False):
response = self._post(f'jobs/{job_id}/cancel', params={'confirm': confirm})
if response.ok:
self.__update_job_cache(timeout=5, ignore_token=True)
return response
def delete_job(self, job_id, confirm=False):
response = self._post(f'jobs/{job_id}/delete', params={'confirm': confirm})
if response.ok:
self.__update_job_cache(timeout=5, ignore_token=True)
return response
def send_subjob_update_notification(self, parent_id, subjob, timeout=5):
"""
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.
"""
return requests.post(f'http://{self.hostname}:{self.port}/api/jobs/{parent_id}/subjob_update',
json=subjob.json(), timeout=timeout)
# --------------------------------------------
# Engines:
# --------------------------------------------
def get_engine_for_filename(self, filename:str, timeout=5):
response = self.request(f'engines/for_filename?filename={os.path.basename(filename)}', timeout)
return response.text
def get_engine_availability(self, engine_name:str, timeout=5):
return self.request_data(f'engines/{engine_name}/availability', timeout)
def get_engine_names(self, timeout=5):
return self.request_data('engines/names', timeout=timeout)
def get_engines(self, response_type='standard', timeout=5):
"""
Fetches engine information from the server.
Args:
response_type (str, optional): Returns standard or full version of engine info
timeout (int, optional): The number of seconds to wait for a response from the server. Defaults to 5.
Returns:
dict: A dictionary containing the engine information.
"""
all_data = self.request_data(f'engines?response_type={response_type}', timeout=timeout)
return all_data
def get_engine(self, engine_name:str, response_type='standard', timeout=5):
"""
Fetches specific engine information from the server.
Args:
engine_name (str): Name of the engine
response_type (str, optional): Returns standard or full version of engine info
timeout (int, optional): The number of seconds to wait for a response from the server. Defaults to 5.
Returns:
dict: A dictionary containing the engine information.
"""
return self.request_data(f'engines/{engine_name}?response_type={response_type}', timeout)
def delete_engine_download(self, engine_name:str, version:str, system_os=None, cpu=None):
"""
Sends a request to the server to delete a specific engine download.
Args:
engine_name (str): The name of the engine to delete.
version (str): The version of the engine to delete.
system_os (str, optional): The system OS. Defaults to None.
cpu (str, optional): The system CPU type. Defaults to None.
Returns:
Response: The response from the server.
"""
form_data = {'engine': engine_name, 'version': version, 'system_os': system_os, 'cpu': cpu}
return self._post('engines/delete', json=form_data)
# --------------------------------------------
# Download Files:
# --------------------------------------------
def download_all_job_files(self, job_id, save_path, timeout=FILE_DOWNLOAD_TIMEOUT):
url = f'http://{self.hostname}:{self.port}/api/jobs/{job_id}/download_all'
return self.__download_file_from_url(url, output_filepath=save_path, timeout=timeout)
def download_job_file(self, job_id, job_filename, save_path, timeout=FILE_DOWNLOAD_TIMEOUT):
url = f'http://{self.hostname}:{self.port}/api/jobs/{job_id}/download?filename={job_filename}'
return self.__download_file_from_url(url, output_filepath=save_path, timeout=timeout)
@staticmethod
def download_file(url, filename):
with requests.get(url, stream=True) as r:
def __download_file_from_url(url, output_filepath, timeout=FILE_DOWNLOAD_TIMEOUT):
with requests.get(url, stream=True, timeout=timeout) as r:
r.raise_for_status()
with open(filename, 'wb') as f:
with open(output_filepath, 'wb') as f:
for chunk in r.iter_content(chunk_size=8192):
f.write(chunk)
return filename
return output_filepath
+35
View File
@@ -0,0 +1,35 @@
from pubsub import pub
from zeroconf import ServiceStateChange
from src.api.server_proxy import RenderServerProxy
class ServerProxyManager:
server_proxys = {}
@classmethod
def subscribe_to_listener(cls):
"""
Subscribes the private class method '__local_job_status_changed' to the 'status_change' pubsub message.
This should be called once, typically during the initialization phase.
"""
pub.subscribe(cls.__zeroconf_state_change, 'zeroconf_state_change')
@classmethod
def __zeroconf_state_change(cls, hostname, state_change):
if state_change == ServiceStateChange.Added or state_change == ServiceStateChange.Updated:
cls.get_proxy_for_hostname(hostname)
else:
cls.get_proxy_for_hostname(hostname).stop_background_update()
cls.server_proxys.pop(hostname)
@classmethod
def get_proxy_for_hostname(cls, hostname):
found_proxy = cls.server_proxys.get(hostname)
if hostname and not found_proxy:
new_proxy = RenderServerProxy(hostname)
new_proxy.start_background_update()
cls.server_proxys[hostname] = new_proxy
found_proxy = new_proxy
return found_proxy
+23
View File
@@ -0,0 +1,23 @@
from __future__ import annotations
from typing import TYPE_CHECKING, Optional
if TYPE_CHECKING:
from src.api.preview_manager import PreviewManager
from src.distributed_job_manager import DistributedJobManager
from src.engines.engine_manager import EngineManager
from src.render_queue import RenderQueue
from src.utilities.config import Config
from src.utilities.zeroconf_server import ZeroconfServer
class ApplicationContext:
"""Holds all service instances. Single source of truth for wiring."""
def __init__(self) -> None:
self.config: Optional[Config] = None
self.engine_manager: Optional[EngineManager] = None
self.preview_manager: Optional[PreviewManager] = None
self.zeroconf_server: Optional[ZeroconfServer] = None
self.render_queue: Optional[RenderQueue] = None
self.distributed_job_manager: Optional[DistributedJobManager] = None
-399
View File
@@ -1,399 +0,0 @@
import datetime
import logging
import os
import socket
import threading
import time
import tkinter as tk
from tkinter import ttk, messagebox, simpledialog
from PIL import Image, ImageTk
from src.client.new_job_window import NewJobWindow
# from src.client.server_details import create_server_popup
from src.api.server_proxy import RenderServerProxy
from src.utilities.misc_helper import launch_url, file_exists_in_mounts, get_time_elapsed
from src.utilities.zeroconf_server import ZeroconfServer
from src.engines.core.base_worker import RenderStatus
logger = logging.getLogger()
def sort_column(tree, col, reverse=False):
data = [(tree.set(child, col), child) for child in tree.get_children('')]
data.sort(reverse=reverse)
for index, (_, child) in enumerate(data):
tree.move(child, '', index)
def make_sortable(tree):
for col in tree["columns"]:
tree.heading(col, text=col, command=lambda c=col: sort_column(tree, c))
class DashboardWindow:
lib_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
image_path = os.path.join(lib_path, 'web', 'static', 'images')
default_image = Image.open(os.path.join(image_path, 'desktop.png'))
def __init__(self):
# Create a Treeview widget
self.root = tk.Tk()
self.root.title("Zordon Dashboard")
self.current_hostname = None
self.server_proxies = {}
self.added_hostnames = []
# Setup zeroconf
ZeroconfServer.configure("_zordon._tcp.local.", socket.gethostname(), 8080)
ZeroconfServer.start(listen_only=True)
# Setup photo preview
photo_pad = tk.Frame(self.root, background="gray")
photo_pad.pack(fill=tk.BOTH, pady=5, padx=5)
self.photo_label = tk.Label(photo_pad, height=500)
self.photo_label.pack(fill=tk.BOTH, expand=True)
self.set_image(self.default_image)
server_frame = tk.LabelFrame(self.root, text="Server")
server_frame.pack(fill=tk.BOTH, pady=5, padx=5, expand=True)
# Create server tree
left_frame = tk.Frame(server_frame)
left_frame.pack(side=tk.LEFT, expand=True, fill=tk.BOTH)
self.server_tree = ttk.Treeview(left_frame, show="headings")
self.server_tree.pack(expand=True, fill=tk.BOTH)
self.server_tree["columns"] = ("Server", "Status")
self.server_tree.bind("<<TreeviewSelect>>", self.server_picked)
self.server_tree.column("Server", width=200)
self.server_tree.column("Status", width=80)
left_button_frame = tk.Frame(left_frame)
left_button_frame.pack(side=tk.BOTTOM, fill=tk.X, padx=5, pady=5, expand=False)
# Create buttons
self.remove_server_button = tk.Button(left_button_frame, text="-", command=self.remove_server_button)
self.remove_server_button.pack(side=tk.RIGHT)
self.remove_server_button.config(state='disabled')
add_server_button = tk.Button(left_button_frame, text="+", command=self.add_server_button)
add_server_button.pack(side=tk.RIGHT)
# Create separator
separator = ttk.Separator(server_frame, orient=tk.VERTICAL)
separator.pack(side=tk.LEFT, padx=5, pady=5, fill=tk.Y)
# Setup the Tree
self.job_tree = ttk.Treeview(server_frame, show="headings")
self.job_tree.tag_configure(RenderStatus.RUNNING.value, background='lawn green', font=('', 0, 'bold'))
self.job_tree.bind("<<TreeviewSelect>>", self.job_picked)
self.job_tree["columns"] = ("id", "Name", "Renderer", "Priority", "Status", "Time Elapsed", "Frames",
"Date Added", "Parent", "")
# Format the columns
self.job_tree.column("id", width=0, stretch=False)
self.job_tree.column("Name", width=300)
self.job_tree.column("Renderer", width=100, stretch=False)
self.job_tree.column("Priority", width=50, stretch=False)
self.job_tree.column("Status", width=100, stretch=False)
self.job_tree.column("Time Elapsed", width=100, stretch=False)
self.job_tree.column("Frames", width=50, stretch=False)
self.job_tree.column("Date Added", width=150, stretch=True)
self.job_tree.column("Parent", width=250, stretch=True)
# Create the column headings
for name in self.job_tree['columns']:
self.job_tree.heading(name, text=name)
# Pack the Treeview widget
self.job_tree.pack(fill=tk.BOTH, expand=True)
button_frame = tk.Frame(server_frame)
button_frame.pack(pady=5, fill=tk.X, expand=False)
# Create buttons
self.logs_button = tk.Button(button_frame, text="Logs", command=self.open_logs)
self.show_files_button = tk.Button(button_frame, text="Show Files", command=self.show_files)
self.stop_button = tk.Button(button_frame, text="Stop", command=self.stop_job)
self.delete_button = tk.Button(button_frame, text="Delete", command=self.delete_job)
add_job_button = tk.Button(button_frame, text="Add Job", command=self.show_new_job_window)
# Pack the buttons in the frame
self.stop_button.pack(side=tk.LEFT)
self.stop_button.config(state='disabled')
self.delete_button.pack(side=tk.LEFT)
self.delete_button.config(state='disabled')
self.show_files_button.pack(side=tk.LEFT)
self.show_files_button.config(state='disabled')
self.logs_button.pack(side=tk.LEFT)
self.logs_button.config(state='disabled')
add_job_button.pack(side=tk.RIGHT)
# Start the Tkinter event loop
self.root.geometry("500x600+300+300")
self.root.maxsize(width=2000, height=1200)
self.root.minsize(width=900, height=800)
make_sortable(self.job_tree)
make_sortable(self.server_tree)
# update servers
self.update_servers()
try:
selected_server = self.server_tree.get_children()[0]
self.server_tree.selection_set(selected_server)
self.server_picked()
except IndexError:
pass
# update jobs
self.update_jobs()
try:
selected_job = self.job_tree.get_children()[0]
self.job_tree.selection_set(selected_job)
self.job_picked()
except IndexError:
pass
# start background update
x = threading.Thread(target=self.__background_update)
x.daemon = True
x.start()
@property
def current_server_proxy(self):
return self.server_proxies.get(self.current_hostname, None)
def remove_server_button(self):
new_hostname = self.server_tree.selection()[0]
if new_hostname in self.added_hostnames:
self.added_hostnames.remove(new_hostname)
self.update_servers()
if self.server_tree.get_children():
self.server_tree.selection_set(self.server_tree.get_children()[0])
self.server_picked(event=None)
def add_server_button(self):
hostname = simpledialog.askstring("Server Hostname", "Enter the server hostname to add:")
if hostname:
hostname = hostname.strip()
if hostname not in self.added_hostnames:
if RenderServerProxy(hostname=hostname).connect():
self.added_hostnames.append(hostname)
self.update_servers()
else:
messagebox.showerror("Cannot Connect", f"Cannot connect to server at hostname: '{hostname}'")
def server_picked(self, event=None):
try:
new_hostname = self.server_tree.selection()[0]
self.remove_server_button.config(state="normal" if new_hostname in self.added_hostnames else "disabled")
if self.current_hostname == new_hostname:
return
self.current_hostname = new_hostname
self.update_jobs(clear_table=True)
except IndexError:
pass
def selected_job_ids(self):
selected_items = self.job_tree.selection() # Get the selected item
row_data = [self.job_tree.item(item) for item in selected_items] # Get the text of the selected item
job_ids = [row['values'][0] for row in row_data]
return job_ids
def stop_job(self):
job_ids = self.selected_job_ids()
for job_id in job_ids:
self.current_server_proxy.cancel_job(job_id, confirm=True)
self.update_jobs(clear_table=True)
def delete_job(self):
job_ids = self.selected_job_ids()
if len(job_ids) == 1:
job = next((d for d in self.current_server_proxy.get_all_jobs() if d.get('id') == job_ids[0]), None)
display_name = job['name'] or os.path.basename(job['input_path'])
message = f"Are you sure you want to delete the job:\n{display_name}?"
else:
message = f"Are you sure you want to delete these {len(job_ids)} jobs?"
result = messagebox.askyesno("Confirmation", message)
if result:
for job_id in job_ids:
self.current_server_proxy.request_data(f'job/{job_id}/delete?confirm=true')
self.update_jobs(clear_table=True)
def set_image(self, image):
thumb_image = ImageTk.PhotoImage(image)
if thumb_image:
self.photo_label.configure(image=thumb_image)
self.photo_label.image = thumb_image
def job_picked(self, event=None):
job_id = self.selected_job_ids()[0] if self.selected_job_ids() else None
if job_id:
# update thumb
def fetch_preview():
try:
before_fetch_hostname = self.current_server_proxy.hostname
response = self.current_server_proxy.request(f'job/{job_id}/thumbnail?size=big')
if response.ok:
import io
image_data = response.content
image = Image.open(io.BytesIO(image_data))
if self.current_server_proxy.hostname == before_fetch_hostname and job_id == self.selected_job_ids()[0]:
self.set_image(image)
except ConnectionError as e:
logger.error(f"Connection error fetching image: {e}")
except Exception as e:
logger.error(f"Error fetching image: {e}")
fetch_thread = threading.Thread(target=fetch_preview)
fetch_thread.daemon = True
fetch_thread.start()
else:
self.set_image(self.default_image)
# update button status
current_jobs = self.current_server_proxy.get_all_jobs() or []
job = next((d for d in current_jobs if d.get('id') == job_id), None)
stop_button_state = 'normal' if job and job['status'] == RenderStatus.RUNNING.value else 'disabled'
self.stop_button.config(state=stop_button_state)
generic_button_state = 'normal' if job else 'disabled'
self.show_files_button.config(state=generic_button_state)
self.delete_button.config(state=generic_button_state)
self.logs_button.config(state=generic_button_state)
def show_files(self):
if not self.selected_job_ids():
return
job = next((d for d in self.current_server_proxy.get_all_jobs() if d.get('id') == self.selected_job_ids()[0]), None)
output_path = os.path.dirname(job['output_path']) # check local filesystem
if not os.path.exists(output_path):
output_path = file_exists_in_mounts(output_path) # check any attached network shares
if not output_path:
return messagebox.showerror("File Not Found", "The file could not be found. Check your network mounts.")
launch_url(output_path)
def open_logs(self):
if self.selected_job_ids():
url = f'http://{self.current_server_proxy.hostname}:{self.current_server_proxy.port}/api/job/{self.selected_job_ids()[0]}/logs'
launch_url(url)
def mainloop(self):
self.root.mainloop()
def __background_update(self):
while True:
self.update_servers()
self.update_jobs()
time.sleep(1)
def update_servers(self):
def update_row(tree, id, new_values, tags=None):
for item in tree.get_children():
values = tree.item(item, "values")
if values[0] == id:
if tags:
tree.item(item, values=new_values, tags=tags)
else:
tree.item(item, values=new_values)
break
current_servers = list(set(ZeroconfServer.found_clients() + self.added_hostnames))
for hostname in current_servers:
if not self.server_proxies.get(hostname, None):
new_proxy = RenderServerProxy(hostname=hostname)
new_proxy.start_background_update()
self.server_proxies[hostname] = new_proxy
try:
for hostname, proxy in self.server_proxies.items():
if hostname not in self.server_tree.get_children():
self.server_tree.insert("", tk.END, iid=hostname, values=(hostname, proxy.status(), ))
else:
update_row(self.server_tree, hostname, new_values=(hostname, proxy.status()))
except RuntimeError:
pass
# remove any servers that don't belong
for row in self.server_tree.get_children():
if row not in current_servers:
self.server_tree.delete(row)
proxy = self.server_proxies.get(row, None)
if proxy:
proxy.stop_background_update()
self.server_proxies.pop(row)
def update_jobs(self, clear_table=False):
if not self.current_server_proxy:
return
def update_row(tree, id, new_values, tags=None):
for item in tree.get_children():
values = tree.item(item, "values")
if values[0] == id:
tree.item(item, values=new_values, tags=tags)
break
if clear_table:
self.job_tree.delete(*self.job_tree.get_children())
job_fetch = self.current_server_proxy.get_all_jobs(ignore_token=clear_table)
if job_fetch:
for job in job_fetch:
display_status = job['status'] if job['status'] != RenderStatus.RUNNING.value else \
('%.0f%%' % (job['percent_complete'] * 100)) # if running, show percent, otherwise just show status
tags = (job['status'],)
start_time = datetime.datetime.fromisoformat(job['start_time']) if job['start_time'] else None
end_time = datetime.datetime.fromisoformat(job['end_time']) if job['end_time'] else None
time_elapsed = "" if (job['status'] != RenderStatus.RUNNING.value and not end_time) else \
get_time_elapsed(start_time, end_time)
values = (job['id'],
job['name'] or os.path.basename(job['input_path']),
job['renderer'] + "-" + job['renderer_version'],
job['priority'],
display_status,
time_elapsed,
job['total_frames'],
job['date_created'],
job['parent'])
try:
if self.job_tree.exists(job['id']):
update_row(self.job_tree, job['id'], new_values=values, tags=tags)
else:
self.job_tree.insert("", tk.END, iid=job['id'], values=values, tags=tags)
except tk.TclError:
pass
# remove any jobs that don't belong
all_job_ids = [job['id'] for job in job_fetch]
for row in self.job_tree.get_children():
if row not in all_job_ids:
self.job_tree.delete(row)
def show_new_job_window(self):
new_window = tk.Toplevel(self.root)
new_window.title("New Window")
new_window.geometry("500x600+300+300")
new_window.resizable(False, height=True)
x = NewJobWindow(parent=new_window, clients=list(self.server_tree.get_children()))
x.pack()
def start_client():
logging.basicConfig(format='%(asctime)s: %(levelname)s: %(module)s: %(message)s', datefmt='%d-%b-%y %H:%M:%S',
level='INFO'.upper())
x = DashboardWindow()
x.mainloop()
if __name__ == '__main__':
start_client()
-452
View File
@@ -1,452 +0,0 @@
#!/usr/bin/env python3
import copy
import logging
import os.path
import pathlib
import socket
import threading
from tkinter import *
from tkinter import filedialog, messagebox
from tkinter.ttk import Frame, Label, Entry, Combobox, Progressbar
import psutil
from src.api.server_proxy import RenderServerProxy
from src.engines.blender.blender_worker import Blender
from src.engines.ffmpeg.ffmpeg_worker import FFMPEG
logger = logging.getLogger()
label_width = 9
header_padding = 6
# CheckListBox source - https://stackoverflow.com/questions/50398649/python-tkinter-tk-support-checklist-box
class ChecklistBox(Frame):
def __init__(self, parent, choices, **kwargs):
super().__init__(parent, **kwargs)
self.vars = []
for choice in choices:
var = StringVar(value="")
self.vars.append(var)
cb = Checkbutton(self, text=choice, onvalue=choice, offvalue="", anchor="w", width=20,
relief="flat", highlightthickness=0, variable=var)
cb.pack(side="top", fill="x", anchor="w")
def getCheckedItems(self):
values = []
for var in self.vars:
value = var.get()
if value:
values.append(value)
return values
def resetCheckedItems(self):
values = []
for var in self.vars:
var.set(value='')
return values
class NewJobWindow(Frame):
def __init__(self, parent=None, clients=None):
super().__init__(parent)
self.root = parent
self.clients = clients or []
self.server_proxy = RenderServerProxy(hostname=clients[0] if clients else None)
self.chosen_file = None
self.project_info = {}
self.presets = {}
self.renderer_info = {}
self.priority = IntVar(value=2)
self.master.title("New Job")
self.pack(fill=BOTH, expand=True)
# project frame
job_frame = LabelFrame(self, text="Job Settings")
job_frame.pack(fill=X, padx=5, pady=5)
# project frame
project_frame = Frame(job_frame)
project_frame.pack(fill=X)
project_label = Label(project_frame, text="Project", width=label_width)
project_label.pack(side=LEFT, padx=5, pady=5)
self.project_button = Button(project_frame, text="no file selected", width=6, command=self.choose_file_button)
self.project_button.pack(fill=X, padx=5, expand=True)
# client frame
client_frame = Frame(job_frame)
client_frame.pack(fill=X)
Label(client_frame, text="Client", width=label_width).pack(side=LEFT, padx=5, pady=5)
self.client_combo = Combobox(client_frame, state="readonly")
self.client_combo.pack(fill=X, padx=5, expand=True)
self.client_combo.bind('<<ComboboxSelected>>', self.client_picked)
self.client_combo['values'] = self.clients
if self.clients:
self.client_combo.current(0)
# renderer frame
renderer_frame = Frame(job_frame)
renderer_frame.pack(fill=X)
Label(renderer_frame, text="Renderer", width=label_width).pack(side=LEFT, padx=5, pady=5)
self.renderer_combo = Combobox(renderer_frame, state="readonly")
self.renderer_combo.pack(fill=X, padx=5, expand=True)
self.renderer_combo.bind('<<ComboboxSelected>>', self.refresh_renderer_settings)
# priority frame
priority_frame = Frame(job_frame)
priority_frame.pack(fill=X)
Label(priority_frame, text="Priority", width=label_width).pack(side=LEFT, padx=5, pady=5)
Radiobutton(priority_frame, text="1", value=1, variable=self.priority).pack(anchor=W, side=LEFT, padx=5)
Radiobutton(priority_frame, text="2", value=2, variable=self.priority).pack(anchor=W, side=LEFT, padx=5)
Radiobutton(priority_frame, text="3", value=3, variable=self.priority).pack(anchor=W, side=LEFT, padx=5)
# presets
presets_frame = Frame(job_frame)
presets_frame.pack(fill=X)
Label(presets_frame, text="Presets", width=label_width).pack(side=LEFT, padx=5, pady=5)
self.presets_combo = Combobox(presets_frame, state="readonly")
self.presets_combo.pack(side=LEFT, padx=5, pady=5, expand=True, fill=X)
self.presets_combo.bind('<<ComboboxSelected>>', self.chose_preset)
# output frame
output_frame = Frame(job_frame)
output_frame.pack(fill=X)
Label(output_frame, text="Output", width=label_width).pack(side=LEFT, padx=5, pady=5)
self.output_entry = Entry(output_frame)
self.output_entry.pack(side=LEFT, padx=5, expand=True, fill=X)
self.output_format = Combobox(output_frame, state="readonly", values=['JPG', 'MOV', 'PNG'], width=9)
self.output_format.pack(side=LEFT, padx=5, pady=5)
self.output_format['state'] = DISABLED
# frame_range frame
frame_range_frame = Frame(job_frame)
frame_range_frame.pack(fill=X)
Label(frame_range_frame, text="Frames", width=label_width).pack(side=LEFT, padx=5, pady=5, expand=False)
self.start_frame_spinbox = Spinbox(frame_range_frame, from_=0, to=50000, width=5)
self.start_frame_spinbox.pack(side=LEFT, expand=False, padx=5, pady=5)
Label(frame_range_frame, text="to").pack(side=LEFT, pady=5, expand=False)
self.end_frame_spinbox = Spinbox(frame_range_frame, from_=0, to=50000, width=5)
self.end_frame_spinbox.pack(side=LEFT, expand=False, padx=5, pady=5)
# Blender
self.blender_frame = None
self.blender_cameras_frame = None
self.blender_engine = StringVar(value='CYCLES')
self.blender_pack_textures = BooleanVar(value=False)
self.blender_multiple_cameras = BooleanVar(value=False)
self.blender_cameras_list = None
# Custom Args / Submit Button
self.custom_args_frame = None
self.custom_args_entry = None
self.submit_frame = None
self.progress_frame = None
self.progress_label = None
self.progress_bar = None
self.upload_status = None
self.fetch_server_data()
def client_picked(self, event=None):
self.server_proxy.hostname = self.client_combo.get()
self.fetch_server_data()
def fetch_server_data(self):
self.renderer_info = self.server_proxy.request_data('renderer_info', timeout=3) or {}
self.presets = self.server_proxy.request_data('presets', timeout=3) or {}
# update available renders
self.renderer_combo['values'] = list(self.renderer_info.keys())
if self.renderer_info.keys():
self.renderer_combo.current(0)
self.refresh_renderer_settings()
def choose_file_button(self):
self.chosen_file = filedialog.askopenfilename()
button_text = os.path.basename(self.chosen_file) if self.chosen_file else "no file selected"
self.project_button.configure(text=button_text)
# Update the output label
self.output_entry.delete(0, END)
if self.chosen_file:
# Generate a default output name
output_name = os.path.splitext(os.path.basename(self.chosen_file))[-1].strip('.')
self.output_entry.insert(0, os.path.basename(output_name))
# Try to determine file type
extension = os.path.splitext(self.chosen_file)[-1].strip('.') # not the best way to do this
for renderer, renderer_info in self.renderer_info.items():
supported = [x.lower().strip('.') for x in renderer_info.get('supported_extensions', [])]
if extension.lower().strip('.') in supported:
if renderer in self.renderer_combo['values']:
self.renderer_combo.set(renderer)
self.refresh_renderer_settings()
def chose_preset(self, event=None):
preset_name = self.presets_combo.get()
renderer = self.renderer_combo.get()
presets_to_show = {key: value for key, value in self.presets.items() if value.get("renderer") == renderer}
matching_dict = next((value for value in presets_to_show.values() if value.get("name") == preset_name), None)
if matching_dict:
self.custom_args_entry.delete(0, END)
self.custom_args_entry.insert(0, matching_dict['args'])
def refresh_renderer_settings(self, event=None):
renderer = self.renderer_combo.get()
# clear old settings
if self.blender_frame:
self.blender_frame.pack_forget()
if not self.chosen_file:
return
if renderer == 'blender':
self.project_info = Blender().get_scene_info(self.chosen_file)
self.draw_blender_settings()
elif renderer == 'ffmpeg':
f = FFMPEG.get_frame_count(self.chosen_file)
self.project_info['frame_end'] = f
# set frame start / end numbers fetched from fils
if self.project_info.get('frame_start'):
self.start_frame_spinbox.delete(0, 'end')
self.start_frame_spinbox.insert(0, self.project_info['frame_start'])
if self.project_info.get('frame_end'):
self.end_frame_spinbox.delete(0, 'end')
self.end_frame_spinbox.insert(0, self.project_info['frame_end'])
# redraw lower ui
self.draw_custom_args()
self.draw_submit_button()
# check supported export formats
if self.renderer_info.get(renderer, {}).get('supported_export_formats', None):
formats = self.renderer_info[renderer]['supported_export_formats']
if formats and isinstance(formats[0], dict):
formats = [x.get('name', str(x)) for x in formats]
formats.sort()
self.output_format['values'] = formats
self.output_format['state'] = NORMAL
self.output_format.current(0)
else:
self.output_format['values'] = []
self.output_format['state'] = DISABLED
# update presets
presets_to_show = {key: value for key, value in self.presets.items() if value.get("renderer") == renderer}
self.presets_combo['values'] = [value['name'] for value in presets_to_show.values()]
def draw_custom_args(self):
if hasattr(self, 'custom_args_frame') and self.custom_args_frame:
self.custom_args_frame.forget()
self.custom_args_frame = LabelFrame(self, text="Advanced")
self.custom_args_frame.pack(side=TOP, fill=X, expand=False, padx=5, pady=5)
Label(self.custom_args_frame, text="Custom Args", width=label_width).pack(side=LEFT, padx=5, pady=5)
self.custom_args_entry = Entry(self.custom_args_frame)
self.custom_args_entry.pack(side=TOP, padx=5, expand=True, fill=X)
def draw_submit_button(self):
if hasattr(self, 'submit_frame') and self.submit_frame:
self.submit_frame.forget()
self.submit_frame = Frame(self)
self.submit_frame.pack(fill=BOTH, expand=True)
# Label(self.submit_frame, text="").pack(fill=BOTH, expand=True)
submit_button = Button(self.submit_frame, text="Submit", command=self.submit_job)
submit_button.pack(fill=Y, anchor="s", pady=header_padding)
def draw_progress_frame(self):
if hasattr(self, 'progress_frame') and self.progress_frame:
self.progress_frame.forget()
self.progress_frame = LabelFrame(self, text="Job Submission")
self.progress_frame.pack(side=TOP, fill=X, expand=False, padx=5, pady=5)
self.progress_bar = Progressbar(self.progress_frame, length=300, mode="determinate")
self.progress_bar.pack()
self.progress_label = Label(self.progress_frame, text="Starting Up")
self.progress_label.pack(pady=5, padx=5)
def draw_blender_settings(self):
# blender settings
self.blender_frame = LabelFrame(self, text="Blender Settings")
self.blender_frame.pack(fill=X, padx=5)
blender_engine_frame = Frame(self.blender_frame)
blender_engine_frame.pack(fill=X)
Label(blender_engine_frame, text="Engine", width=label_width).pack(side=LEFT, padx=5, pady=5)
Radiobutton(blender_engine_frame, text="Cycles", value="CYCLES", variable=self.blender_engine).pack(
anchor=W, side=LEFT, padx=5)
Radiobutton(blender_engine_frame, text="Eevee", value="BLENDER_EEVEE", variable=self.blender_engine).pack(
anchor=W, side=LEFT, padx=5)
# options
pack_frame = Frame(self.blender_frame)
pack_frame.pack(fill=X)
Label(pack_frame, text="Options", width=label_width).pack(side=LEFT, padx=5, pady=5)
Checkbutton(pack_frame, text="Pack Textures", variable=self.blender_pack_textures, onvalue=True, offvalue=False
).pack(anchor=W, side=LEFT, padx=5)
# multi cams
def draw_scene_cams(event=None):
if self.project_info:
show_cams_checkbutton['state'] = NORMAL
if self.blender_multiple_cameras.get():
self.blender_cameras_frame = Frame(self.blender_frame)
self.blender_cameras_frame.pack(fill=X)
Label(self.blender_cameras_frame, text="Cameras", width=label_width).pack(side=LEFT, padx=5, pady=5)
choices = [f"{x['name']} - {int(float(x['lens']))}mm" for x in self.project_info['cameras']]
choices.sort()
self.blender_cameras_list = ChecklistBox(self.blender_cameras_frame, choices, relief="sunken")
self.blender_cameras_list.pack(padx=5, fill=X)
elif self.blender_cameras_frame:
self.blender_cameras_frame.pack_forget()
else:
show_cams_checkbutton['state'] = DISABLED
if self.blender_cameras_frame:
self.blender_cameras_frame.pack_forget()
# multiple cameras checkbox
camera_count = len(self.project_info.get('cameras', [])) if self.project_info else 0
show_cams_checkbutton = Checkbutton(pack_frame, text=f'Multiple Cameras ({camera_count})', offvalue=False,
onvalue=True,
variable=self.blender_multiple_cameras, command=draw_scene_cams)
show_cams_checkbutton.pack(side=LEFT, padx=5)
show_cams_checkbutton['state'] = NORMAL if camera_count > 1 else DISABLED
def submit_job(self):
def submit_job_worker():
self.draw_progress_frame()
self.progress_bar['value'] = 0
self.progress_bar.configure(mode='determinate')
self.progress_bar.start()
self.progress_label.configure(text="Preparing files...")
# start the progress UI
client = self.client_combo.get()
renderer = self.renderer_combo.get()
job_json = {'owner': psutil.Process().username() + '@' + socket.gethostname(),
'renderer': renderer,
'client': client,
'output_path': os.path.join(os.path.dirname(self.chosen_file), self.output_entry.get()),
'args': {'raw': self.custom_args_entry.get()},
'start_frame': self.start_frame_spinbox.get(),
'end_frame': self.end_frame_spinbox.get(),
'name': None}
job_list = []
input_path = self.chosen_file
temp_files = []
if renderer == 'blender':
if self.blender_pack_textures.get():
self.progress_label.configure(text="Packing Blender file...")
new_path = Blender().pack_project_file(project_path=input_path, timeout=300)
if new_path:
logger.info(f"New Path is now {new_path}")
input_path = new_path
temp_files.append(new_path)
else:
err_msg = f'Failed to pack Blender file: {input_path}'
messagebox.showinfo("Error", err_msg)
return
# add all Blender args
job_json['args']['engine'] = self.blender_engine.get()
job_json['args']['export_format'] = self.output_format.get()
# multiple camera rendering
if self.blender_cameras_list and self.blender_multiple_cameras.get():
selected_cameras = self.blender_cameras_list.getCheckedItems()
for cam in selected_cameras:
job_copy = copy.deepcopy(job_json)
job_copy['args']['camera'] = cam.rsplit('-', 1)[0].strip()
job_copy['name'] = pathlib.Path(input_path).stem.replace(' ', '_') + "-" + cam.replace(' ', '')
job_list.append(job_copy)
# Submit to server
job_list = job_list or [job_json]
self.progress_label.configure(text="Posting to server...")
self.progress_bar.stop()
self.progress_bar.configure(mode='determinate')
self.progress_bar.start()
def create_callback(encoder):
encoder_len = encoder.len
def callback(monitor):
percent = f"{monitor.bytes_read / encoder_len * 100:.0f}"
self.progress_label.configure(text=f"Transferring to {client} - {percent}%")
self.progress_bar['value'] = int(percent)
return callback
result = self.server_proxy.post_job_to_server(file_path=input_path, job_list=job_list,
callback=create_callback)
self.progress_bar.stop()
# clean up
for temp in temp_files:
os.remove(temp)
def finish_on_main():
if result.ok:
message = "Job successfully submitted to server."
self.progress_label.configure(text=message)
messagebox.showinfo("Success", message)
logger.info(message)
else:
message = result.text or "Unknown error"
self.progress_label.configure(text=message)
logger.warning(message)
messagebox.showinfo("Error", message)
self.progress_label.configure(text="")
self.progress_frame.forget()
self.root.after(0, finish_on_main)
# Start the job submit task as a bg thread
bg_thread = threading.Thread(target=submit_job_worker)
bg_thread.start()
def main():
root = Tk()
root.geometry("500x600+300+300")
root.maxsize(width=1000, height=2000)
root.minsize(width=600, height=600)
app = NewJobWindow(root)
root.mainloop()
if __name__ == '__main__':
main()
+237 -279
View File
@@ -1,15 +1,20 @@
import logging
import os
import socket
import threading
import time
import zipfile
from typing import Optional
from pathlib import Path
from plyer import notification
from pubsub import pub
from src.api.preview_manager import PreviewManager
from src.api.server_proxy import RenderServerProxy
from src.engines.engine_manager import EngineManager
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.zeroconf_server import ZeroconfServer
@@ -17,353 +22,306 @@ logger = logging.getLogger()
class DistributedJobManager:
def __init__(self):
pass
_default_instance: Optional['DistributedJobManager'] = None
@classmethod
def start(cls):
"""
Subscribes the private class method '__local_job_status_changed' to the 'status_change' pubsub message.
This should be called once, typically during the initialization phase.
"""
pub.subscribe(cls.__local_job_status_changed, 'status_change')
def _sync_class(cls) -> None:
if cls._default_instance is not None:
pass # no class-level attributes to sync
@classmethod
def __local_job_status_changed(cls, job_id, old_status, new_status):
"""
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.
def __init__(self) -> None:
self.background_worker: Optional[threading.Thread] = None
Parameters:
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 'status_change' pubsub message.
"""
def _subscribe_to_listener(self) -> None:
pub.subscribe(self._local_job_status_changed, 'status_change')
pub.subscribe(self._local_job_frame_complete, 'frame_complete')
def _local_job_frame_complete(self, job_id, frame_number, update_interval=5) -> None:
render_job = RenderQueue.job_with_id(job_id, none_ok=True)
if not render_job: # ignore jobs created but not yet added to queue
if not render_job:
return
logger.debug(f"Job {job_id} has completed frame #{frame_number}")
replace_existing_previews = (frame_number % update_interval) == 0
self._job_update_shared(render_job, replace_existing_previews)
def _job_update_shared(self, render_job, replace_existing_previews=False) -> None:
PreviewManager.update_previews_for_job(job=render_job, replace_existing=replace_existing_previews)
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}")
def _local_job_status_changed(self, job_id: str, old_status: str, new_status: str) -> None:
render_job = RenderQueue.job_with_id(job_id, none_ok=True)
if not render_job:
return
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)
self._job_update_shared(render_job, replace_existing_previews=(render_job.status == RenderStatus.COMPLETED))
# handle cancelling all the children
elif render_job.children and new_status in [RenderStatus.CANCELLED, RenderStatus.ERROR]:
for child in render_job.children:
child_id, hostname = child.split('@')
RenderServerProxy(hostname).cancel_job(child_id, confirm=True)
if render_job.children:
if new_status in (RenderStatus.CANCELLED, RenderStatus.ERROR):
for child in render_job.children:
child_id, child_hostname = child.split('@')
RenderServerProxy(child_hostname).cancel_job(child_id, confirm=True)
# UI Notifications
try:
if new_status == RenderStatus.COMPLETED:
logger.debug("show render complete notification")
logger.debug("Show render complete notification")
notification.notify(
title='Render Job Complete',
message=f'{render_job.name} completed succesfully',
timeout=10 # Display time in seconds
timeout=10
)
elif new_status == RenderStatus.ERROR:
logger.debug("show render complete notification")
logger.debug("Show render error notification")
notification.notify(
title='Render Job Failed',
message=f'{render_job.name} failed rendering',
timeout=10 # Display time in seconds
timeout=10
)
elif new_status == RenderStatus.RUNNING:
logger.debug("show render complete notification")
logger.debug("Show render started notification")
notification.notify(
title='Render Job Started',
message=f'{render_job.name} started rendering',
timeout=10 # Display time in seconds
timeout=10
)
except Exception as e:
logger.debug(f"Unable to show UI notification: {e}")
@classmethod
def handle_subjob_status_change(cls, local_job, subjob_data):
"""
Responds to a status change from a remote subjob and triggers the creation or modification of subjobs as needed.
# --------------------------------------------
# Create Job
# --------------------------------------------
Parameters:
local_job (BaseRenderWorker): The local parent job worker.
subjob_data (dict): subjob data sent from remote server.
def _create_render_job(self, new_job_attributes: dict, loaded_project_local_path: Path):
requested_output_path = new_job_attributes.get('output_path')
output_filename = Path(str(requested_output_path)).name if requested_output_path else loaded_project_local_path.stem
Returns:
None
"""
output_dir = loaded_project_local_path.parent.parent / "output"
if new_job_attributes.get('__use_output_subdir'):
output_dir = output_dir / output_filename
output_path = output_dir / output_filename
os.makedirs(output_dir, exist_ok=True)
logger.debug(f"New job output path: {output_path}")
worker = EngineManager.create_worker(engine_name=new_job_attributes['engine_name'],
input_path=loaded_project_local_path,
output_path=output_path,
engine_version=new_job_attributes.get('engine_version'),
args=new_job_attributes.get('args', {}),
parent=new_job_attributes.get('parent'),
name=new_job_attributes.get('name'))
worker.status = new_job_attributes.get("initial_status", worker.status)
worker.priority = int(new_job_attributes.get('priority', worker.priority))
worker.start_frame = int(new_job_attributes.get("start_frame", worker.start_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()
if new_job_attributes.get("enable_split_jobs", False) and (worker.total_frames > 1) and not worker.parent:
self.split_into_subjobs_async(worker, new_job_attributes, loaded_project_local_path)
else:
worker.status = RenderStatus.NOT_STARTED
RenderQueue.add_to_render_queue(worker, force_start=new_job_attributes.get('force_start', False))
PreviewManager.update_previews_for_job(worker)
return worker
# --------------------------------------------
# Handling Subjobs
# --------------------------------------------
def _handle_subjob_update_notification(self, local_job, subjob_data: dict) -> None:
subjob_status = string_to_status(subjob_data['status'])
subjob_id = subjob_data['id']
subjob_hostname = next((hostname.split('@')[1] for hostname in local_job.children if
hostname.split('@')[0] == subjob_id), None)
local_job.children[f'{subjob_id}@{subjob_hostname}'] = subjob_data
subjob_hostname = subjob_data['hostname']
subjob_key = f'{subjob_id}@{subjob_hostname}'
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}"
logger.debug(f"Subjob status changed: {logname} -> {subjob_status.value}")
logname = f"<Parent: {local_job.id} | Child: {subjob_key}>"
if old_status != subjob_status.value:
logger.debug(f"Subjob status changed: {logname} -> {subjob_status.value}")
# Download complete or partial render jobs
if subjob_status in [RenderStatus.COMPLETED, RenderStatus.CANCELLED, RenderStatus.ERROR] and \
subjob_data['file_count']:
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}")
download_success = download_missing_frames_from_subjob(local_job, subjob_id, subjob_hostname)
if subjob_data['status'] == 'completed' and download_success:
local_job.children[subjob_key]['download_status'] = 'completed'
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.exception(f"Exception 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
def wait_for_subjobs(cls, local_job):
logger.debug(f"Waiting for subjobs for job {local_job}")
local_job.status = RenderStatus.WAITING_FOR_SUBJOBS
statuses_to_download = [RenderStatus.CANCELLED, RenderStatus.ERROR, RenderStatus.COMPLETED]
def _wait_for_subjobs(self, parent_job) -> None:
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)
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}
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()):
for child_key, subjob_cached_data in subjobs_not_downloaded().items():
server_delay = 10
sleep_counter = 0
while parent_job.status == RenderStatus.WAITING_FOR_SUBJOBS:
subjob_id = child_key.split('@')[0]
subjob_hostname = child_key.split('@')[-1]
if sleep_counter % server_delay == 0:
for child_key in subjobs_not_downloaded():
subjob_id = child_key.split('@')[0]
subjob_hostname = child_key.split('@')[-1]
# Fetch info from server and handle failing case
subjob_data = RenderServerProxy(subjob_hostname).get_job_info(subjob_id)
if not subjob_data:
logger.warning(f"No response from: {subjob_hostname}")
# todo: handle timeout / missing server situations
continue
subjob_data = RenderServerProxy(subjob_hostname).get_job(subjob_id)
if not subjob_data:
logger.warning(f"No response from {subjob_hostname}")
parent_job.children[child_key]['download_status'] = f'error: No response from {subjob_hostname}'
continue
# Update parent job cache but keep the download status
download_status = local_job.children[child_key].get('download_status', None)
local_job.children[child_key] = subjob_data
local_job.children[child_key]['download_status'] = download_status
download_status = parent_job.children[child_key].get('download_status', None)
parent_job.children[child_key] = subjob_data
parent_job.children[child_key]['download_status'] = download_status
status = string_to_status(subjob_data.get('status', ''))
status_msg = f"Subjob {child_key} | {status} | " \
f"{float(subjob_data.get('percent_complete')) * 100.0}%"
logger.debug(status_msg)
status = string_to_status(subjob_data.get('status', ''))
status_msg = f"Subjob {child_key} | {status} | " \
f"{float(subjob_data.get('percent_complete')) * 100.0}%"
logger.debug(status_msg)
# Still working in another thread - keep waiting
if download_status == 'working':
continue
if download_status is None and subjob_data.get('file_count') and status in statuses_to_download:
try:
download_missing_frames_from_subjob(parent_job, subjob_id, subjob_hostname)
parent_job.children[child_key]['download_status'] = 'complete'
except Exception as e:
logger.error(f"Error downloading missing frames from subjob: {e}")
parent_job.children[child_key]['download_status'] = 'error: {}'
# 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:
download_result = cls.download_from_subjob(local_job, subjob_id, subjob_hostname)
if not download_result:
logger.error("Failed to download from subjob")
# todo: error handling here
# Any finished jobs not successfully downloaded at this point are skipped
if local_job.children[child_key].get('download_status', None) is None and \
status in statuses_to_download:
logger.warning(f"Skipping waiting on downloading from subjob: {child_key}")
local_job.children[child_key]['download_status'] = 'skipped'
if parent_job.children[child_key].get('download_status', None) is None and \
status in statuses_to_download:
logger.warning(f"Skipping waiting on downloading from subjob: {child_key}")
parent_job.children[child_key]['download_status'] = 'skipped'
if subjobs_not_downloaded():
logger.debug(f"Waiting on {len(subjobs_not_downloaded())} subjobs on "
f"{', '.join(list(subjobs_not_downloaded().keys()))}")
time.sleep(5)
time.sleep(1)
sleep_counter += 1
else:
parent_job.status = RenderStatus.RUNNING
@classmethod
def split_into_subjobs(cls, worker, job_data, project_path):
# --------------------------------------------
# Creating Subjobs
# --------------------------------------------
# Check availability
available_servers = cls.find_available_servers(worker.renderer)
logger.debug(f"Splitting into subjobs - Available servers: {available_servers}")
subjob_servers = cls.distribute_server_work(worker.start_frame, worker.end_frame, available_servers)
local_hostname = socket.gethostname()
def _split_into_subjobs_async(self, parent_worker, new_job_attributes, project_path, system_os=None) -> None:
parent_worker.status = RenderStatus.CONFIGURING
self.background_worker = threading.Thread(target=self.split_into_subjobs, args=(
parent_worker, new_job_attributes, project_path, system_os))
self.background_worker.start()
# Prep and submit these sub-jobs
logger.info(f"Job {worker.id} split plan: {subjob_servers}")
def split_into_subjobs(self, parent_worker, new_job_attributes, project_path, system_os=None, specific_servers=None) -> None:
available_servers = specific_servers if specific_servers else self.find_available_servers(
parent_worker.engine_name, system_os)
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)
logger.info(f"Job {parent_worker.id} split plan: {all_subjob_server_data}")
try:
for server_data in subjob_servers:
server_hostname = server_data['hostname']
if server_hostname != local_hostname:
post_results = cls.__create_subjob(job_data, local_hostname, project_path, server_data,
server_hostname, worker)
if post_results.ok:
server_data['submission_results'] = post_results.json()[0]
else:
logger.error(f"Failed to create subjob on {server_hostname}")
break
else:
# truncate parent render_job
worker.start_frame = max(server_data['frame_range'][0], worker.start_frame)
worker.end_frame = min(server_data['frame_range'][-1], worker.end_frame)
logger.info(f"Local job now rendering from {worker.start_frame} to {worker.end_frame}")
server_data['submission_results'] = worker.json()
for subjob_data in all_subjob_server_data:
subjob_hostname = subjob_data['hostname']
post_results = self._create_subjob(new_job_attributes, project_path, subjob_data, subjob_hostname,
parent_worker)
if not post_results.ok:
ValueError(f"Failed to create subjob on {subjob_hostname}")
# check that job posts were all successful.
if not all(d.get('submission_results') is not None for d in subjob_servers):
raise ValueError("Failed to create all subjobs") # look into recalculating job #s and use exising jobs
# start subjobs
logger.debug(f"Starting {len(subjob_servers) - 1} attempted subjobs")
for server_data in subjob_servers:
if server_data['hostname'] != local_hostname:
child_key = f"{server_data['submission_results']['id']}@{server_data['hostname']}"
worker.children[child_key] = server_data['submission_results']
worker.name = f"{worker.name}[{worker.start_frame}-{worker.end_frame}]"
submission_results = post_results.json()[0]
child_key = f"{submission_results['id']}@{subjob_hostname}"
parent_worker.children[child_key] = submission_results
logger.debug(f"Created {len(all_subjob_server_data)} subjobs successfully")
parent_worker.name = f"{parent_worker.name} (Parent)"
parent_worker.status = RenderStatus.NOT_STARTED
except Exception as e:
# cancel all the subjobs
logger.error(f"Failed to split job into subjobs: {e}")
logger.debug(f"Cancelling {len(subjob_servers) - 1} attempted subjobs")
# [RenderServerProxy(hostname).cancel_job(results['id'], confirm=True) for hostname, results in
# submission_results.items()] # todo: fix this
logger.debug(f"Cancelling {len(all_subjob_server_data) - 1} attempted subjobs")
RenderServerProxy(parent_worker.hostname).cancel_job(parent_worker.id, confirm=True)
@staticmethod
def __create_subjob(job_data, local_hostname, project_path, server_data, server_hostname, worker):
subjob = job_data.copy()
subjob['name'] = f"{worker.name}[{server_data['frame_range'][0]}-{server_data['frame_range'][-1]}]"
subjob['parent'] = f"{worker.id}@{local_hostname}"
def _create_subjob(new_job_attributes: dict, project_path, server_data, server_hostname, parent_worker):
subjob = new_job_attributes.copy()
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['start_frame'] = server_data['frame_range'][0]
subjob['end_frame'] = server_data['frame_range'][-1]
subjob['engine_version'] = parent_worker.engine_version
logger.debug(f"Posting subjob with frames {subjob['start_frame']}-"
f"{subjob['end_frame']} to {server_hostname}")
post_results = RenderServerProxy(server_hostname).post_job_to_server(
file_path=project_path, job_list=[subjob])
post_results = RenderServerProxy(server_hostname).create_job(
file_path=project_path, job_data=subjob)
return post_results
@staticmethod
def distribute_server_work(start_frame, end_frame, available_servers, method='cpu_count'):
"""
Splits the frame range among available servers proportionally based on their performance (CPU count).
:param start_frame: int, The start frame number of the animation to be rendered.
:param end_frame: int, The end frame number of the animation to be rendered.
:param available_servers: list, A list of available server dictionaries. Each server dictionary should include
'hostname' and 'cpu_count' keys (see find_available_servers)
:param method: str, Optional. Specifies the distribution method. Possible values are 'cpu_count' and 'equally'
:return: 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_performance = 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_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 method == 'equally':
breakdown = divide_frames_equally(start_frame, end_frame, available_servers)
# elif method == 'benchmark_score': # todo: implement benchmark score
# pass
else:
breakdown = divide_frames_by_cpu_count(start_frame, end_frame, available_servers)
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
# --------------------------------------------
# Server Handling
# --------------------------------------------
@staticmethod
def find_available_servers(engine_name):
"""
Scan the Zeroconf network for currently available render servers supporting a specific engine.
def find_available_servers(engine_name: str, system_os=None):
from src.api.api_server import API_VERSION
found_available_servers = []
for hostname in ZeroconfServer.found_hostnames():
host_properties = ZeroconfServer.get_hostname_properties(hostname)
if host_properties.get('api_version') == API_VERSION:
if not system_os or (system_os and system_os == host_properties.get('system_os')):
response = RenderServerProxy(hostname).get_engine_availability(engine_name)
if response and response.get('available', False):
found_available_servers.append(response)
:param engine_name: str, The engine type to search for
:return: A list of dictionaries with each dict containing hostname and cpu_count of available servers
"""
available_servers = []
for hostname in ZeroconfServer.found_clients():
response = RenderServerProxy(hostname).is_engine_available(engine_name)
if response and response.get('available', False):
available_servers.append(response)
return found_available_servers
return available_servers
# --- Forwarders for backward compatibility ---
@classmethod
def subscribe_to_listener(cls):
if cls._default_instance is not None:
cls._default_instance._subscribe_to_listener()
@classmethod
def create_render_job(cls, new_job_attributes, loaded_project_local_path):
if cls._default_instance is not None:
return cls._default_instance._create_render_job(new_job_attributes, loaded_project_local_path)
raise RuntimeError("DistributedJobManager is not initialized")
@classmethod
def handle_subjob_update_notification(cls, local_job, subjob_data):
if cls._default_instance is not None:
cls._default_instance._handle_subjob_update_notification(local_job, subjob_data)
@classmethod
def wait_for_subjobs(cls, parent_job):
if cls._default_instance is not None:
cls._default_instance._wait_for_subjobs(parent_job)
@classmethod
def split_into_subjobs_async(cls, parent_worker, new_job_attributes, project_path, system_os=None):
if cls._default_instance is not None:
cls._default_instance._split_into_subjobs_async(parent_worker, new_job_attributes, project_path, system_os)
if __name__ == '__main__':
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
ZeroconfServer.configure("_zordon._tcp.local.", 'testing', 8080)
ZeroconfServer.start(listen_only=True)
print("Starting Zeroconf...")
time.sleep(2)
available_servers = DistributedJobManager.find_available_servers('blender')
print(f"AVAILABLE SERVERS ({len(available_servers)}): {available_servers}")
# results = distribute_server_work(1, 100, available_servers)
# print(f"RESULTS: {results}")
ZeroconfServer.stop()
+1 -1
View File
@@ -8,7 +8,7 @@ class AERender(BaseRenderEngine):
def version(self):
version = None
try:
render_path = self.renderer_path()
render_path = self.engine_path()
if render_path:
ver_out = subprocess.check_output([render_path, '-version'], timeout=SUBPROCESS_TIMEOUT)
version = ver_out.decode('utf-8').split(" ")[-1].strip()
+64 -35
View File
@@ -1,22 +1,25 @@
import logging
import re
import threading
import requests
from src.engines.core.downloader_core import download_and_extract_app
from src.engines.blender.blender_engine import Blender
from src.engines.core.base_downloader import EngineDownloader
from src.utilities.misc_helper import current_system_os, current_system_cpu
# url = "https://download.blender.org/release/"
url = "https://ftp.nluug.nl/pub/graphics/blender/release/" # much faster mirror for testing
url = "https://download.blender.org/release/"
logger = logging.getLogger()
supported_formats = ['.zip', '.tar.xz', '.dmg']
class BlenderDownloader:
class BlenderDownloader(EngineDownloader):
engine = Blender
@staticmethod
def get_major_versions():
def __get_major_versions():
try:
response = requests.get(url, timeout=5)
response.raise_for_status()
@@ -30,21 +33,23 @@ class BlenderDownloader:
return major_versions
except requests.exceptions.RequestException as e:
logger.error(f"Error: {e}")
return None
return []
@staticmethod
def get_minor_versions(major_version, system_os=None, cpu=None):
def __get_minor_versions(major_version, system_os=None, cpu=None):
try:
base_url = url + 'Blender' + major_version
response = requests.get(base_url, timeout=5)
response.raise_for_status()
versions_pattern = r'<a href="(?P<file>[^"]+)">blender-(?P<version>[\d\.]+)-(?P<system_os>\w+)-(?P<cpu>\w+).*</a>'
versions_pattern = \
r'<a href="(?P<file>[^"]+)">blender-(?P<version>[\d\.]+)-(?P<system_os>\w+)-(?P<cpu>\w+).*</a>'
versions_data = [match.groupdict() for match in re.finditer(versions_pattern, response.text)]
# Filter to just the supported formats
versions_data = [item for item in versions_data if any(item["file"].endswith(ext) for ext in supported_formats)]
versions_data = [item for item in versions_data if any(item["file"].endswith(ext) for ext in
supported_formats)]
# Filter down OS and CPU
system_os = system_os or current_system_os()
@@ -63,18 +68,9 @@ class BlenderDownloader:
logger.exception(e)
return []
@classmethod
def version_is_available_to_download(cls, version, system_os=None, cpu=None):
requested_major_version = '.'.join(version.split('.')[:2])
minor_versions = cls.get_minor_versions(requested_major_version, system_os, cpu)
for minor in minor_versions:
if minor['version'] == version:
return minor
return None
@staticmethod
def find_LTS_versions():
response = requests.get('https://www.blender.org/download/lts/')
def __find_LTS_versions():
response = requests.get('https://www.blender.org/download/lts/', timeout=5)
response.raise_for_status()
lts_pattern = r'https://www.blender.org/download/lts/(\d+-\d+)/'
@@ -85,27 +81,61 @@ class BlenderDownloader:
return lts_versions
@classmethod
def find_most_recent_version(cls, system_os=None, cpu=None, lts_only=False):
try:
major_version = cls.find_LTS_versions()[0] if lts_only else cls.get_major_versions()[0]
most_recent = cls.get_minor_versions(major_version=major_version, system_os=system_os, cpu=cpu)
return most_recent[0]
except IndexError:
logger.error("Cannot find a most recent version")
def all_versions(cls, system_os=None, cpu=None):
majors = cls.__get_major_versions()
all_versions = []
threads = []
results = [[] for _ in majors]
def thread_function(major_version, index, system_os_t, cpu_t):
results[index] = cls.__get_minor_versions(major_version, system_os_t, cpu_t)
for i, m in enumerate(majors):
thread = threading.Thread(target=thread_function, args=(m, i, system_os, cpu))
threads.append(thread)
thread.start()
# Wait for all threads to complete
for thread in threads:
thread.join()
# Extend all_versions with the results from each thread
for result in results:
all_versions.extend(result)
return all_versions
@classmethod
def download_engine(cls, version, download_location, system_os=None, cpu=None, timeout=120):
def find_most_recent_version(cls, system_os=None, cpu=None, lts_only=False):
try:
major_version = cls.__find_LTS_versions()[0] if lts_only else cls.__get_major_versions()[0]
most_recent = cls.__get_minor_versions(major_version=major_version, system_os=system_os, cpu=cpu)
return most_recent[0]
except (IndexError, requests.exceptions.RequestException):
logger.error(f"Cannot get most recent version of blender")
return {}
@classmethod
def version_is_available_to_download(cls, version, system_os=None, cpu=None):
requested_major_version = '.'.join(version.split('.')[:2])
minor_versions = cls.__get_minor_versions(requested_major_version, system_os, cpu)
for minor in minor_versions:
if minor['version'] == version:
return minor
return None
@classmethod
def download_engine(cls, version, download_location, system_os=None, cpu=None, timeout=120, progress_callback=None):
system_os = system_os or current_system_os()
cpu = cpu or current_system_cpu()
try:
logger.info(f"Requesting download of blender-{version}-{system_os}-{cpu}")
major_version = '.'.join(version.split('.')[:2])
minor_versions = [x for x in cls.get_minor_versions(major_version, system_os, cpu) if x['version'] == version]
# we get the URL instead of calculating it ourselves. May change this
download_and_extract_app(remote_url=minor_versions[0]['url'], download_location=download_location,
timeout=timeout)
minor_versions = [x for x in cls.__get_minor_versions(major_version, system_os, cpu) if
x['version'] == version]
cls.download_and_extract_app(remote_url=minor_versions[0]['url'], download_location=download_location,
timeout=timeout, progress_callback=progress_callback)
except IndexError:
logger.error("Cannot find requested engine")
@@ -113,5 +143,4 @@ class BlenderDownloader:
if __name__ == '__main__':
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
print(BlenderDownloader.get_major_versions())
print(BlenderDownloader.find_most_recent_version())
+85 -33
View File
@@ -1,24 +1,46 @@
import json
import re
from pathlib import Path
from src.engines.core.base_engine import *
from src.utilities.misc_helper import system_safe_path
logger = logging.getLogger()
_creationflags = subprocess.CREATE_NO_WINDOW if platform.system() == 'Windows' else 0
class Blender(BaseRenderEngine):
install_paths = ['/Applications/Blender.app/Contents/MacOS/Blender']
supported_extensions = ['.blend']
binary_names = {'linux': 'blender', 'windows': 'blender.exe', 'macos': 'Blender'}
@staticmethod
def downloader():
from src.engines.blender.blender_downloader import BlenderDownloader
return BlenderDownloader
@staticmethod
def worker_class():
from src.engines.blender.blender_worker import BlenderRenderWorker
return BlenderRenderWorker
def ui_options(self):
options = [
{'name': 'engine', 'options': self.supported_render_engines()},
{'name': 'render_device', 'options': ['Any', 'GPU', 'CPU']},
]
return options
def supported_extensions(self):
return ['blend']
def version(self):
version = None
try:
render_path = self.renderer_path()
render_path = self.engine_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()
except Exception as e:
logger.error(f'Failed to get Blender version: {e}')
@@ -32,32 +54,43 @@ class Blender(BaseRenderEngine):
def run_python_expression(self, project_path, python_expression, timeout=None):
if os.path.exists(project_path):
try:
return subprocess.run([self.renderer_path(), '-b', project_path, '--python-expr', python_expression],
capture_output=True, timeout=timeout)
return subprocess.run([self.engine_path(), '-b', project_path, '--python-expr', python_expression],
capture_output=True, timeout=timeout, creationflags=_creationflags)
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:
raise FileNotFoundError(f'Project file not found: {project_path}')
def run_python_script(self, project_path, script_path, timeout=None):
if os.path.exists(project_path) and os.path.exists(script_path):
try:
return subprocess.run([self.renderer_path(), '-b', project_path, '--python', script_path],
capture_output=True, timeout=timeout)
except Exception as e:
logger.warning(f"Error running python script in blender: {e}")
pass
elif not os.path.exists(project_path):
def run_python_script(self, script_path, project_path=None, timeout=None):
if project_path and not os.path.exists(project_path):
raise FileNotFoundError(f'Project file not found: {project_path}')
elif not os.path.exists(script_path):
raise FileNotFoundError(f'Python script not found: {script_path}')
raise Exception("Uncaught exception")
def get_scene_info(self, project_path, timeout=10):
try:
command = [self.engine_path(), '-b', '--python', script_path]
if project_path:
command.insert(2, project_path)
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:
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):
scene_info = {}
try:
script_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'scripts', 'get_file_info.py')
results = self.run_python_script(project_path, system_safe_path(script_path), timeout=timeout)
results = self.run_python_script(project_path=project_path, script_path=Path(script_path),
timeout=timeout)
result_text = results.stdout.decode()
for line in result_text.splitlines():
if line.startswith('SCENE_DATA:'):
@@ -67,15 +100,18 @@ class Blender(BaseRenderEngine):
elif line.startswith('Error'):
logger.error(f"get_scene_info error: {line.strip()}")
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
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
try:
logger.info(f"Starting to pack Blender file: {project_path}")
script_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'scripts', 'pack_project.py')
results = self.run_python_script(project_path, system_safe_path(script_path), timeout=timeout)
results = self.run_python_script(project_path=project_path, script_path=Path(script_path),
timeout=timeout)
result_text = results.stdout.decode()
dir_name = os.path.dirname(project_path)
@@ -83,7 +119,7 @@ class Blender(BaseRenderEngine):
# report any missing textures
not_found = re.findall("(Unable to pack file, source path .*)\n", result_text)
for err in not_found:
logger.error(err)
raise ChildProcessError(err)
p = re.compile('Saved to: (.*)\n')
match = p.search(result_text)
@@ -91,12 +127,15 @@ class Blender(BaseRenderEngine):
new_path = os.path.join(dir_name, match.group(1).strip())
logger.info(f'Blender file packed successfully to {new_path}')
return new_path
return project_path
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
def get_arguments(self):
help_text = subprocess.check_output([self.renderer_path(), '-h']).decode('utf-8')
help_text = subprocess.check_output([self.engine_path(), '-h'], creationflags=_creationflags).decode('utf-8')
lines = help_text.splitlines()
options = {}
@@ -127,19 +166,32 @@ class Blender(BaseRenderEngine):
return options
def get_detected_gpus(self):
engine_output = subprocess.run([self.renderer_path(), '-E', 'help'], timeout=SUBPROCESS_TIMEOUT,
capture_output=True).stdout.decode('utf-8')
gpu_names = re.findall(r"DETECTED GPU: (.+)", engine_output)
return gpu_names
def system_info(self):
return {'render_devices': self.get_render_devices(), 'engines': self.supported_render_engines()}
def get_render_devices(self):
script_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'scripts', 'get_system_info.py')
results = self.run_python_script(script_path=script_path)
output = results.stdout.decode()
match = re.search(r"GPU DATA:(\[.*?\])", output, re.DOTALL)
if match:
gpu_data_json = match.group(1)
gpus_info = json.loads(gpu_data_json)
return gpus_info
else:
logger.error("GPU data not found in the output.")
def supported_render_engines(self):
engine_output = subprocess.run([self.renderer_path(), '-E', 'help'], timeout=SUBPROCESS_TIMEOUT,
capture_output=True).stdout.decode('utf-8').strip()
engine_output = subprocess.run([self.engine_path(), '-b', '-E', 'help'], timeout=SUBPROCESS_TIMEOUT,
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()]
return render_engines
def perform_presubmission_tasks(self, project_path):
packed_path = self.pack_project_file(project_path, timeout=120)
return packed_path
if __name__ == "__main__":
x = Blender.get_detected_gpus()
x = Blender().system_info()
print(x)
+76 -29
View File
@@ -12,41 +12,71 @@ class BlenderRenderWorker(BaseRenderWorker):
engine = Blender
def __init__(self, input_path, output_path, engine_path, args=None, parent=None, name=None):
super(BlenderRenderWorker, self).__init__(input_path=input_path, output_path=output_path,
engine_path=engine_path, args=args, parent=parent, name=name)
# Args
self.blender_engine = self.args.get('engine', 'BLENDER_EEVEE').upper()
self.export_format = self.args.get('export_format', None) or 'JPEG'
self.camera = self.args.get('camera', None)
super(BlenderRenderWorker, self).__init__(input_path=input_path, output_path=output_path, engine_path=engine_path, args=args, parent=parent, name=name)
# Stats
self.__frame_percent_complete = 0.0
# Scene Info
self.scene_info = Blender(engine_path).get_scene_info(input_path)
self.start_frame = int(self.scene_info.get('start_frame', 1))
self.end_frame = int(self.scene_info.get('end_frame', self.start_frame))
self.project_length = (self.end_frame - self.start_frame) + 1
self.scene_info = {}
self.current_frame = -1
def generate_worker_subprocess(self):
cmd = [self.renderer_path]
self.scene_info = Blender(self.engine_path).get_project_info(self.input_path)
cmd = [self.engine_path]
if self.args.get('background', True): # optionally run render not in background
cmd.append('-b')
cmd.append(self.input_path)
# Python expressions
# 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
cmd.append('--python-expr')
python_exp = 'import bpy; bpy.context.scene.render.use_overwrite = False;'
if self.camera:
python_exp = python_exp + f"bpy.context.scene.camera = bpy.data.objects['{self.camera}'];"
# insert any other python exp checks here
# Setup Custom Resolution
if self.args.get('resolution'):
res = self.args.get('resolution')
python_exp += 'bpy.context.scene.render.resolution_percentage = 100;'
python_exp += f'bpy.context.scene.render.resolution_x={res[0]}; bpy.context.scene.render.resolution_y={res[1]};'
# Setup Custom Camera
custom_camera = self.args.get('camera', None)
if custom_camera:
python_exp += f"bpy.context.scene.camera = bpy.data.objects['{custom_camera}'];"
# Set Render Device for Cycles (gpu/cpu/any)
if blender_engine == 'CYCLES':
render_device = self.args.get('render_device', 'any').lower()
if render_device not in {'any', 'gpu', 'cpu'}:
raise AttributeError(f"Invalid Cycles render device: {render_device}")
use_gpu = render_device in {'any', 'gpu'}
use_cpu = render_device in {'any', 'cpu'}
python_exp = python_exp + ("exec(\"for device in bpy.context.preferences.addons["
f"'cycles'].preferences.devices: device.use = {use_cpu} if device.type == 'CPU'"
f" else {use_gpu}\")")
# -- insert any other python exp checks / generators here --
# End Python expressions here
cmd.append(python_exp)
path_without_ext = os.path.splitext(self.output_path)[0] + "_"
cmd.extend(['-E', self.blender_engine, '-o', path_without_ext, '-F', self.export_format])
# Export format
export_format = self.args.get('export_format', None) or 'JPEG'
main_part, ext = os.path.splitext(self.output_path)
# 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
cmd.extend(['-s', self.start_frame, '-e', self.end_frame, '-a'])
@@ -60,11 +90,15 @@ class BlenderRenderWorker(BaseRenderWorker):
def _parse_stdout(self, line):
pattern = re.compile(
cycles_pattern = re.compile(
r'Fra:(?P<frame>\d*).*Mem:(?P<memory>\S+).*Time:(?P<time>\S+)(?:.*Remaining:)?(?P<remaining>\S*)')
found = pattern.search(line)
if found:
stats = found.groupdict()
cycles_match = cycles_pattern.search(line)
eevee_pattern = re.compile(
r"Rendering\s+(?P<current>\d+)\s*/\s*(?P<total>\d+)\s+samples"
)
eevee_match = eevee_pattern.search(line)
if cycles_match:
stats = cycles_match.groupdict()
memory_use = stats['memory']
time_elapsed = stats['time']
time_remaining = stats['remaining'] or 'Unknown'
@@ -79,27 +113,40 @@ class BlenderRenderWorker(BaseRenderWorker):
logger.debug(
'Frame:{0} | Mem:{1} | Time:{2} | Remaining:{3}'.format(self.current_frame, memory_use,
time_elapsed, time_remaining))
elif eevee_match:
self.__frame_percent_complete = int(eevee_match.groups()[0]) / int(eevee_match.groups()[1])
logger.debug(f'Frame:{self.current_frame} | Samples:{eevee_match.groups()[0]}/{eevee_match.groups()[1]}')
elif "Rendering frame" in line: # used for eevee
self.current_frame = int(line.split("Rendering frame")[-1].strip())
elif "file doesn't exist" in line.lower():
self.log_error(line, halt_render=True)
elif line.lower().startswith('error'):
self.log_error(line)
elif 'Saved' in line or 'Saving' in line or 'quit' in line:
match = re.match(r'Time: (.*) \(Saving', line)
if match:
time_completed = match.groups()[0]
render_stats_match = re.match(r'Time: (.*) \(Saving', line)
output_filename_match = re.match(r"Saved: .*_(\d+)\.\w+", line) # try to get frame # from filename
if output_filename_match:
output_file_number = output_filename_match.groups()[0]
try:
self.current_frame = int(output_file_number)
self._send_frame_complete_notification()
except ValueError:
pass
elif render_stats_match:
time_completed = render_stats_match.groups()[0]
frame_count = self.current_frame - self.end_frame + self.total_frames
logger.info(f'Frame #{self.current_frame} - '
f'{frame_count} of {self.total_frames} completed in {time_completed} | '
f'Total Elapsed Time: {datetime.now() - self.start_time}')
else:
logger.debug(line)
else:
pass
# if len(line.strip()):
# logger.debug(line.strip())
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
else:
whole_frame_percent = (self.current_frame - self.start_frame) / self.total_frames
@@ -140,7 +187,7 @@ class BlenderRenderWorker(BaseRenderWorker):
if __name__ == '__main__':
import pprint
x = Blender.get_scene_info('/Users/brett/Desktop/TC Previz/nallie_farm.blend')
x = Blender.get_project_info('/Users/brett/Desktop/TC Previz/nallie_farm.blend')
pprint.pprint(x)
# logging.basicConfig(format='%(asctime)s - %(message)s', datefmt='%d-%b-%y %H:%M:%S', level=logging.DEBUG)
+3 -2
View File
@@ -2,6 +2,7 @@ import json
import bpy
# Get all cameras
scene = bpy.data.scenes[0]
cameras = []
for cam_obj in bpy.data.cameras:
user_map = bpy.data.user_map(subset={cam_obj}, value_types={'OBJECT'})
@@ -12,10 +13,10 @@ for cam_obj in bpy.data.cameras:
'lens': cam_obj.lens,
'lens_unit': cam_obj.lens_unit,
'sensor_height': cam_obj.sensor_height,
'sensor_width': cam_obj.sensor_width}
'sensor_width': cam_obj.sensor_width,
'is_active': scene.camera.name_full == cam_obj.name_full}
cameras.append(cam)
scene = bpy.data.scenes[0]
data = {'cameras': cameras,
'engine': scene.render.engine,
'frame_start': scene.frame_start,
@@ -0,0 +1,21 @@
import bpy
import json
# Force CPU rendering
bpy.context.preferences.addons["cycles"].preferences.compute_device_type = "NONE"
bpy.context.scene.cycles.device = "CPU"
# Ensure Cycles is available
bpy.context.preferences.addons['cycles'].preferences.get_devices()
# Collect the devices information
devices_info = []
for device in bpy.context.preferences.addons['cycles'].preferences.devices:
devices_info.append({
"name": device.name,
"type": device.type,
"use": device.use
})
# Print the devices information in JSON format
print("GPU DATA:" + json.dumps(devices_info))
+295
View File
@@ -0,0 +1,295 @@
import logging
import os
import shutil
import tempfile
import requests
from tqdm import tqdm
logger = logging.getLogger()
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']
def __init__(self):
pass
# --------------------------------------------
# Required Overrides for Subclasses:
# --------------------------------------------
@classmethod
def find_most_recent_version(cls, system_os=None, cpu=None, lts_only=False):
"""
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
def version_is_available_to_download(cls, version, system_os=None, cpu=None):
"""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
def download_engine(cls, version, download_location, system_os=None, cpu=None, timeout=120, progress_callback=None):
"""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.
progress_callback (callable, optional): A callback function that is called periodically with the current download progress.
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
def download_and_extract_app(cls, remote_url, download_location, timeout=120, progress_callback=None):
"""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.
progress_callback (callable, optional): A callback function that is called periodically with the current download progress.
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.
"""
if progress_callback:
progress_callback(0)
# Create a temp download directory
temp_download_dir = tempfile.mkdtemp()
temp_downloaded_file_path = os.path.join(temp_download_dir, os.path.basename(remote_url))
try:
output_dir_name = os.path.basename(remote_url)
for fmt in cls.supported_formats:
output_dir_name = output_dir_name.split(fmt)[0]
if os.path.exists(os.path.join(download_location, output_dir_name)):
logger.error(f"Engine download for {output_dir_name} already exists")
return None
if not os.path.exists(temp_downloaded_file_path):
# Make a GET request to the URL with stream=True to enable streaming
logger.info(f"Downloading {output_dir_name} from {remote_url}")
response = requests.get(remote_url, stream=True, timeout=timeout)
# Check if the request was successful
if response.status_code == 200:
# Get the total file size from the "Content-Length" header
file_size = int(response.headers.get("Content-Length", 0))
# Create a progress bar using tqdm
progress_bar = tqdm(total=file_size, unit="B", unit_scale=True)
# Open a file for writing in binary mode
total_saved = 0
with open(temp_downloaded_file_path, "wb") as file:
for chunk in response.iter_content(chunk_size=1024):
if chunk:
# Write the chunk to the file
file.write(chunk)
total_saved += len(chunk)
# Update the progress bar
progress_bar.update(len(chunk))
if progress_callback:
percent = float(total_saved) / float(file_size)
progress_callback(percent)
# Close the progress bar
progress_callback(1.0)
progress_bar.close()
logger.info(f"Successfully downloaded {os.path.basename(temp_downloaded_file_path)}")
else:
logger.error(f"Failed to download the file. Status code: {response.status_code}")
return None
os.makedirs(download_location, exist_ok=True)
# Extract the downloaded file
# Process .tar.xz files
if temp_downloaded_file_path.lower().endswith('.tar.xz'):
import tarfile
try:
with tarfile.open(temp_downloaded_file_path, 'r:xz') as tar:
tar.extractall(path=download_location)
logger.info(
f'Successfully extracted {os.path.basename(temp_downloaded_file_path)} to {download_location}')
except tarfile.TarError as e:
logger.error(f'Error extracting {temp_downloaded_file_path}: {e}')
except FileNotFoundError:
logger.error(f'File not found: {temp_downloaded_file_path}')
# Process .zip files
elif temp_downloaded_file_path.lower().endswith('.zip'):
import zipfile
try:
with zipfile.ZipFile(temp_downloaded_file_path, 'r') as zip_ref:
zip_ref.extractall(download_location)
logger.info(
f'Successfully extracted {os.path.basename(temp_downloaded_file_path)} to {download_location}')
except zipfile.BadZipFile:
logger.error(f'Error: {temp_downloaded_file_path} is not a valid ZIP file.')
except FileNotFoundError:
logger.error(f'File not found: {temp_downloaded_file_path}')
# Process .dmg files (macOS only)
elif temp_downloaded_file_path.lower().endswith('.dmg'):
import dmglib
dmg = dmglib.DiskImage(temp_downloaded_file_path)
for mount_point in dmg.attach():
try:
copy_directory_contents(mount_point, os.path.join(download_location, output_dir_name))
logger.info(f'Successfully copied {os.path.basename(temp_downloaded_file_path)} '
f'to {download_location}')
except FileNotFoundError:
logger.error(f'Error: The source .app bundle does not exist.')
except PermissionError:
logger.error(f'Error: Permission denied to copy {download_location}.')
except Exception as e:
logger.error(f'An error occurred: {e}')
dmg.detach()
else:
logger.error("Unknown file. Unable to extract binary.")
except Exception as e:
logger.exception(e)
# remove downloaded file on completion
shutil.rmtree(temp_download_dir)
return download_location
# Function to copy directory contents but ignore symbolic links and hidden files
def copy_directory_contents(src_dir, dest_dir):
try:
# Create the destination directory if it doesn't exist
os.makedirs(dest_dir, exist_ok=True)
for item in os.listdir(src_dir):
item_path = os.path.join(src_dir, item)
# Ignore symbolic links
if os.path.islink(item_path):
continue
# Ignore hidden files or directories (those starting with a dot)
if not item.startswith('.'):
dest_item_path = os.path.join(dest_dir, item)
# If it's a directory, recursively copy its contents
if os.path.isdir(item_path):
copy_directory_contents(item_path, dest_item_path)
else:
# Otherwise, copy the file
shutil.copy2(item_path, dest_item_path)
except PermissionError as ex:
logger.error(f"Permissions error: {ex}")
except Exception as e:
logger.exception(f"Error copying directory contents: {e}")
+178 -32
View File
@@ -1,31 +1,196 @@
import logging
import os
import platform
import subprocess
from typing import Optional, List, Dict, Any, Type
logger = logging.getLogger()
SUBPROCESS_TIMEOUT = 5
SUBPROCESS_TIMEOUT = 10
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 engines
install_paths = []
supported_extensions = []
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.
"""
def __init__(self, custom_path=None):
self.custom_renderer_path = custom_path
if not self.renderer_path():
raise FileNotFoundError(f"Cannot find path to renderer for {self.name()} instance")
install_paths: List[str] = []
binary_names: Dict[str, str] = {}
def renderer_path(self):
return self.custom_renderer_path or self.default_renderer_path()
# --------------------------------------------
# Required Overrides for Subclasses:
# --------------------------------------------
def __init__(self, custom_path: Optional[str] = None) -> None:
"""Initialize the render engine.
Args:
custom_path: Optional custom path to the engine executable.
Raises:
FileNotFoundError: If the engine executable cannot be found.
"""
self.custom_engine_path: Optional[str] = custom_path
if not self.engine_path() or not os.path.exists(self.engine_path()):
raise FileNotFoundError(f"Cannot find path to engine for {self.name()} instance: {self.engine_path()}")
if not os.access(self.engine_path(), os.X_OK):
logger.warning(f"Path is not executable. Setting permissions to 755 for {self.engine_path()}")
os.chmod(self.engine_path(), 0o755)
def version(self) -> str:
"""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: str, timeout: int = 10) -> Dict[str, Any]:
"""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 name(cls):
return cls.__name__.lower()
def get_output_formats(cls) -> List[str]:
"""Returns a list of available output formats supported by the engine.
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() -> Type[Any]: # override when subclassing to link worker class
raise NotImplementedError("Worker class not implemented")
# --------------------------------------------
# Optional Overrides for Subclasses:
# --------------------------------------------
def supported_extensions(self) -> List[str]:
"""Return a list of file extensions supported by this engine.
Returns:
List[str]: List of supported file extensions (e.g., ['.blend', '.mp4']).
"""
return []
def get_help(self) -> str:
"""Retrieves the help documentation for the engine.
This method runs the engine's help command (default: '-h') and captures the output.
Override this method if the engine uses a different help flag.
Returns:
str: The help documentation as a string.
Raises:
FileNotFoundError: If the engine path is not found.
"""
path = self.engine_path()
if not path:
raise FileNotFoundError(f"Engine path not found: {path}")
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) -> Dict[str, Any]:
"""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: str) -> str:
"""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) -> Dict[str, Any]:
"""Return command-line arguments for this engine.
Returns:
Dict[str, Any]: Dictionary of argument specifications.
"""
return {}
@staticmethod
def downloader() -> Optional[Any]:
"""Return the downloader class for this engine.
Returns:
Optional[Any]: Downloader class instance, or None if no downloader is used.
"""
return None
def ui_options(self) -> Dict[str, Any]:
"""Return UI configuration options for this engine.
Returns:
Dict[str, Any]: Dictionary of UI options and their configurations.
"""
return {}
# --------------------------------------------
# Do Not Override These Methods:
# --------------------------------------------
def engine_path(self) -> Optional[str]:
"""Return the path to the engine executable.
Returns:
Optional[str]: Path to the engine executable, or None if not found.
"""
return self.custom_engine_path or self.default_engine_path()
@classmethod
def default_renderer_path(cls):
path = None
def name(cls) -> str:
"""Return the name of this engine.
Returns:
str: Engine name in lowercase.
"""
return str(cls.__name__).lower()
@classmethod
def default_engine_path(cls) -> Optional[str]:
"""Find the default path to the engine executable.
Returns:
Optional[str]: Default path to the engine executable, or None if not found.
"""
path: Optional[str] = None
try: # Linux and macOS
path = subprocess.check_output(['which', cls.name()], timeout=SUBPROCESS_TIMEOUT).decode('utf-8').strip()
except (subprocess.CalledProcessError, FileNotFoundError):
@@ -35,22 +200,3 @@ class BaseRenderEngine(object):
except Exception as e:
logger.exception(e)
return path
def version(self):
raise NotImplementedError("version not implemented")
def get_help(self):
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
@classmethod
def get_output_formats(cls):
raise NotImplementedError(f"get_output_formats not implemented for {cls.__name__}")
@classmethod
def get_arguments(cls):
pass
+388 -116
View File
@@ -3,14 +3,18 @@ import io
import json
import logging
import os
import signal
import subprocess
import threading
import time
from datetime import datetime
from typing import Optional, Dict, Any, List, Union
import psutil
from pubsub import pub
from sqlalchemy import Column, Integer, String, DateTime, JSON
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.ext.mutable import MutableDict
from src.utilities.misc_helper import get_time_elapsed
from src.utilities.status_utils import RenderStatus, string_to_status
@@ -23,60 +27,81 @@ class BaseRenderWorker(Base):
__tablename__ = 'render_workers'
id = Column(String, primary_key=True)
hostname = Column(String, nullable=True)
input_path = Column(String)
output_path = Column(String)
date_created = Column(DateTime)
start_time = Column(DateTime, nullable=True)
end_time = Column(DateTime, nullable=True)
renderer = Column(String)
renderer_version = Column(String)
renderer_path = Column(String)
engine_name = Column(String)
engine_version = Column(String)
engine_path = Column(String)
priority = Column(Integer)
project_length = Column(Integer)
start_frame = Column(Integer)
end_frame = Column(Integer, nullable=True)
parent = Column(String, nullable=True)
children = Column(JSON)
children = Column(MutableDict.as_mutable(JSON))
args = Column(MutableDict.as_mutable(JSON))
name = Column(String)
file_hash = Column(String)
_status = Column(String)
engine = None
# --------------------------------------------
# Required Overrides for Subclasses:
# --------------------------------------------
def __init__(self, input_path, output_path, engine_path, priority=2, args=None, ignore_extensions=True, parent=None,
name=None):
def __init__(self, input_path: str, output_path: str, engine_path: str, priority: int = 2,
args: Optional[Dict[str, Any]] = None, ignore_extensions: bool = True,
parent: Optional[str] = None, name: Optional[str] = None) -> None:
"""Initialize a render worker.
Args:
input_path: Path to the input project file.
output_path: Path where output files will be saved.
engine_path: Path to the render engine executable.
priority: Job priority level (default: 2).
args: Additional arguments for the render job.
ignore_extensions: Whether to ignore file extension validation.
parent: Parent job ID for distributed jobs.
name: Custom name for the job.
Raises:
ValueError: If file extension is not supported.
NotImplementedError: If engine is not defined.
"""
if not ignore_extensions:
if not any(ext in input_path for ext in self.engine.supported_extensions):
err_meg = f'Cannot find valid project with supported file extension for {self.engine.name()} renderer'
if not any(ext in input_path for ext in self.engine.supported_extensions()):
err_meg = f"Cannot find valid project with supported file extension for '{self.engine.name()}'"
logger.error(err_meg)
raise ValueError(err_meg)
if not self.engine:
raise NotImplementedError("Engine not defined")
raise NotImplementedError(f"Engine not defined for {self.__class__.__name__}")
def generate_id():
"""Generate a unique job ID."""
import uuid
return str(uuid.uuid4()).split('-')[0]
# Essential Info
self.id = generate_id()
self.hostname = None
self.input_path = input_path
self.output_path = output_path
self.args = args or {}
self.date_created = datetime.now()
self.renderer = self.engine.name()
self.renderer_path = engine_path
self.renderer_version = self.engine(engine_path).version()
self.custom_renderer_path = None
self.engine_name = self.engine.name()
self.engine_path = engine_path
self.engine_version = self.engine(engine_path).version()
self.custom_engine_path = None
self.priority = priority
self.parent = parent
self.children = {}
self.name = name or os.path.basename(input_path)
self.maximum_attempts = 3
# Frame Ranges
self.project_length = -1
self.current_frame = 0 # should this be a 1 ?
self.start_frame = 0 # should this be a 1 ?
self.current_frame = 0
self.start_frame = 0
self.end_frame = None
# Logging
@@ -89,14 +114,73 @@ class BaseRenderWorker(Base):
self.errors = []
# Threads and processes
self.__thread = threading.Thread(target=self.run, args=())
self.__thread = threading.Thread(target=self.__run, args=())
self.__thread.daemon = True
self.__process = None
self.last_output = None
self.__last_output_time = None
self.watchdog_timeout = 120
def generate_worker_subprocess(self) -> List[str]:
"""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: str) -> None:
"""Parses a line of standard output from the engine.
This method should be overridden in a subclass to implement the logic for processing
and interpreting a single line of output from the engine'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 engine'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) -> float:
"""Return the completion percentage of this job.
Returns:
float: Completion percentage between 0.0 and 1.0.
"""
# todo: fix this
if self.status == RenderStatus.COMPLETED:
return 1.0
return 0
def post_processing(self) -> None:
"""Override to perform any engine-specific postprocessing"""
pass
# --------------------------------------------
# Do Not Override These Methods:
# --------------------------------------------
def __repr__(self):
"""Return string representation of the worker.
Returns:
str: String representation showing job details.
"""
return f"<Job id:{self.id} p{self.priority} {self.engine_name}-{self.engine_version} '{self.name}' status:{self.status.value}>"
@property
def total_frames(self):
return (self.end_frame or self.project_length) - self.start_frame + 1
return max(self.end_frame, 1) - self.start_frame + 1
@property
def status(self):
@@ -116,158 +200,316 @@ class BaseRenderWorker(Base):
self._status = RenderStatus.CANCELLED.value
return string_to_status(self._status)
def validate(self):
if not os.path.exists(self.input_path):
raise FileNotFoundError(f"Cannot find input path: {self.input_path}")
self.generate_subprocess()
def _send_frame_complete_notification(self):
pub.sendMessage('frame_complete', job_id=self.id, frame_number=self.current_frame)
def generate_subprocess(self):
"""Generate subprocess command arguments.
Returns:
List[str]: List of command line arguments for the subprocess.
Raises:
ValueError: If argument conflicts are detected.
"""
# Convert raw args from string if available and catch conflicts
generated_args = [str(x) for x in self.generate_worker_subprocess()]
generated_args_flags = [x for x in generated_args if x.startswith('-')]
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.debug(f"Generated args for subprocess: {generated_args}")
raise ValueError(msg)
return generated_args
def get_raw_args(self):
raw_args_string = self.args.get('raw', None)
"""Parse raw command line arguments from args dictionary.
Returns:
Optional[List[str]]: Parsed raw arguments, or None if no raw args.
"""
raw_args_string = self.args.get('raw', '')
raw_args = None
if raw_args_string:
import shlex
raw_args = shlex.split(raw_args_string)
return raw_args
def generate_worker_subprocess(self):
raise NotImplementedError("generate_worker_subprocess not implemented")
def log_path(self):
"""Generate the log file path for this job.
Returns:
str: Path to the log file.
"""
filename = (self.name or os.path.basename(self.input_path)) + '_' + \
self.date_created.strftime("%Y.%m.%d_%H.%M.%S") + '.log'
return os.path.join(os.path.dirname(self.input_path), filename)
def start(self):
"""Start the render job.
if self.status not in [RenderStatus.SCHEDULED, RenderStatus.NOT_STARTED]:
Validates input paths and engine availability, then starts the render thread.
"""
if self.status not in [RenderStatus.SCHEDULED, RenderStatus.NOT_STARTED, RenderStatus.CONFIGURING]:
logger.error(f"Trying to start job with status: {self.status}")
return
if not os.path.exists(self.input_path):
self.status = RenderStatus.ERROR
msg = 'Cannot find input path: {}'.format(self.input_path)
msg = f'Cannot find input path: {self.input_path}'
logger.error(msg)
self.errors.append(msg)
return
if not os.path.exists(self.renderer_path):
if not os.path.exists(self.engine_path):
self.status = RenderStatus.ERROR
msg = 'Cannot find render engine path for {}'.format(self.engine.name())
msg = f'Cannot find render engine path for {self.engine.name()}'
logger.error(msg)
self.errors.append(msg)
return
self.status = RenderStatus.RUNNING
self.status = RenderStatus.RUNNING if not self.children else RenderStatus.WAITING_FOR_SUBJOBS
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()
def run(self):
# handle multiple attempts at running subprocess
def __run__subprocess_cycle(self, log_file):
subprocess_cmds = self.generate_subprocess()
initial_file_count = len(self.file_list())
failed_attempts = 0
log_file.write(f"Running command: {subprocess_cmds}\n")
log_file.write('=' * 80 + '\n\n')
while True:
# 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:
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
return_code = self.__setup_and_run_process(log_file, subprocess_cmds)
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 engine 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 engine 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)
subprocess_cmds = self.generate_subprocess()
initial_file_count = len(self.file_list())
attempt_number = 0
with open(self.log_path(), "a") as log_file:
with open(self.log_path(), "a") as f:
self.log_and_print(f"{self.start_time.isoformat()} - Starting "
f"{self.engine.name()} {self.engine_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)
f.write(f"{self.start_time.isoformat()} - Starting {self.engine.name()} {self.renderer_version} "
f"render for {self.input_path}\n\n")
f.write(f"Running command: {subprocess_cmds}\n")
f.write('=' * 80 + '\n\n')
# 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
while True:
# Log attempt #
if attempt_number:
f.write(f'\n{"=" * 80} Attempt #{attempt_number} {"=" * 30}\n\n')
logger.warning(f"Restarting render - Attempt #{attempt_number}")
attempt_number += 1
msg = f"Frames: Expected ({expected_list_length}) vs actual ({file_list_length}) for {self}"
self.log_and_print(msg, log_file, 'debug')
# Start process and get updates
self.__process = subprocess.Popen(subprocess_cmds, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
universal_newlines=False)
for c in io.TextIOWrapper(self.__process.stdout, encoding="utf-8"): # or another encoding
f.write(c)
self.last_output = c.strip()
self._parse_stdout(c.strip())
f.write('\n')
# Check return codes and process
return_code = self.__process.wait()
self.end_time = datetime.now()
if self.status in [RenderStatus.CANCELLED, RenderStatus.ERROR]: # user cancelled
message = f"{self.engine.name()} render ended with status '{self.status}' " \
f"after {self.time_elapsed()}"
f.write(message)
return
if not return_code:
message = f"{'=' * 50}\n\n{self.engine.name()} render completed successfully in {self.time_elapsed()}"
f.write(message)
break
# Handle non-zero return codes
message = f"{'=' * 50}\n\n{self.engine.name()} render failed with code {return_code} " \
f"after {self.time_elapsed()}"
f.write(message)
self.errors.append(message)
# if file output hasn't increased, return as error, otherwise restart process.
if len(self.file_list()) <= initial_file_count:
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
return
# todo: create new subjob to generate missing frames
if self.children:
from src.distributed_job_manager import DistributedJobManager
DistributedJobManager.wait_for_subjobs(local_job=self)
# 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
logger.debug("Starting post-processing work")
self.post_processing()
self.status = RenderStatus.COMPLETED
logger.info(f"Render {self.id}-{self.name} completed successfully after {self.time_elapsed()}")
# 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')
def post_processing(self):
pass
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,
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)
# 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.flush()
os.fsync(f.fileno())
except Exception as e:
logger.error(f"Error saving log to disk: {e}")
try:
self._parse_stdout(c.strip())
except Exception as e:
logger.error(f'Error parsing stdout: {e}')
f.write('\n')
# Check return codes and process
return_code = self.__process.wait()
except Exception as e:
message = f'Uncaught error running render process: {e}'
f.write(message)
logger.exception(message)
self.__kill_process()
# let watchdog end before continuing - prevents multiple watchdogs running when process restarts
if watchdog_thread.is_alive():
watchdog_thread.join()
return return_code
def __kill_process(self):
try:
if self.__process.poll():
return
logger.debug(f"Trying to kill process {self.__process}")
self.__process.terminate()
self.__process.kill()
if os.name == 'posix': # linux / macos
os.killpg(os.getpgid(self.__process.pid), signal.SIGTERM)
os.killpg(os.getpgid(self.__process.pid), signal.SIGKILL)
else: # windows
parent = psutil.Process(self.__process.pid)
for child in parent.children(recursive=True):
child.kill()
self.__process.wait(timeout=5)
logger.debug(f"Process ended with status {self.__process.poll()}")
except (ProcessLookupError, AttributeError, psutil.NoSuchProcess):
pass
except Exception as e:
logger.error(f"Error stopping the process: {e}")
def is_running(self):
if self.__thread:
"""Check if the render job is currently running.
Returns:
bool: True if the job is running, False otherwise.
"""
if hasattr(self, '__thread'):
return self.__thread.is_alive()
return False
def log_error(self, error_line, halt_render=False):
"""Log an error and optionally halt the render.
Args:
error_line: Error message to log.
halt_render: Whether to stop the render due to this error.
"""
logger.error(error_line)
self.errors.append(error_line)
if halt_render:
self.stop(is_error=True)
def stop(self, is_error=False):
if hasattr(self, '__process'):
try:
process = psutil.Process(self.__process.pid)
for proc in process.children(recursive=True):
proc.kill()
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]:
"""Stop the render job.
Args:
is_error: Whether this stop is due to an error.
"""
logger.debug(f"Stopping {self}")
# cleanup status
if self.status in [RenderStatus.RUNNING, RenderStatus.NOT_STARTED, RenderStatus.SCHEDULED,
RenderStatus.CONFIGURING]:
if is_error:
err_message = self.errors[-1] if self.errors else 'Unknown error'
logger.error(f"Halting render due to error: {err_message}")
@@ -275,28 +517,46 @@ class BaseRenderWorker(Base):
else:
self.status = RenderStatus.CANCELLED
def percent_complete(self):
return 0
def _parse_stdout(self, line):
raise NotImplementedError("_parse_stdout not implemented")
self.__kill_process()
if self.is_running(): # allow the log files to close
self.__thread.join(timeout=5)
def time_elapsed(self):
"""Get elapsed time for this job.
Returns:
str: Formatted time elapsed string.
"""
return get_time_elapsed(self.start_time, self.end_time)
def file_list(self):
"""Get list of output files for this job.
Returns:
List[str]: List of output file paths.
"""
try:
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()
return file_list
except FileNotFoundError:
return []
def json(self):
"""Convert worker to JSON-serializable dictionary.
Returns:
Dict[str, Any]: Dictionary representation of worker data.
"""
job_dict = {
'id': self.id,
'name': self.name,
'hostname': self.hostname,
'input_path': self.input_path,
'output_path': self.output_path,
'priority': self.priority,
@@ -309,20 +569,23 @@ class BaseRenderWorker(Base):
'file_hash': self.file_hash,
'percent_complete': self.percent_complete(),
'file_count': len(self.file_list()),
'renderer': self.renderer,
'renderer_version': self.renderer_version,
'engine': self.engine_name,
'engine_version': self.engine_version,
'errors': getattr(self, 'errors', None),
'start_frame': self.start_frame,
'end_frame': self.end_frame,
'total_frames': self.total_frames,
'last_output': getattr(self, 'last_output', None),
'log_path': self.log_path()
'log_path': self.log_path(),
'args': self.args
}
# convert to json and back to auto-convert dates to iso format
def date_serializer(o):
"""Serialize datetime objects to ISO format."""
if isinstance(o, datetime):
return o.isoformat()
return None
json_convert = json.dumps(job_dict, default=date_serializer)
worker_json = json.loads(json_convert)
@@ -330,6 +593,15 @@ class BaseRenderWorker(Base):
def timecode_to_frames(timecode, frame_rate):
"""Convert timecode string to frame number.
Args:
timecode: Timecode in format HH:MM:SS:FF.
frame_rate: Frames per second.
Returns:
int: Frame number corresponding to timecode.
"""
e = [int(x) for x in timecode.split(':')]
seconds = (((e[0] * 60) + e[1] * 60) + e[2])
frames = (seconds * frame_rate) + e[-1] + 1
-139
View File
@@ -1,139 +0,0 @@
import logging
import os
import shutil
import tarfile
import tempfile
import zipfile
import requests
from tqdm import tqdm
supported_formats = ['.zip', '.tar.xz', '.dmg']
logger = logging.getLogger()
def download_and_extract_app(remote_url, download_location, timeout=120):
# Create a temp download directory
temp_download_dir = tempfile.mkdtemp()
temp_downloaded_file_path = os.path.join(temp_download_dir, os.path.basename(remote_url))
try:
output_dir_name = os.path.basename(remote_url)
for fmt in supported_formats:
output_dir_name = output_dir_name.split(fmt)[0]
if os.path.exists(os.path.join(download_location, output_dir_name)):
logger.error(f"Engine download for {output_dir_name} already exists")
return
if not os.path.exists(temp_downloaded_file_path):
# Make a GET request to the URL with stream=True to enable streaming
logger.info(f"Downloading {output_dir_name} from {remote_url}")
response = requests.get(remote_url, stream=True, timeout=timeout)
# Check if the request was successful
if response.status_code == 200:
# Get the total file size from the "Content-Length" header
file_size = int(response.headers.get("Content-Length", 0))
# Create a progress bar using tqdm
progress_bar = tqdm(total=file_size, unit="B", unit_scale=True)
# Open a file for writing in binary mode
with open(temp_downloaded_file_path, "wb") as file:
for chunk in response.iter_content(chunk_size=1024):
if chunk:
# Write the chunk to the file
file.write(chunk)
# Update the progress bar
progress_bar.update(len(chunk))
# Close the progress bar
progress_bar.close()
logger.info(f"Successfully downloaded {os.path.basename(temp_downloaded_file_path)}")
else:
logger.error(f"Failed to download the file. Status code: {response.status_code}")
return
os.makedirs(download_location, exist_ok=True)
# Extract the downloaded file
# Process .tar.xz files
if temp_downloaded_file_path.lower().endswith('.tar.xz'):
try:
with tarfile.open(temp_downloaded_file_path, 'r:xz') as tar:
tar.extractall(path=download_location)
logger.info(
f'Successfully extracted {os.path.basename(temp_downloaded_file_path)} to {download_location}')
except tarfile.TarError as e:
logger.error(f'Error extracting {temp_downloaded_file_path}: {e}')
except FileNotFoundError:
logger.error(f'File not found: {temp_downloaded_file_path}')
# Process .zip files
elif temp_downloaded_file_path.lower().endswith('.zip'):
try:
with zipfile.ZipFile(temp_downloaded_file_path, 'r') as zip_ref:
zip_ref.extractall(download_location)
logger.info(
f'Successfully extracted {os.path.basename(temp_downloaded_file_path)} to {download_location}')
except zipfile.BadZipFile as e:
logger.error(f'Error: {temp_downloaded_file_path} is not a valid ZIP file.')
except FileNotFoundError:
logger.error(f'File not found: {temp_downloaded_file_path}')
# Process .dmg files (macOS only)
elif temp_downloaded_file_path.lower().endswith('.dmg'):
import dmglib
dmg = dmglib.DiskImage(temp_downloaded_file_path)
for mount_point in dmg.attach():
try:
copy_directory_contents(mount_point, os.path.join(download_location, output_dir_name))
logger.info(f'Successfully copied {os.path.basename(temp_downloaded_file_path)} to {download_location}')
except FileNotFoundError:
logger.error(f'Error: The source .app bundle does not exist.')
except PermissionError:
logger.error(f'Error: Permission denied to copy {download_location}.')
except Exception as e:
logger.error(f'An error occurred: {e}')
dmg.detach()
else:
logger.error("Unknown file. Unable to extract binary.")
except Exception as e:
logger.exception(e)
# remove downloaded file on completion
shutil.rmtree(temp_download_dir)
return download_location
# Function to copy directory contents but ignore symbolic links and hidden files
def copy_directory_contents(src_dir, dest_dir):
try:
# Create the destination directory if it doesn't exist
os.makedirs(dest_dir, exist_ok=True)
for item in os.listdir(src_dir):
item_path = os.path.join(src_dir, item)
# Ignore symbolic links
if os.path.islink(item_path):
continue
# Ignore hidden files or directories (those starting with a dot)
if not item.startswith('.'):
dest_item_path = os.path.join(dest_dir, item)
# If it's a directory, recursively copy its contents
if os.path.isdir(item_path):
copy_directory_contents(item_path, dest_item_path)
else:
# Otherwise, copy the file
shutil.copy2(item_path, dest_item_path)
except Exception as e:
logger.exception(f"Error copying directory contents: {e}")
-61
View File
@@ -1,61 +0,0 @@
import logging
from src.engines.engine_manager import EngineManager
logger = logging.getLogger()
class RenderWorkerFactory:
@staticmethod
def supported_classes():
# to add support for any additional RenderWorker classes, import their classes and add to list here
from src.engines.blender.blender_worker import BlenderRenderWorker
from src.engines.aerender.aerender_worker import AERenderWorker
from src.engines.ffmpeg.ffmpeg_worker import FFMPEGRenderWorker
classes = [BlenderRenderWorker, AERenderWorker, FFMPEGRenderWorker]
return classes
@staticmethod
def create_worker(renderer, input_path, output_path, engine_version=None, args=None, parent=None, name=None):
worker_class = RenderWorkerFactory.class_for_name(renderer)
# check to make sure we have versions installed
all_versions = EngineManager.all_versions_for_engine(renderer)
if not all_versions:
raise FileNotFoundError(f"Cannot find any installed {renderer} engines")
# Find the path to the requested engine version or use default
engine_path = None if engine_version else all_versions[0]['path']
if engine_version:
for ver in all_versions:
if ver['version'] == engine_version:
engine_path = ver['path']
break
# Download the required engine if not found locally
if not engine_path:
download_result = EngineManager.download_engine(renderer, engine_version)
if not download_result:
raise FileNotFoundError(f"Cannot download requested version: {renderer} {engine_version}")
engine_path = download_result['path']
logger.info("Engine downloaded. Creating worker.")
if not engine_path:
raise FileNotFoundError(f"Cannot find requested engine version {engine_version}")
return worker_class(input_path=input_path, output_path=output_path, engine_path=engine_path, args=args,
parent=parent, name=name)
@staticmethod
def supported_renderers():
return [x.engine.name() for x in RenderWorkerFactory.supported_classes()]
@staticmethod
def class_for_name(name):
name = name.lower()
for render_class in RenderWorkerFactory.supported_classes():
if render_class.engine.name() == name:
return render_class
raise LookupError(f'Cannot find class for name: {name}')
+356 -108
View File
@@ -2,176 +2,424 @@ import logging
import os
import shutil
import threading
import concurrent.futures
from pathlib import Path
from typing import Type, List, Dict, Any, Optional
from src.engines.blender.blender_downloader import BlenderDownloader
from src.engines.core.base_engine import BaseRenderEngine
from src.engines.blender.blender_engine import Blender
from src.engines.ffmpeg.ffmpeg_downloader import FFMPEGDownloader
from src.engines.ffmpeg.ffmpeg_engine import FFMPEG
from src.utilities.misc_helper import system_safe_path, current_system_os, current_system_cpu
from src.utilities.misc_helper import current_system_os, current_system_cpu
logger = logging.getLogger()
ENGINE_CLASSES = [Blender, FFMPEG]
class EngineManager:
"""Class that manages different versions of installed render engines and handles fetching and downloading new versions,
if possible.
"""
engines_path = "~/zordon-uploads/engines"
downloader_classes = {
"blender": BlenderDownloader,
"ffmpeg": FFMPEGDownloader,
# Add more engine types and corresponding downloader classes as needed
}
_default_instance: Optional['EngineManager'] = None
engines_path: Optional[str] = None
download_tasks: List[Any] = []
def __init__(self) -> None:
self.engines_path: Optional[str] = None
self.download_tasks: List[Any] = []
@classmethod
def supported_engines(cls):
return [Blender, FFMPEG]
def _sync_class(cls) -> None:
if cls._default_instance is not None:
cls.engines_path = cls._default_instance.engines_path
cls.download_tasks = cls._default_instance.download_tasks
@staticmethod
def supported_engines() -> list[type[BaseRenderEngine]]:
return ENGINE_CLASSES
# --- Installed Engines ---
def _engine_class_for_project_path(self, path: str) -> Type[BaseRenderEngine]:
_, extension = os.path.splitext(path)
extension = extension.lower().strip('.')
for engine_class in self.supported_engines():
engine = self.get_latest_engine_instance(engine_class)
if extension in engine.supported_extensions():
return engine_class
undefined_renderer_support = [x for x in self.supported_engines() if not self.get_latest_engine_instance(x).supported_extensions()]
return undefined_renderer_support[0]
def _engine_class_with_name(self, engine_name: str) -> Optional[Type[BaseRenderEngine]]:
for obj in self.supported_engines():
if obj.name().lower() == engine_name.lower():
return obj
return None
def _get_latest_engine_instance(self, engine_class: Type[BaseRenderEngine]) -> BaseRenderEngine:
newest = self.newest_installed_engine_data(engine_class.name())
engine = engine_class(newest["path"])
return engine
def _get_installed_engine_data(self, filter_name: Optional[str] = None, include_corrupt: bool = False,
ignore_system: bool = False) -> List[Dict[str, Any]]:
if not self.engines_path:
raise FileNotFoundError("Engine path is not set")
@classmethod
def all_engines(cls):
results = []
# Parse downloaded engine directory
try:
all_items = os.listdir(cls.engines_path)
all_directories = [item for item in all_items if os.path.isdir(os.path.join(cls.engines_path, item))]
all_items = os.listdir(self.engines_path)
all_directories = [item for item in all_items if os.path.isdir(os.path.join(self.engines_path, item))]
keys = ["engine", "version", "system_os", "cpu"]
for directory in all_directories:
# Split the input string by dashes to get segments
segments = directory.split('-')
# Create a dictionary with named keys
keys = ["engine", "version", "system_os", "cpu"]
result_dict = {keys[i]: segments[i] for i in range(min(len(keys), len(segments)))}
result_dict['type'] = 'managed'
# Figure out the binary name for the path
binary_name = result_dict['engine'].lower()
for eng in cls.supported_engines():
if eng.name().lower() == result_dict['engine']:
binary_name = eng.binary_names.get(result_dict['system_os'], binary_name)
# Find path to binary
path = None
for root, _, files in os.walk(system_safe_path(os.path.join(cls.engines_path, directory))):
if binary_name in files:
path = os.path.join(root, binary_name)
break
eng = self.engine_class_with_name(result_dict['engine'])
if eng:
binary_name = eng.binary_names.get(result_dict['system_os'], binary_name)
search_root = Path(self.engines_path) / directory
match = next((p for p in search_root.rglob(binary_name) if p.is_file()), None)
path = str(match) if match else None
result_dict['path'] = path
results.append(result_dict)
except FileNotFoundError:
logger.warning("Cannot find local engines download directory")
# add system installs to this list
for eng in cls.supported_engines():
if eng.default_renderer_path():
results.append({'engine': eng.name(), 'version': eng().version(),
'system_os': current_system_os(),
'cpu': current_system_cpu(),
'path': eng.default_renderer_path(), 'type': 'system'})
if not filter_name or filter_name == result_dict['engine']:
results.append(result_dict)
except FileNotFoundError as e:
logger.warning(f"Cannot find local engines download directory: {e}")
def fetch_engine_details(eng, include_corrupt=False):
version = eng().version()
if not version and not include_corrupt:
return
return {
'engine': eng.name(),
'version': version or 'error',
'system_os': current_system_os(),
'cpu': current_system_cpu(),
'path': eng.default_engine_path(),
'type': 'system'
}
if not ignore_system:
with concurrent.futures.ThreadPoolExecutor() as executor:
futures = {
executor.submit(fetch_engine_details, eng, include_corrupt): eng.name()
for eng in self.supported_engines()
if eng.default_engine_path() and (not filter_name or filter_name == eng.name())
}
for future in concurrent.futures.as_completed(futures):
result = future.result()
if result:
results.append(result)
return results
@classmethod
def all_versions_for_engine(cls, engine):
return [x for x in cls.all_engines() if x['engine'] == engine]
# --- Check for Updates ---
@classmethod
def newest_engine_version(cls, engine, system_os=None, cpu=None):
def _update_all_engines(self) -> None:
for engine in self.downloadable_engines():
update_available = self.is_engine_update_available(engine)
if update_available:
update_available['name'] = engine.name()
self.download_engine(engine.name(), update_available['version'], background=True)
def _all_version_data_for_engine(self, engine_name: str, include_corrupt=False, ignore_system=False) -> list:
versions = self.get_installed_engine_data(filter_name=engine_name, include_corrupt=include_corrupt, ignore_system=ignore_system)
sorted_versions = sorted(versions, key=lambda x: x['version'], reverse=True)
return sorted_versions
def _newest_installed_engine_data(self, engine_name: str, system_os=None, cpu=None, ignore_system=None) -> list:
system_os = system_os or current_system_os()
cpu = cpu or current_system_cpu()
try:
filtered = [x for x in cls.all_engines() if x['engine'] == engine and x['system_os'] == system_os and x['cpu'] == cpu]
versions = sorted(filtered, key=lambda x: x['version'], reverse=True)
return versions[0]
filtered = [x for x in self.all_version_data_for_engine(engine_name, ignore_system=ignore_system)
if x['system_os'] == system_os and x['cpu'] == cpu]
return filtered[0]
except IndexError:
logger.error(f"Cannot find newest engine version for {engine}-{system_os}-{cpu}")
return None
logger.error(f"Cannot find newest engine version for {engine_name}-{system_os}-{cpu}")
return []
@classmethod
def is_version_downloaded(cls, engine, version, system_os=None, cpu=None):
def _is_version_installed(self, engine_name: str, version: str, system_os=None, cpu=None, ignore_system=False):
system_os = system_os or current_system_os()
cpu = cpu or current_system_cpu()
filtered = [x for x in cls.all_engines() if
x['engine'] == engine and x['system_os'] == system_os and x['cpu'] == cpu and x['version'] == version]
filtered = [x for x in self.get_installed_engine_data(filter_name=engine_name, ignore_system=ignore_system) if
x['system_os'] == system_os and x['cpu'] == cpu and x['version'] == version]
return filtered[0] if filtered else False
@classmethod
def version_is_available_to_download(cls, engine, version, system_os=None, cpu=None):
def _version_is_available_to_download(self, engine_name: str, version, system_os=None, cpu=None):
try:
return cls.downloader_classes[engine].version_is_available_to_download(version=version, system_os=system_os,
cpu=cpu)
downloader = self.engine_class_with_name(engine_name).downloader()
return downloader.version_is_available_to_download(version=version, system_os=system_os, cpu=cpu)
except Exception as e:
logger.debug(f"Exception in version_is_available_to_download: {e}")
return None
@classmethod
def find_most_recent_version(cls, engine=None, system_os=None, cpu=None, lts_only=False):
def _find_most_recent_version(self, engine_name: str, system_os=None, cpu=None, lts_only=False) -> dict:
try:
return cls.downloader_classes[engine].find_most_recent_version(system_os=system_os, cpu=cpu)
downloader = self.engine_class_with_name(engine_name).downloader()
return downloader.find_most_recent_version(system_os=system_os, cpu=cpu)
except Exception as e:
logger.debug(f"Exception in find_most_recent_version: {e}")
return {}
def _is_engine_update_available(self, engine_class: Type[BaseRenderEngine], ignore_system_installs=False):
logger.debug(f"Checking for updates to {engine_class.name()}")
latest_version = engine_class.downloader().find_most_recent_version()
if not latest_version:
logger.warning(f"Could not find most recent version of {engine_class.name()} to download")
return None
@classmethod
def download_engine(cls, engine, version, system_os=None, cpu=None):
existing_download = cls.is_version_downloaded(engine, version, system_os, cpu)
if existing_download:
logger.info(f"Requested download of {engine} {version}, but local copy already exists")
return existing_download
version_num = latest_version.get('version')
if self.is_version_installed(engine_class.name(), version_num, ignore_system=ignore_system_installs):
logger.debug(f"Latest version of {engine_class.name()} ({version_num}) already downloaded")
return None
# Check if the provided engine type is valid
if engine not in cls.downloader_classes:
logger.error("No valid engine found")
return
return latest_version
# Get the appropriate downloader class based on the engine type
cls.downloader_classes[engine].download_engine(version, download_location=cls.engines_path,
system_os=system_os, cpu=cpu, timeout=300)
# --- Downloads ---
# Check that engine was properly downloaded
found_engine = cls.is_version_downloaded(engine, version, system_os, cpu)
def _downloadable_engines(self):
return [engine for engine in self.supported_engines() if hasattr(engine, "downloader") and engine.downloader()]
def _get_existing_download_task(self, engine_name, version, system_os=None, cpu=None):
for task in self.download_tasks:
task_parts = task.name.split('-')
task_engine, task_version, task_system_os, task_cpu = task_parts[:4]
if engine_name == task_engine and version == task_version:
if system_os in (task_system_os, None) and cpu in (task_cpu, None):
return task
return None
def _download_engine(self, engine_name, version, system_os=None, cpu=None, background=False, ignore_system=False):
engine_to_download = self.engine_class_with_name(engine_name)
existing_task = self.get_existing_download_task(engine_name, version, system_os, cpu)
if existing_task:
logger.debug(f"Already downloading {engine_name} {version}")
if not background:
existing_task.join()
return None
elif not engine_to_download.downloader():
logger.warning("No valid downloader for this engine. Please update this software manually.")
return None
elif not self.engines_path:
raise FileNotFoundError("Engines path must be set before requesting downloads")
thread = EngineDownloadWorker(engine_name, version, system_os, cpu)
self.download_tasks.append(thread)
thread.start()
if background:
return thread
thread.join()
found_engine = self.is_version_installed(engine_name, version, system_os, cpu, ignore_system)
if not found_engine:
logger.error(f"Error downloading {engine}")
logger.error(f"Error downloading {engine_name}")
return found_engine
def _delete_engine_download(self, engine_name, version, system_os=None, cpu=None):
logger.info(f"Requested deletion of engine: {engine_name}-{version}")
found = self.is_version_installed(engine_name, version, system_os, cpu)
if found and found['type'] == 'managed':
root_dir_name = '-'.join([engine_name, version, found['system_os'], found['cpu']])
remove_path = os.path.join(found['path'].split(root_dir_name)[0], root_dir_name)
logger.info(f"Deleting engine at path: {remove_path}")
shutil.rmtree(remove_path, ignore_errors=False)
logger.info(f"Engine {engine_name}-{version}-{found['system_os']}-{found['cpu']} successfully deleted")
return True
elif found:
logger.error(f'Cannot delete requested {engine_name} {version}. Managed externally.')
else:
logger.error(f"Cannot find engine: {engine_name}-{version}")
return False
# --- Background Tasks ---
def _active_downloads(self) -> list:
return [x for x in self.download_tasks if x.is_alive()]
def _create_worker(self, engine_name: str, input_path: Path, output_path: Path, engine_version=None, args=None, parent=None, name=None):
worker_class = self.engine_class_with_name(engine_name).worker_class()
all_versions = self.all_version_data_for_engine(engine_name)
if not all_versions:
raise FileNotFoundError(f"Cannot find any installed '{engine_name}' engines")
engine_path = None
if engine_version and engine_version != 'latest':
for ver in all_versions:
if ver['version'] == engine_version:
engine_path = ver['path']
break
if not engine_path:
download_result = self.download_engine(engine_name, engine_version)
if not download_result:
raise FileNotFoundError(f"Cannot download requested version: {engine_name} {engine_version}")
engine_path = download_result['path']
logger.info("Engine downloaded. Creating worker.")
else:
logger.debug(f"Using latest engine version ({all_versions[0]['version']})")
engine_path = all_versions[0]['path']
if not engine_path:
raise FileNotFoundError(f"Cannot find requested engine version {engine_version}")
return worker_class(input_path=str(input_path), output_path=str(output_path), engine_path=engine_path, args=args,
parent=parent, name=name)
# --- Forwarders for backward compatibility ---
@classmethod
def delete_engine_download(cls, engine, version, system_os=None, cpu=None):
logger.info(f"Requested deletion of engine: {engine}-{version}")
found = cls.is_version_downloaded(engine, version, system_os, cpu)
if found:
dir_path = os.path.dirname(found['path'])
shutil.rmtree(dir_path, ignore_errors=True)
logger.info(f"Engine {engine}-{version}-{found['system_os']}-{found['cpu']} successfully deleted")
return True
else:
logger.error(f"Cannot find engine: {engine}-{version}")
def engine_class_for_project_path(cls, path):
if cls._default_instance is not None:
return cls._default_instance._engine_class_for_project_path(path)
@classmethod
def engine_class_with_name(cls, engine_name):
if cls._default_instance is not None:
return cls._default_instance._engine_class_with_name(engine_name)
@classmethod
def get_latest_engine_instance(cls, engine_class):
if cls._default_instance is not None:
return cls._default_instance._get_latest_engine_instance(engine_class)
@classmethod
def get_installed_engine_data(cls, filter_name=None, include_corrupt=False, ignore_system=False):
if cls._default_instance is not None:
return cls._default_instance._get_installed_engine_data(filter_name, include_corrupt, ignore_system)
return []
@classmethod
def update_all_engines(cls):
def engine_update_task(engine, engine_downloader):
logger.debug(f"Checking for updates to {engine}")
latest_version = engine_downloader.find_most_recent_version()
if latest_version:
logger.debug(f"Latest version of {engine} available: {latest_version.get('version')}")
if not cls.is_version_downloaded(engine, latest_version.get('version')):
logger.info(f"Downloading {engine} ({latest_version['version']})")
cls.download_engine(engine=engine, version=latest_version['version'])
else:
logger.warning(f"Unable to get latest version for {engine}")
if cls._default_instance is not None:
cls._default_instance._update_all_engines()
logger.info(f"Checking for updates for render engines...")
threads = []
for engine, engine_downloader in cls.downloader_classes.items():
thread = threading.Thread(target=engine_update_task, args=(engine, engine_downloader))
threads.append(thread)
thread.start()
@classmethod
def all_version_data_for_engine(cls, engine_name, include_corrupt=False, ignore_system=False):
if cls._default_instance is not None:
return cls._default_instance._all_version_data_for_engine(engine_name, include_corrupt, ignore_system)
return []
@classmethod
def newest_installed_engine_data(cls, engine_name, system_os=None, cpu=None, ignore_system=None):
if cls._default_instance is not None:
return cls._default_instance._newest_installed_engine_data(engine_name, system_os, cpu, ignore_system)
return []
@classmethod
def is_version_installed(cls, engine_name, version, system_os=None, cpu=None, ignore_system=False):
if cls._default_instance is not None:
return cls._default_instance._is_version_installed(engine_name, version, system_os, cpu, ignore_system)
return False
@classmethod
def version_is_available_to_download(cls, engine_name, version, system_os=None, cpu=None):
if cls._default_instance is not None:
return cls._default_instance._version_is_available_to_download(engine_name, version, system_os, cpu)
return None
@classmethod
def find_most_recent_version(cls, engine_name, system_os=None, cpu=None, lts_only=False):
if cls._default_instance is not None:
return cls._default_instance._find_most_recent_version(engine_name, system_os, cpu, lts_only)
return {}
@classmethod
def is_engine_update_available(cls, engine_class, ignore_system_installs=False):
if cls._default_instance is not None:
return cls._default_instance._is_engine_update_available(engine_class, ignore_system_installs)
return None
@classmethod
def downloadable_engines(cls):
if cls._default_instance is not None:
return cls._default_instance._downloadable_engines()
return []
@classmethod
def get_existing_download_task(cls, engine_name, version, system_os=None, cpu=None):
if cls._default_instance is not None:
return cls._default_instance._get_existing_download_task(engine_name, version, system_os, cpu)
return None
@classmethod
def download_engine(cls, engine_name, version, system_os=None, cpu=None, background=False, ignore_system=False):
if cls._default_instance is not None:
return cls._default_instance._download_engine(engine_name, version, system_os, cpu, background, ignore_system)
return None
@classmethod
def delete_engine_download(cls, engine_name, version, system_os=None, cpu=None):
if cls._default_instance is not None:
return cls._default_instance._delete_engine_download(engine_name, version, system_os, cpu)
return False
@classmethod
def active_downloads(cls):
if cls._default_instance is not None:
return cls._default_instance._active_downloads()
return []
@classmethod
def create_worker(cls, engine_name, input_path, output_path, engine_version=None, args=None, parent=None, name=None):
if cls._default_instance is not None:
return cls._default_instance._create_worker(engine_name, input_path, output_path, engine_version, args, parent, name)
raise RuntimeError("EngineManager is not initialized")
class EngineDownloadWorker(threading.Thread):
def __init__(self, engine, version, system_os=None, cpu=None):
super().__init__()
self.engine = engine
self.version = version
self.system_os = system_os
self.cpu = cpu
self.percent_complete = 0
def _update_progress(self, current_progress):
self.percent_complete = current_progress
def run(self):
try:
existing_download = EngineManager.is_version_installed(self.engine, self.version, self.system_os, self.cpu,
ignore_system=True)
if existing_download:
logger.info(f"Requested download of {self.engine} {self.version}, but local copy already exists")
return existing_download
downloader = EngineManager.engine_class_with_name(self.engine).downloader()
downloader.download_engine(self.version, download_location=EngineManager.engines_path,
system_os=self.system_os, cpu=self.cpu, timeout=300, progress_callback=self._update_progress)
except Exception as e:
logger.error(f"Error in download worker: {e}")
finally:
try:
if EngineManager._default_instance is not None:
EngineManager._default_instance.download_tasks.remove(self)
except ValueError:
pass
for thread in threads: # wait to finish
thread.join()
if __name__ == '__main__':
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
# print(EngineManager.newest_engine_version('blender', 'macos', 'arm64'))
EngineManager.delete_engine_download('blender', '3.2.1', 'macos', 'a')
# EngineManager.delete_engine_download('blender', '3.2.1', 'macos', 'a')
EngineManager.engines_path = "/Users/brettwilliams/zordon-uploads/engines"
# print(EngineManager.is_version_downloaded("ffmpeg", "6.0"))
print(EngineManager.get_installed_engine_data())
+29 -25
View File
@@ -4,14 +4,16 @@ import re
import requests
from src.engines.core.downloader_core import download_and_extract_app
from src.engines.core.base_downloader import EngineDownloader
from src.engines.ffmpeg.ffmpeg_engine import FFMPEG
from src.utilities.misc_helper import current_system_cpu, current_system_os
logger = logging.getLogger()
supported_formats = ['.zip', '.tar.xz', '.dmg']
class FFMPEGDownloader:
class FFMPEGDownloader(EngineDownloader):
engine = FFMPEG
# macOS FFMPEG mirror maintained by Evermeet - https://evermeet.cx/ffmpeg/
macos_url = "https://evermeet.cx/pub/ffmpeg/"
@@ -87,16 +89,6 @@ class FFMPEGDownloader:
cls.version_cache['linux'] = releases
return releases
@classmethod
def find_most_recent_version(cls, system_os=None, cpu=None, lts_only=False):
try:
system_os = system_os or current_system_os()
cpu = cpu or current_system_cpu()
return cls.all_versions(system_os, cpu)[0]
except TypeError:
pass
return None
@classmethod
def all_versions(cls, system_os=None, cpu=None):
system_os = system_os or current_system_os()
@@ -105,7 +97,7 @@ class FFMPEGDownloader:
'windows': cls.__get_windows_versions}
if not versions_per_os.get(system_os):
logger.error(f"Cannot find version list for {system_os}")
return
return None
results = []
all_versions = versions_per_os[system_os]()
@@ -115,13 +107,6 @@ class FFMPEGDownloader:
'version': version})
return results
@classmethod
def version_is_available_to_download(cls, version, system_os=None, cpu=None):
for ver in cls.all_versions(system_os, cpu):
if ver['version'] == version:
return ver
return None
@classmethod
def __get_remote_url_for_version(cls, version, system_os, cpu):
# Platform specific naming cleanup
@@ -142,7 +127,24 @@ class FFMPEGDownloader:
return remote_url
@classmethod
def download_engine(cls, version, download_location, system_os=None, cpu=None, timeout=120):
def find_most_recent_version(cls, system_os=None, cpu=None, lts_only=False):
try:
system_os = system_os or current_system_os()
cpu = cpu or current_system_cpu()
return cls.all_versions(system_os, cpu)[0]
except (IndexError, requests.exceptions.RequestException) as e:
logger.error(f"Cannot get most recent version of ffmpeg: {e}")
return {}
@classmethod
def version_is_available_to_download(cls, version, system_os=None, cpu=None):
for ver in cls.all_versions(system_os, cpu):
if ver['version'] == version:
return ver
return None
@classmethod
def download_engine(cls, version, download_location, system_os=None, cpu=None, timeout=120, progress_callback=None):
system_os = system_os or current_system_os()
cpu = cpu or current_system_cpu()
@@ -150,7 +152,7 @@ class FFMPEGDownloader:
found_version = [item for item in cls.all_versions(system_os, cpu) if item['version'] == version]
if not found_version:
logger.error(f"Cannot find FFMPEG version {version} for {system_os} and {cpu}")
return
return None
# Platform specific naming cleanup
remote_url = cls.__get_remote_url_for_version(version=version, system_os=system_os, cpu=cpu)
@@ -160,7 +162,8 @@ class FFMPEGDownloader:
# Download and extract
try:
logger.info(f"Requesting download of ffmpeg-{version}-{system_os}-{cpu}")
download_and_extract_app(remote_url=remote_url, download_location=download_location, timeout=timeout)
cls.download_and_extract_app(remote_url=remote_url, download_location=download_location, timeout=timeout,
progress_callback=progress_callback)
# naming cleanup to match existing naming convention
output_path = os.path.join(download_location, f'ffmpeg-{version}-{system_os}-{cpu}')
@@ -180,4 +183,5 @@ if __name__ == "__main__":
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
# print(FFMPEGDownloader.download_engine('6.0', '/Users/brett/zordon-uploads/engines/'))
# print(FFMPEGDownloader.find_most_recent_version(system_os='linux'))
print(FFMPEGDownloader.download_engine(version='6.0', download_location='/Users/brett/zordon-uploads/engines/', system_os='linux', cpu='x64'))
print(FFMPEGDownloader.download_engine(version='6.0', download_location='/Users/brett/zordon-uploads/engines/',
system_os='linux', cpu='x64'))
+92 -17
View File
@@ -1,28 +1,99 @@
import json
import os
import re
from src.engines.core.base_engine import *
_creationflags = subprocess.CREATE_NO_WINDOW if platform.system() == 'Windows' else 0
class FFMPEG(BaseRenderEngine):
binary_names = {'linux': 'ffmpeg', 'windows': 'ffmpeg.exe', 'macos': 'ffmpeg'}
@staticmethod
def downloader():
from src.engines.ffmpeg.ffmpeg_downloader import FFMPEGDownloader
return FFMPEGDownloader
@staticmethod
def worker_class():
from src.engines.ffmpeg.ffmpeg_worker import FFMPEGRenderWorker
return FFMPEGRenderWorker
def ui_options(self):
return []
def supported_extensions(self):
help_text = (subprocess.check_output([self.engine_path(), '-h', 'full'], stderr=subprocess.STDOUT,
creationflags=_creationflags).decode('utf-8'))
found = re.findall(r'extensions that .* is allowed to access \(default "(.*)"', help_text)
found_extensions = set()
for match in found:
found_extensions.update(match.split(','))
return list(found_extensions)
def version(self):
version = None
try:
ver_out = subprocess.check_output([self.renderer_path(), '-version'],
timeout=SUBPROCESS_TIMEOUT).decode('utf-8')
match = re.match(".*version\s*(\S+)\s*Copyright", ver_out)
ver_out = subprocess.check_output([self.engine_path(), '-version'], timeout=SUBPROCESS_TIMEOUT,
creationflags=_creationflags).decode('utf-8')
match = re.match(r".*version\s*([\w.*]+)\W*", ver_out)
if match:
version = match.groups()[0]
except Exception as e:
logger.error("Failed to get FFMPEG version: {}".format(e))
return version
def get_project_info(self, project_path, timeout=10):
"""Run ffprobe and parse the output as JSON"""
try:
# resolve ffprobe path
engine_dir = os.path.dirname(self.engine_path())
ffprobe_path = os.path.join(engine_dir, 'ffprobe')
if self.engine_path().endswith('.exe'):
ffprobe_path += '.exe'
if not os.path.exists(ffprobe_path): # fallback to system install (if available)
ffprobe_path = 'ffprobe'
# run ffprobe
cmd = [
ffprobe_path, '-v', 'quiet', '-print_format', 'json',
'-show_streams', '-select_streams', 'v', project_path
]
output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, text=True,
creationflags=_creationflags)
video_info = json.loads(output)
# Extract the necessary information
video_stream = video_info['streams'][0]
frame_rate = eval(video_stream['r_frame_rate'])
duration = float(video_stream['duration'])
width = video_stream['width']
height = video_stream['height']
# Calculate total frames (end frame)
total_frames = int(duration * frame_rate)
end_frame = total_frames - 1
# The start frame is typically 0
start_frame = 0
return {
'frame_start': start_frame,
'frame_end': end_frame,
'fps': frame_rate,
'resolution_x': width,
'resolution_y': height
}
except Exception as e:
print(f"Failed to get FFMPEG project info: {e}")
return None
def get_encoders(self):
raw_stdout = subprocess.check_output([self.renderer_path(), '-encoders'], stderr=subprocess.DEVNULL,
timeout=SUBPROCESS_TIMEOUT).decode('utf-8')
pattern = '(?P<type>[VASFXBD.]{6})\s+(?P<name>\S{2,})\s+(?P<description>.*)'
raw_stdout = subprocess.check_output([self.engine_path(), '-encoders'], stderr=subprocess.DEVNULL,
timeout=SUBPROCESS_TIMEOUT, creationflags=_creationflags).decode('utf-8')
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)]
return encoders
@@ -32,9 +103,10 @@ class FFMPEG(BaseRenderEngine):
def get_all_formats(self):
try:
formats_raw = subprocess.check_output([self.renderer_path(), '-formats'], stderr=subprocess.DEVNULL,
timeout=SUBPROCESS_TIMEOUT).decode('utf-8')
pattern = '(?P<type>[DE]{1,2})\s+(?P<id>\S{2,})\s+(?P<name>.*)\r'
formats_raw = subprocess.check_output([self.engine_path(), '-formats'], stderr=subprocess.DEVNULL,
timeout=SUBPROCESS_TIMEOUT,
creationflags=_creationflags).decode('utf-8')
pattern = r'(?P<type>[DE]{1,2})\s+(?P<id>\S{2,})\s+(?P<name>.*)'
all_formats = [m.groupdict() for m in re.finditer(pattern, formats_raw)]
return all_formats
except Exception as e:
@@ -45,7 +117,8 @@ class FFMPEG(BaseRenderEngine):
# Extract the common extension using regex
muxer_flag = 'muxer' if 'E' in ffmpeg_format['type'] else 'demuxer'
format_detail_raw = subprocess.check_output(
[self.renderer_path(), '-hide_banner', '-h', f"{muxer_flag}={ffmpeg_format['id']}"]).decode('utf-8')
[self.engine_path(), '-hide_banner', '-h', f"{muxer_flag}={ffmpeg_format['id']}"],
creationflags=_creationflags).decode('utf-8')
pattern = r"Common extensions: (\w+)"
common_extensions = re.findall(pattern, format_detail_raw)
found_extensions = []
@@ -54,19 +127,21 @@ class FFMPEG(BaseRenderEngine):
return found_extensions
def get_output_formats(self):
return [x for x in self.get_all_formats() if 'E' in x['type'].upper()]
return [x['id'] for x in self.get_all_formats() if 'E' in x['type'].upper()]
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',
'-f', 'null', '-'], stderr=subprocess.STDOUT,
timeout=SUBPROCESS_TIMEOUT).decode('utf-8')
raw_stdout = subprocess.check_output([self.engine_path(), '-i', path_to_file, '-map', '0:v:0', '-c', 'copy',
'-f', 'null', '-'], stderr=subprocess.STDOUT,
timeout=SUBPROCESS_TIMEOUT, creationflags=_creationflags).decode('utf-8')
match = re.findall(r'frame=\s*(\d+)', raw_stdout)
if match:
frame_number = int(match[-1])
return frame_number
return -1
def get_arguments(self):
help_text = subprocess.check_output([self.renderer_path(), '-h', 'long'], stderr=subprocess.STDOUT).decode('utf-8')
help_text = (subprocess.check_output([self.engine_path(), '-h', 'long'], stderr=subprocess.STDOUT,
creationflags=_creationflags).decode('utf-8'))
lines = help_text.splitlines()
options = {}
@@ -93,4 +168,4 @@ class FFMPEG(BaseRenderEngine):
if __name__ == "__main__":
print(FFMPEG().get_all_formats())
print(FFMPEG().get_all_formats())
+7 -14
View File
@@ -1,6 +1,5 @@
#!/usr/bin/env python3
import re
import subprocess
from src.engines.core.base_worker import BaseRenderWorker
from src.engines.ffmpeg.ffmpeg_engine import FFMPEG
@@ -10,24 +9,18 @@ class FFMPEGRenderWorker(BaseRenderWorker):
engine = FFMPEG
def __init__(self, input_path, output_path, args=None, parent=None, name=None):
super(FFMPEGRenderWorker, self).__init__(input_path=input_path, output_path=output_path, args=args,
parent=parent, name=name)
stream_info = subprocess.check_output([self.renderer_path, "-i", # https://stackoverflow.com/a/61604105
input_path, "-map", "0:v:0", "-c", "copy", "-f", "null", "-y",
"/dev/null"], stderr=subprocess.STDOUT).decode('utf-8')
found_frames = re.findall('frame=\s*(\d+)', stream_info)
self.project_length = found_frames[-1] if found_frames else '-1'
def __init__(self, input_path, output_path, engine_path, args=None, parent=None, name=None):
super(FFMPEGRenderWorker, self).__init__(input_path=input_path, output_path=output_path,
engine_path=engine_path, args=args, parent=parent, name=name)
self.current_frame = -1
def generate_worker_subprocess(self):
cmd = [self.engine.default_renderer_path(), '-y', '-stats', '-i', self.input_path]
cmd = [self.engine_path, '-y', '-stats', '-i', self.input_path]
# Resize frame
if self.args.get('x_resolution', None) and self.args.get('y_resolution', None):
cmd.extend(['-vf', f"scale={self.args['x_resolution']}:{self.args['y_resolution']}"])
if self.args.get('resolution', None):
cmd.extend(['-vf', f"scale={self.args['resolution'][0]}:{self.args['resolution'][1]}"])
# Convert raw args from string if available
raw_args = self.args.get('raw', None)
@@ -35,7 +28,7 @@ class FFMPEGRenderWorker(BaseRenderWorker):
cmd.extend(raw_args.split(' '))
# Close with output path
cmd.append(self.output_path)
cmd.extend(['-max_muxing_queue_size', '1024', self.output_path])
return cmd
def percent_complete(self):
+245 -103
View File
@@ -1,157 +1,299 @@
import logging
import threading
from collections import Counter
from datetime import datetime
from pathlib import Path
from typing import Any, Dict, List, Optional
from pubsub import pub
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.orm import Session, sessionmaker
from sqlalchemy.orm.exc import DetachedInstanceError
from src.engines.core.base_worker import Base, BaseRenderWorker
from src.utilities.status_utils import RenderStatus
from src.engines.engine_manager import EngineManager
from src.engines.core.base_worker import Base
logger = logging.getLogger()
class JobNotFoundError(Exception):
def __init__(self, job_id, *args):
def __init__(self, job_id: str, *args: Any) -> None:
super().__init__(args)
self.job_id = job_id
def __str__(self) -> str:
return f"Cannot find job with ID: {self.job_id}"
class RenderQueue:
engine = create_engine('sqlite:///database.db')
Base.metadata.create_all(engine)
Session = sessionmaker(bind=engine)
session = Session()
job_queue = []
maximum_renderer_instances = {'blender': 1, 'aerender': 1, 'ffmpeg': 4}
last_saved_counts = {}
def __init__(self):
pass
_default_instance: Optional['RenderQueue'] = None
@classmethod
def start_queue(cls):
cls.load_state()
def _sync_class(cls) -> None:
if cls._default_instance is not None:
pass # no class-level attributes to sync
@classmethod
def add_to_render_queue(cls, render_job, force_start=False):
logger.debug('Adding priority {} job to render queue: {}'.format(render_job.priority, render_job))
cls.job_queue.append(render_job)
if force_start:
cls.start_job(render_job)
cls.session.add(render_job)
cls.save_state()
def __init__(self) -> None:
self.engine: Optional[create_engine] = None
self.session: Optional[Session] = None
self.job_queue: List[BaseRenderWorker] = []
self.maximum_renderer_instances: Dict[str, int] = {'blender': 1, 'aerender': 1, 'ffmpeg': 4}
self.last_saved_counts: Dict[str, int] = {}
self.is_running: bool = False
self._lock = threading.Lock()
@classmethod
def all_jobs(cls):
return cls.job_queue
# --------------------------------------------
# Render Queue Evaluation:
# --------------------------------------------
@classmethod
def running_jobs(cls):
return cls.jobs_with_status(RenderStatus.RUNNING)
def _start(self) -> None:
logger.debug("Starting render queue updates")
self.is_running = True
self.evaluate_queue()
@classmethod
def pending_jobs(cls):
pending_jobs = cls.jobs_with_status(RenderStatus.NOT_STARTED)
pending_jobs.extend(cls.jobs_with_status(RenderStatus.SCHEDULED))
return pending_jobs
def _evaluate_queue(self) -> None:
try:
not_started = self.jobs_with_status(RenderStatus.NOT_STARTED, priority_sorted=True)
for job in not_started:
if self.is_available_for_job(job.engine_name, job.priority):
self.start_job(job)
@classmethod
def jobs_with_status(cls, status, priority_sorted=False):
found_jobs = [x for x in cls.all_jobs() if x.status == status]
scheduled = self.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}")
self.start_job(job)
if self.last_saved_counts != self.job_counts():
self.save_state()
except DetachedInstanceError:
pass
def _local_job_status_changed(self, job_id: str, old_status: str, new_status: str) -> None:
render_job = self.job_with_id(job_id, none_ok=True)
if render_job and self.is_running:
logger.debug(f"RenderQueue detected job {job_id} has changed from {old_status} -> {new_status}")
self.evaluate_queue()
def _stop(self) -> None:
logger.debug("Stopping render queue updates")
self.is_running = False
# --------------------------------------------
# Fetch Jobs:
# --------------------------------------------
def _all_jobs(self) -> List[BaseRenderWorker]:
return self.job_queue
def _running_jobs(self) -> List[BaseRenderWorker]:
return self.jobs_with_status(RenderStatus.RUNNING)
def _pending_jobs(self) -> List[BaseRenderWorker]:
pending = self.jobs_with_status(RenderStatus.NOT_STARTED)
pending.extend(self.jobs_with_status(RenderStatus.SCHEDULED))
return pending
def _jobs_with_status(self, status: RenderStatus, priority_sorted: bool = False) -> List[BaseRenderWorker]:
found_jobs = [x for x in self.all_jobs() if x.status == status]
if priority_sorted:
found_jobs = sorted(found_jobs, key=lambda a: a.priority, reverse=False)
return found_jobs
@classmethod
def job_with_id(cls, job_id, none_ok=False):
found_job = next((x for x in cls.all_jobs() if x.id == job_id), None)
def _job_with_id(self, job_id: str, none_ok: bool = False) -> Optional[BaseRenderWorker]:
found_job = next((x for x in self.all_jobs() if x.id == job_id), None)
if not found_job and not none_ok:
raise JobNotFoundError(job_id)
return found_job
@classmethod
def clear_history(cls):
to_remove = [x for x in cls.all_jobs() if x.status in [RenderStatus.CANCELLED,
RenderStatus.COMPLETED, RenderStatus.ERROR]]
for job_to_remove in to_remove:
cls.delete_job(job_to_remove)
cls.save_state()
def _job_counts(self) -> Dict[str, int]:
counts = Counter(x.status for x in self.all_jobs())
return {s.value: counts.get(s, 0) for s in RenderStatus}
@classmethod
def load_state(cls):
# --------------------------------------------
# Startup / Shutdown:
# --------------------------------------------
def _load_state(self, database_directory: Path) -> None:
self.engine = create_engine(f"sqlite:///{database_directory / 'database.db'}")
Base.metadata.create_all(self.engine)
self.session = sessionmaker(bind=self.engine)()
from src.engines.core.base_worker import BaseRenderWorker
cls.job_queue = cls.session.query(BaseRenderWorker).all()
self.job_queue = self.session.query(BaseRenderWorker).all()
pub.subscribe(self._local_job_status_changed, 'status_change')
@classmethod
def save_state(cls):
cls.session.commit()
def _save_state(self) -> None:
if self.session:
self.session.commit()
@classmethod
def prepare_for_shutdown(cls):
running_jobs = cls.jobs_with_status(RenderStatus.RUNNING) # cancel all running jobs
def _prepare_for_shutdown(self) -> None:
logger.debug("Closing session")
self.stop()
running_jobs = self.jobs_with_status(RenderStatus.RUNNING)
for job in running_jobs:
cls.cancel_job(job)
cls.save_state()
self.cancel_job(job)
self.save_state()
if self.session:
self.session.close()
@classmethod
def is_available_for_job(cls, renderer, priority=2):
# --------------------------------------------
# Renderer Availability:
# --------------------------------------------
if not EngineManager.all_versions_for_engine(renderer):
return False
def renderer_instances(self) -> Counter:
all_instances = [x.engine_name for x in self.running_jobs()]
return Counter(all_instances)
instances = cls.renderer_instances()
higher_priority_jobs = [x for x in cls.running_jobs() if x.priority < priority]
max_allowed_instances = cls.maximum_renderer_instances.get(renderer, 1)
maxed_out_instances = renderer in instances.keys() and instances[renderer] >= max_allowed_instances
def _is_available_for_job(self, renderer: str, priority: int = 2) -> bool:
instances = self.renderer_instances()
higher_priority_jobs = [x for x in self.running_jobs() if x.priority < priority]
max_allowed_instances = self.maximum_renderer_instances.get(renderer, 1)
maxed_out_instances = renderer in instances and instances[renderer] >= max_allowed_instances
return not maxed_out_instances and not higher_priority_jobs
@classmethod
def evaluate_queue(cls):
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)
# --------------------------------------------
# Job Lifecycle Management:
# --------------------------------------------
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)
def _add_to_render_queue(self, render_job: BaseRenderWorker, force_start: bool = False) -> None:
logger.info(f"Adding job to render queue: {render_job}")
with self._lock:
self.job_queue.append(render_job)
if force_start and render_job.status in (RenderStatus.NOT_STARTED, RenderStatus.SCHEDULED):
self.start_job(render_job)
self.session.add(render_job)
self.save_state()
if self.is_running:
self.evaluate_queue()
if cls.last_saved_counts != cls.job_counts():
cls.save_state()
@classmethod
def start_job(cls, job):
logger.info(f'Starting render: {job.name} - Priority {job.priority}')
def _start_job(self, job: BaseRenderWorker) -> None:
logger.info(f'Starting job: {job}')
job.start()
cls.save_state()
self.save_state()
@classmethod
def cancel_job(cls, job):
logger.info(f'Cancelling job ID: {job.id}')
def _cancel_job(self, job: BaseRenderWorker) -> bool:
logger.info(f'Cancelling job: {job}')
job.stop()
return job.status == RenderStatus.CANCELLED
@classmethod
def delete_job(cls, job):
logger.info(f"Deleting job ID: {job.id}")
job.stop()
cls.job_queue.remove(job)
cls.session.delete(job)
cls.save_state()
def _delete_job(self, job: BaseRenderWorker) -> bool:
logger.info(f"Deleting job: {job}")
with self._lock:
job.stop()
self.job_queue.remove(job)
self.session.delete(job)
self.save_state()
return True
# --------------------------------------------
# Miscellaneous:
# --------------------------------------------
def _clear_history(self) -> None:
for job in list(self.all_jobs()):
if job.status in (RenderStatus.CANCELLED, RenderStatus.COMPLETED, RenderStatus.ERROR):
self.delete_job(job)
self.save_state()
# --- Forwarders for backward compatibility ---
@classmethod
def renderer_instances(cls):
from collections import Counter
all_instances = [x.renderer for x in cls.running_jobs()]
return Counter(all_instances)
def start(cls):
if cls._default_instance is not None:
cls._default_instance._start()
@classmethod
def evaluate_queue(cls):
if cls._default_instance is not None:
cls._default_instance._evaluate_queue()
@classmethod
def stop(cls):
if cls._default_instance is not None:
cls._default_instance._stop()
@classmethod
def all_jobs(cls):
if cls._default_instance is not None:
return cls._default_instance.job_queue
return []
@classmethod
def running_jobs(cls):
if cls._default_instance is not None:
return cls._default_instance._running_jobs()
return []
@classmethod
def pending_jobs(cls):
if cls._default_instance is not None:
return cls._default_instance._pending_jobs()
return []
@classmethod
def jobs_with_status(cls, status, priority_sorted=False):
if cls._default_instance is not None:
return cls._default_instance._jobs_with_status(status, priority_sorted)
return []
@classmethod
def job_with_id(cls, job_id, none_ok=False):
if cls._default_instance is not None:
return cls._default_instance._job_with_id(job_id, none_ok)
if not none_ok:
raise JobNotFoundError(job_id)
return None
@classmethod
def job_counts(cls):
job_counts = {}
for job_status in RenderStatus:
job_counts[job_status.value] = len(cls.jobs_with_status(job_status))
return job_counts
if cls._default_instance is not None:
return cls._default_instance._job_counts()
return {}
@classmethod
def load_state(cls, database_directory):
if cls._default_instance is not None:
cls._default_instance._load_state(database_directory)
@classmethod
def save_state(cls):
if cls._default_instance is not None:
cls._default_instance._save_state()
@classmethod
def prepare_for_shutdown(cls):
if cls._default_instance is not None:
cls._default_instance._prepare_for_shutdown()
@classmethod
def is_available_for_job(cls, renderer, priority=2):
if cls._default_instance is not None:
return cls._default_instance._is_available_for_job(renderer, priority)
return True
@classmethod
def add_to_render_queue(cls, render_job, force_start=False):
if cls._default_instance is not None:
cls._default_instance._add_to_render_queue(render_job, force_start)
@classmethod
def start_job(cls, job):
if cls._default_instance is not None:
cls._default_instance._start_job(job)
@classmethod
def cancel_job(cls, job):
if cls._default_instance is not None:
return cls._default_instance._cancel_job(job)
return False
@classmethod
def delete_job(cls, job):
if cls._default_instance is not None:
return cls._default_instance._delete_job(job)
return False
@classmethod
def clear_history(cls):
if cls._default_instance is not None:
cls._default_instance._clear_history()
+74
View 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()
+690
View File
@@ -0,0 +1,690 @@
import logging
import socket
from pathlib import Path
import psutil
from PyQt6.QtCore import QThread, pyqtSignal, Qt, pyqtSlot
logger = logging.getLogger(__name__)
from PyQt6.QtWidgets import (
QApplication, QWidget, QVBoxLayout, QHBoxLayout, QLabel, QLineEdit, QPushButton, QFileDialog, QSpinBox, QComboBox,
QGroupBox, QCheckBox, QProgressBar, QPlainTextEdit, QDoubleSpinBox, QMessageBox, QListWidget, QListWidgetItem,
QTabWidget
)
from src.api.server_proxy import RenderServerProxy
from src.engines.engine_manager import EngineManager
from src.ui.engine_help_window import EngineHelpViewer
from src.utilities.misc_helper import COMMON_RESOLUTIONS, COMMON_FRAME_RATES
from src.utilities.zeroconf_server import ZeroconfServer
class NewRenderJobForm(QWidget):
def __init__(self, project_path=None):
super().__init__()
self.resolution_options_list = None
self.resolution_x_input = None
self.resolution_y_input = None
self.fps_options_list = None
self.fps_input = None
self.engine_group = None
self.notes_group = None
self.output_settings_group = None
self.project_path = project_path
# UI
self.project_group = None
self.load_file_group = None
self.current_engine_options = None
self.file_format_combo = None
self.engine_options_layout = None
self.cameras_list = None
self.cameras_group = None
self.engine_version_combo = None
self.worker_thread = None
self.msg_box = None
self.engine_help_viewer = None
self.raw_args = None
self.submit_progress_label = None
self.submit_progress = None
self.engine_type = None
self.process_label = None
self.process_progress_bar = None
self.splitjobs_same_os = None
self.enable_splitjobs = None
self.server_input = None
self.submit_button = None
self.notes_input = None
self.priority_input = None
self.end_frame_input = None
self.start_frame_input = None
self.job_name_input = None
self.scene_file_input = None
self.scene_file_browse_button = None
self.tabs = None
# Job / Server Data
self.server_proxy = RenderServerProxy(socket.gethostname())
self.project_info = None
self.installed_engines = []
self.preferred_engine = None
# Setup
self.setWindowTitle("New Job")
self.setup_ui()
self.setup_project()
self.show()
def setup_ui(self):
# Main widget layout
main_layout = QVBoxLayout(self)
# Tabs
self.tabs = QTabWidget()
# ==================== Loading Section (outside tabs) ====================
self.load_file_group = QGroupBox("Loading")
load_file_layout = QVBoxLayout(self.load_file_group)
progress_layout = QHBoxLayout()
self.process_label = QLabel("Processing")
self.process_progress_bar = QProgressBar()
self.process_progress_bar.setMinimum(0)
self.process_progress_bar.setMaximum(0) # Indeterminate
progress_layout.addWidget(self.process_label)
progress_layout.addWidget(self.process_progress_bar)
load_file_layout.addLayout(progress_layout)
# Scene File
job_overview_group = QGroupBox("Project File")
file_group_layout = QVBoxLayout(job_overview_group)
# Job Name
job_name_layout = QHBoxLayout()
job_name_layout.addWidget(QLabel("Job name:"))
self.job_name_input = QLineEdit()
job_name_layout.addWidget(self.job_name_input)
self.engine_type = QComboBox()
job_name_layout.addWidget(self.engine_type)
file_group_layout.addLayout(job_name_layout)
# Job File
scene_file_picker_layout = QHBoxLayout()
scene_file_picker_layout.addWidget(QLabel("File:"))
self.scene_file_input = QLineEdit()
self.scene_file_input.setText(self.project_path)
self.scene_file_browse_button = QPushButton("Browse...")
self.scene_file_browse_button.clicked.connect(self.browse_scene_file)
scene_file_picker_layout.addWidget(self.scene_file_input)
scene_file_picker_layout.addWidget(self.scene_file_browse_button)
file_group_layout.addLayout(scene_file_picker_layout)
main_layout.addWidget(job_overview_group)
main_layout.addWidget(self.load_file_group)
main_layout.addWidget(self.tabs)
# ==================== Tab 1: Job Settings ====================
self.project_group = QWidget()
project_layout = QVBoxLayout(self.project_group) # Fixed: proper parent
# Server / Hostname
server_list_layout = QHBoxLayout()
server_list_layout.addWidget(QLabel("Render Target:"))
self.server_input = QComboBox()
self.server_input.currentTextChanged.connect(self.server_changed)
server_list_layout.addWidget(self.server_input)
project_layout.addLayout(server_list_layout)
# Priority
priority_layout = QHBoxLayout()
priority_layout.addWidget(QLabel("Priority:"))
self.priority_input = QComboBox()
self.priority_input.addItems(["High", "Medium", "Low"])
self.priority_input.setCurrentIndex(1)
priority_layout.addWidget(self.priority_input)
project_layout.addLayout(priority_layout)
# Split Jobs Options
self.enable_splitjobs = QCheckBox("Automatically split render across multiple servers")
project_layout.addWidget(self.enable_splitjobs)
self.splitjobs_same_os = QCheckBox("Only render on same OS")
project_layout.addWidget(self.splitjobs_same_os)
project_layout.addStretch() # Push everything up
# ==================== Tab 2: Output Settings ====================
self.output_settings_group = QWidget()
output_settings_layout = QVBoxLayout(self.output_settings_group)
# File Format
format_group = QGroupBox("Format / Range")
output_settings_layout.addWidget(format_group)
format_group_layout = QVBoxLayout()
format_group.setLayout(format_group_layout)
file_format_layout = QHBoxLayout()
file_format_layout.addWidget(QLabel("Format:"))
self.file_format_combo = QComboBox()
self.file_format_combo.setFixedWidth(200)
file_format_layout.addWidget(self.file_format_combo)
file_format_layout.addStretch()
format_group_layout.addLayout(file_format_layout)
# Frame Range
frame_range_layout = QHBoxLayout()
frame_range_layout.addWidget(QLabel("Frames:"))
self.start_frame_input = QSpinBox()
self.start_frame_input.setRange(1, 99999)
self.start_frame_input.setFixedWidth(80)
self.end_frame_input = QSpinBox()
self.end_frame_input.setRange(1, 99999)
self.end_frame_input.setFixedWidth(80)
frame_range_layout.addWidget(self.start_frame_input)
frame_range_layout.addWidget(QLabel("to"))
frame_range_layout.addWidget(self.end_frame_input)
frame_range_layout.addStretch()
format_group_layout.addLayout(frame_range_layout)
# --- Resolution & FPS Group ---
resolution_group = QGroupBox("Resolution / Frame Rate")
output_settings_layout.addWidget(resolution_group)
resolution_group_layout = QVBoxLayout()
resolution_group.setLayout(resolution_group_layout)
# Resolution
resolution_layout = QHBoxLayout()
self.resolution_options_list = QComboBox()
self.resolution_options_list.setFixedWidth(200)
self.resolution_options_list.addItem("Original Size")
for res in COMMON_RESOLUTIONS:
self.resolution_options_list.addItem(res)
self.resolution_options_list.currentIndexChanged.connect(self._resolution_preset_changed)
resolution_layout.addWidget(self.resolution_options_list)
resolution_group_layout.addLayout(resolution_layout)
self.resolution_x_input = QSpinBox()
self.resolution_x_input.setRange(1, 9999)
self.resolution_x_input.setValue(1920)
self.resolution_x_input.setFixedWidth(80)
resolution_layout.addWidget(self.resolution_x_input)
self.resolution_y_input = QSpinBox()
self.resolution_y_input.setRange(1, 9999)
self.resolution_y_input.setValue(1080)
self.resolution_y_input.setFixedWidth(80)
resolution_layout.addWidget(QLabel("x"))
resolution_layout.addWidget(self.resolution_y_input)
resolution_layout.addStretch()
fps_layout = QHBoxLayout()
self.fps_options_list = QComboBox()
self.fps_options_list.setFixedWidth(200)
self.fps_options_list.addItem("Original FPS")
for fps_option in COMMON_FRAME_RATES:
self.fps_options_list.addItem(fps_option)
self.fps_options_list.currentIndexChanged.connect(self._fps_preset_changed)
fps_layout.addWidget(self.fps_options_list)
self.fps_input = QDoubleSpinBox()
self.fps_input.setDecimals(3)
self.fps_input.setRange(1.0, 999.0)
self.fps_input.setValue(23.976)
self.fps_input.setFixedWidth(80)
fps_layout.addWidget(self.fps_input)
fps_layout.addWidget(QLabel("fps"))
fps_layout.addStretch()
resolution_group_layout.addLayout(fps_layout)
output_settings_layout.addStretch()
# ==================== Tab 3: Engine Settings ====================
self.engine_group = QWidget()
engine_group_layout = QVBoxLayout(self.engine_group)
engine_layout = QHBoxLayout()
engine_layout.addWidget(QLabel("Engine Version:"))
self.engine_version_combo = QComboBox()
self.engine_version_combo.addItem('latest')
engine_layout.addWidget(self.engine_version_combo)
engine_group_layout.addLayout(engine_layout)
# Dynamic engine options
self.engine_options_layout = QVBoxLayout()
engine_group_layout.addLayout(self.engine_options_layout)
# Raw Args
raw_args_layout = QHBoxLayout()
raw_args_layout.addWidget(QLabel("Raw Args:"))
self.raw_args = QLineEdit()
raw_args_layout.addWidget(self.raw_args)
args_help_button = QPushButton("?")
args_help_button.clicked.connect(self.args_help_button_clicked)
raw_args_layout.addWidget(args_help_button)
engine_group_layout.addLayout(raw_args_layout)
engine_group_layout.addStretch()
# ==================== Tab 4: Cameras ====================
self.cameras_group = QWidget()
cameras_layout = QVBoxLayout(self.cameras_group)
self.cameras_list = QListWidget()
self.cameras_list.itemChanged.connect(self.update_job_count)
cameras_layout.addWidget(self.cameras_list)
# ==================== Tab 5: Misc / Notes ====================
self.notes_group = QWidget()
notes_layout = QVBoxLayout(self.notes_group)
self.notes_input = QPlainTextEdit()
notes_layout.addWidget(self.notes_input)
# == Create Tabs
self.tabs.addTab(self.project_group, "Job Settings")
self.tabs.addTab(self.output_settings_group, "Output Settings")
self.tabs.addTab(self.engine_group, "Engine Settings")
self.tabs.addTab(self.cameras_group, "Cameras")
self.tabs.addTab(self.notes_group, "Notes")
self.update_server_list()
index = self.tabs.indexOf(self.cameras_group)
if index != -1:
self.tabs.setTabEnabled(index, False)
# ==================== Submit Section (outside tabs) ====================
self.submit_button = QPushButton("Submit Job")
self.submit_button.clicked.connect(self.submit_job)
main_layout.addWidget(self.submit_button)
self.submit_progress = QProgressBar()
self.submit_progress.setMinimum(0)
self.submit_progress.setMaximum(0)
self.submit_progress.setHidden(True)
main_layout.addWidget(self.submit_progress)
self.submit_progress_label = QLabel("Submitting...")
self.submit_progress_label.setHidden(True)
main_layout.addWidget(self.submit_progress_label)
# Initial engine state
self.toggle_engine_enablement(False)
self.tabs.setCurrentIndex(0)
def update_job_count(self, changed_item=None):
checked = 1
if self.cameras_group.isEnabled():
checked = 0
total = self.cameras_list.count()
for i in range(total):
item = self.cameras_list.item(i)
if item.checkState() == Qt.CheckState.Checked:
checked += 1
message = f"Submit {checked} Jobs" if checked > 1 else "Submit Job"
self.submit_button.setText(message)
self.submit_button.setEnabled(bool(checked))
def _resolution_preset_changed(self, index):
selected_res = COMMON_RESOLUTIONS.get(self.resolution_options_list.currentText())
if selected_res:
self.resolution_x_input.setValue(selected_res[0])
self.resolution_y_input.setValue(selected_res[1])
elif index == 0:
self.resolution_x_input.setValue(self.project_info.get('resolution_x'))
self.resolution_y_input.setValue(self.project_info.get('resolution_y'))
def _fps_preset_changed(self, index):
selected_fps = COMMON_FRAME_RATES.get(self.fps_options_list.currentText())
if selected_fps:
self.fps_input.setValue(selected_fps)
elif index == 0:
self.fps_input.setValue(self.project_info.get('fps'))
def engine_changed(self):
# load the version numbers
current_engine = self.engine_type.currentText().lower() or self.engine_type.itemText(0)
self.engine_version_combo.clear()
self.engine_version_combo.addItem('latest')
self.file_format_combo.clear()
if current_engine:
engine_info = self.server_proxy.get_engine(current_engine, 'full', timeout=10)
self.current_engine_options = engine_info.get('options', [])
if not engine_info:
raise FileNotFoundError(f"Cannot get information about engine '{current_engine}'")
engine_vers = [v['version'] for v in engine_info['versions']]
self.engine_version_combo.addItems(engine_vers)
self.file_format_combo.addItems(engine_info.get('supported_export_formats'))
def server_changed(self, hostname):
if not hostname:
return
self.server_proxy = RenderServerProxy(hostname)
if self.engine_type and self.engine_type.count():
try:
self.engine_changed()
except Exception as e:
logger.error(f"Error updating engine data for server '{hostname}': {e}")
def update_server_list(self):
current_hostname = self.server_input.currentText()
clients = ZeroconfServer.found_hostnames()
self.server_input.clear()
self.server_input.addItems(clients)
if current_hostname and current_hostname in clients:
self.server_input.setCurrentText(current_hostname)
elif clients:
self.server_changed(clients[0])
def browse_scene_file(self):
file_name, _ = QFileDialog.getOpenFileName(self, "Select Scene File")
if file_name:
self.scene_file_input.setText(file_name)
self.setup_project()
def setup_project(self):
# UI stuff on main thread
self.process_progress_bar.setHidden(False)
self.process_label.setHidden(False)
self.toggle_engine_enablement(False)
output_name = Path(self.scene_file_input.text()).stem.replace(' ', '_')
self.job_name_input.setText(output_name)
file_name = self.scene_file_input.text()
# setup bg worker
self.worker_thread = GetProjectInfoWorker(window=self, project_path=file_name)
self.worker_thread.message_signal.connect(self.post_get_project_info_update)
self.worker_thread.error_signal.connect(self.show_error_message)
self.worker_thread.start()
def browse_output_path(self):
directory = QFileDialog.getExistingDirectory(self, "Select Output Directory")
if directory:
self.job_name_input.setText(directory)
def args_help_button_clicked(self):
url = (f'http://{self.server_proxy.hostname}:{self.server_proxy.port}/api/engines/'
f'{self.engine_type.currentText()}/help')
self.engine_help_viewer = EngineHelpViewer(url)
self.engine_help_viewer.show()
def show_error_message(self, message):
msg = QMessageBox(self)
msg.setIcon(QMessageBox.Icon.Critical)
msg.setWindowTitle("Error")
msg.setText(message)
msg.exec()
# -------- Update --------
def post_get_project_info_update(self):
"""Called by the GetProjectInfoWorker - Do not call directly."""
try:
self.engine_type.addItems(self.installed_engines)
self.engine_type.setCurrentText(self.preferred_engine)
self.engine_changed()
# Set the best engine we can find
input_path = self.scene_file_input.text()
engine = EngineManager.engine_class_for_project_path(input_path)
engine_index = self.engine_type.findText(engine.name().lower())
if engine_index >= 0:
self.engine_type.setCurrentIndex(engine_index)
else:
self.engine_type.setCurrentIndex(0) #todo: find out why we don't have engine info yet
# not ideal but if we don't have the engine info we have to pick something
# cleanup progress UI
self.load_file_group.setHidden(True)
self.toggle_engine_enablement(True)
# Load scene data
self.start_frame_input.setValue(self.project_info.get('frame_start'))
self.end_frame_input.setValue(self.project_info.get('frame_end'))
self.resolution_x_input.setValue(self.project_info.get('resolution_x'))
self.resolution_y_input.setValue(self.project_info.get('resolution_y'))
self.fps_input.setValue(self.project_info.get('fps'))
# Cameras
self.cameras_list.clear()
index = self.tabs.indexOf(self.cameras_group)
if self.project_info.get('cameras'):
self.tabs.setTabEnabled(index, True)
found_active = False
for camera in self.project_info['cameras']:
# create the list items and make them checkable
item = QListWidgetItem(f"{camera['name']} - {camera['lens']}mm")
item.setFlags(item.flags() | Qt.ItemFlag.ItemIsUserCheckable)
is_checked = camera['is_active'] or len(self.project_info['cameras']) == 1
found_active = found_active or is_checked
item.setCheckState(Qt.CheckState.Checked if is_checked else Qt.CheckState.Unchecked)
self.cameras_list.addItem(item)
if not found_active:
self.cameras_list.item(0).setCheckState(Qt.CheckState.Checked)
else:
self.tabs.setTabEnabled(index, False)
self.update_job_count()
# Dynamic Engine Options
clear_layout(self.engine_options_layout) # clear old options
# dynamically populate option list
for option in self.current_engine_options:
h_layout = QHBoxLayout()
label = QLabel(option['name'].replace('_', ' ').capitalize() + ':')
h_layout.addWidget(label)
if option.get('options'):
combo_box = QComboBox()
for opt in option['options']:
combo_box.addItem(opt)
h_layout.addWidget(combo_box)
else:
text_box = QLineEdit()
h_layout.addWidget(text_box)
self.engine_options_layout.addLayout(h_layout)
except AttributeError as e:
logger.error(f"AttributeError in post_get_project_info_update: {e}")
def toggle_engine_enablement(self, enabled=False):
"""Toggle on/off all the render settings"""
indexes = [self.tabs.indexOf(self.project_group),
self.tabs.indexOf(self.output_settings_group),
self.tabs.indexOf(self.engine_group),
self.tabs.indexOf(self.cameras_group),
self.tabs.indexOf(self.notes_group)]
for idx in indexes:
self.tabs.setTabEnabled(idx, enabled)
self.submit_button.setEnabled(enabled)
def after_job_submission(self, error_string):
# UI cleanup
self.submit_progress.setMaximum(0)
self.submit_button.setHidden(False)
self.submit_progress.setHidden(True)
self.submit_progress_label.setHidden(True)
self.process_progress_bar.setHidden(True)
self.process_label.setHidden(True)
self.toggle_engine_enablement(True)
self.msg_box = QMessageBox()
if not error_string:
self.msg_box.setStandardButtons(QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No)
self.msg_box.setIcon(QMessageBox.Icon.Information)
self.msg_box.setText("Job successfully submitted to server. Submit another?")
self.msg_box.setWindowTitle("Success")
x = self.msg_box.exec()
if x == QMessageBox.StandardButton.No:
self.close()
else:
self.msg_box.setStandardButtons(QMessageBox.StandardButton.Ok)
self.msg_box.setIcon(QMessageBox.Icon.Critical)
self.msg_box.setText(error_string)
self.msg_box.setWindowTitle("Error")
self.msg_box.exec()
# -------- Submit Job Calls --------
def submit_job(self):
# Pre-worker UI
self.submit_progress.setHidden(False)
self.submit_progress_label.setHidden(False)
self.submit_button.setHidden(True)
self.submit_progress.setMaximum(0)
# submit job in background thread
self.worker_thread = SubmitWorker(window=self)
self.worker_thread.update_ui_signal.connect(self.update_submit_progress)
self.worker_thread.message_signal.connect(self.after_job_submission)
self.worker_thread.start()
@pyqtSlot(str, str)
def update_submit_progress(self, hostname, percent):
# Update the UI here. This slot will be executed in the main thread
self.submit_progress_label.setText(f"Transferring to {hostname} - {percent}%")
self.submit_progress.setMaximum(100)
self.submit_progress.setValue(int(percent))
class SubmitWorker(QThread):
"""Worker class called to submit all the jobs to the server and update the UI accordingly"""
message_signal = pyqtSignal(str)
update_ui_signal = pyqtSignal(str, str)
def __init__(self, window):
super().__init__()
self.window = window
def run(self):
def create_callback(encoder):
encoder_len = encoder.len
def callback(monitor):
percent = f"{monitor.bytes_read / encoder_len * 100:.0f}"
self.update_ui_signal.emit(hostname, percent)
return callback
try:
hostname = self.window.server_input.currentText()
resolution = (self.window.resolution_x_input.text(), self.window.resolution_y_input.text())
job_json = {'owner': psutil.Process().username() + '@' + socket.gethostname(),
'engine_name': self.window.engine_type.currentText().lower(),
'engine_version': self.window.engine_version_combo.currentText(),
'args': {'raw': self.window.raw_args.text(),
'export_format': self.window.file_format_combo.currentText(),
'resolution': resolution,
'fps': self.window.fps_input.text(),},
'output_path': self.window.job_name_input.text(),
'start_frame': self.window.start_frame_input.value(),
'end_frame': self.window.end_frame_input.value(),
'priority': self.window.priority_input.currentIndex() + 1,
'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.job_name_input.text()}
# get the dynamic args
for i in range(self.window.engine_options_layout.count()):
item = self.window.engine_options_layout.itemAt(i)
layout = item.layout() # get the layout
for x in range(layout.count()):
z = layout.itemAt(x)
widget = z.widget()
if isinstance(widget, QComboBox):
job_json['args'][self.window.current_engine_options[i]['name']] = widget.currentText()
elif isinstance(widget, QLineEdit):
job_json['args'][self.window.current_engine_options[i]['name']] = widget.text()
# determine if any cameras are checked
selected_cameras = []
if self.window.cameras_list.count() and self.window.cameras_group.isEnabled():
for index in range(self.window.cameras_list.count()):
item = self.window.cameras_list.item(index)
if item.checkState() == Qt.CheckState.Checked:
selected_cameras.append(item.text().rsplit('-', 1)[0].strip()) # cleanup to just camera name
# process cameras into nested format
input_path = self.window.scene_file_input.text()
if selected_cameras and self.window.cameras_list.count() > 1:
children_jobs = []
for cam in selected_cameras:
child_job_data = dict()
child_job_data['args'] = dict(job_json['args'])
child_job_data['args']['camera'] = cam
child_job_data['name'] = job_json['name'].replace(' ', '-') + "_" + cam.replace(' ', '')
child_job_data['output_path'] = child_job_data['name']
children_jobs.append(child_job_data)
job_json['child_jobs'] = children_jobs
# presubmission tasks - use local installs
engine_class = EngineManager.engine_class_with_name(self.window.engine_type.currentText().lower())
latest_engine = EngineManager.get_latest_engine_instance(engine_class)
input_path = Path(latest_engine.perform_presubmission_tasks(input_path))
# submit
err_msg = ""
result = self.window.server_proxy.create_job(file_path=input_path, job_data=job_json,
callback=create_callback)
if not (result and result.ok):
err_msg = f"Error posting job to server: {result.text}"
self.message_signal.emit(err_msg)
except Exception as e:
self.message_signal.emit(str(e))
class GetProjectInfoWorker(QThread):
"""Worker class called to retrieve information about a project file on a background thread and update the UI"""
message_signal = pyqtSignal()
error_signal = pyqtSignal(str)
def __init__(self, window, project_path):
super().__init__()
self.window = window
self.project_path = project_path
def run(self):
try:
# get the engine info and add them all to the ui
self.window.installed_engines = self.window.server_proxy.get_engine_names()
# select the best engine for the file type
self.window.preferred_engine = self.window.server_proxy.get_engine_for_filename(self.project_path)
# this should be the only time we use a local engine instead of using the proxy besides submitting
engine_class = EngineManager.engine_class_for_project_path(self.project_path)
engine = EngineManager.get_latest_engine_instance(engine_class)
self.window.project_info = engine.get_project_info(self.project_path)
self.message_signal.emit()
except Exception as e:
self.error_signal.emit(str(e))
def clear_layout(layout):
if layout is not None:
# Go through the layout's items in reverse order
for i in reversed(range(layout.count())):
# Take the item at the current position
item = layout.takeAt(i)
# Check if the item is a widget
if item.widget():
# Remove the widget and delete it
widget_to_remove = item.widget()
widget_to_remove.setParent(None)
widget_to_remove.deleteLater()
elif item.layout():
# If the item is a sub-layout, clear its contents recursively
clear_layout(item.layout())
# Then delete the layout
item.layout().deleteLater()
# Run the application
if __name__ == '__main__':
app = QApplication([])
window = NewRenderJobForm()
app.exec()
+62
View File
@@ -0,0 +1,62 @@
import logging
from PyQt6.QtGui import QFont
from PyQt6.QtWidgets import QMainWindow, QVBoxLayout, QWidget, QPlainTextEdit
from PyQt6.QtCore import pyqtSignal, QObject
# Create a custom logging handler that emits a signal
class QSignalHandler(logging.Handler, QObject):
new_record = pyqtSignal(str)
def __init__(self):
logging.Handler.__init__(self)
QObject.__init__(self)
def emit(self, record):
msg = self.format(record)
try:
self.new_record.emit(msg) # Emit signal
except RuntimeError:
pass
class ConsoleWindow(QMainWindow):
def __init__(self, buffer_handler):
super().__init__()
self.buffer_handler = buffer_handler
self.log_handler = None
self.init_ui()
self.init_logging()
def init_ui(self):
self.setGeometry(100, 100, 600, 800)
self.setWindowTitle("Log Output")
self.text_edit = QPlainTextEdit(self)
self.text_edit.setReadOnly(True)
self.text_edit.setFont(QFont("Courier", 10))
layout = QVBoxLayout()
layout.addWidget(self.text_edit)
layout.setContentsMargins(0, 0, 0, 0)
central_widget = QWidget()
central_widget.setLayout(layout)
self.setCentralWidget(central_widget)
def init_logging(self):
self.buffer_handler.new_record.connect(self.append_log_record)
# Display all messages that were buffered before the window was opened
for record in self.buffer_handler.get_buffer():
self.text_edit.appendPlainText(record)
self.log_handler = QSignalHandler()
# self.log_handler.new_record.connect(self.append_log_record)
self.log_handler.setFormatter(self.buffer_handler.formatter)
logging.getLogger().addHandler(self.log_handler)
logging.getLogger().setLevel(logging.INFO)
def append_log_record(self, record):
self.text_edit.appendPlainText(record)
+169
View File
@@ -0,0 +1,169 @@
import os
import socket
import subprocess
import sys
import threading
from PyQt6.QtCore import QTimer
from PyQt6.QtWidgets import (
QMainWindow, QWidget, QVBoxLayout, QPushButton, QTableWidget, QTableWidgetItem, QHBoxLayout, QAbstractItemView,
QHeaderView, QProgressBar, QLabel, QMessageBox
)
from src.api.server_proxy import RenderServerProxy
from src.engines.engine_manager import EngineManager
from src.utilities.misc_helper import is_localhost, launch_url
class EngineBrowserWindow(QMainWindow):
def __init__(self, hostname=None):
super().__init__()
self.delete_button = None
self.install_button = None
self.progress_label = None
self.progress_bar = None
self.table_widget = None
self.launch_button = None
self.hostname = hostname or socket.gethostname()
self.setWindowTitle(f'Engine Browser ({self.hostname})')
self.setGeometry(100, 100, 500, 300)
self.engine_data = []
self.initUI()
self.init_timer()
def initUI(self):
# Central widget
central_widget = QWidget()
self.setCentralWidget(central_widget)
# Layout
layout = QVBoxLayout(central_widget)
# Table
self.table_widget = QTableWidget(0, 4)
self.table_widget.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows)
self.table_widget.verticalHeader().setVisible(False)
self.table_widget.itemSelectionChanged.connect(self.engine_picked)
self.table_widget.setEditTriggers(QAbstractItemView.EditTrigger.NoEditTriggers)
layout.addWidget(self.table_widget)
self.update_table()
# Progress Bar Layout
self.progress_bar = QProgressBar()
self.progress_bar.setMinimum(0)
self.progress_bar.setMaximum(0)
# self.progress_bar.setHidden(True)
layout.addWidget(self.progress_bar)
# Progress Bar Label
self.progress_label = QLabel('Downloading blah blah')
layout.addWidget(self.progress_label)
# Buttons Layout
buttons_layout = QHBoxLayout()
# Install Button
self.install_button = QPushButton('Install')
self.install_button.clicked.connect(self.install_button_click) # Connect to slot
# buttons_layout.addWidget(self.install_button)
# Launch Button
self.launch_button = QPushButton('Launch')
self.launch_button.clicked.connect(self.launch_button_click) # Connect to slot
self.launch_button.setEnabled(False)
buttons_layout.addWidget(self.launch_button)
#Delete Button
self.delete_button = QPushButton('Delete')
self.delete_button.clicked.connect(self.delete_button_click) # Connect to slot
self.delete_button.setEnabled(False)
buttons_layout.addWidget(self.delete_button)
# Add Buttons Layout to the Main Layout
layout.addLayout(buttons_layout)
self.update_download_status()
def init_timer(self):
# Set up the timer
self.timer = QTimer(self)
self.timer.timeout.connect(self.update_download_status)
self.timer.start(1000)
def update_table(self):
def update_table_worker():
raw_server_data = RenderServerProxy(self.hostname).get_engines()
if not raw_server_data:
return
table_data = [] # convert the data into a flat list
for _, engine_data in raw_server_data.items():
table_data.extend(engine_data['versions'])
self.engine_data = table_data
self.table_widget.setRowCount(len(self.engine_data))
self.table_widget.setColumnCount(4)
for row, engine in enumerate(self.engine_data):
self.table_widget.setItem(row, 0, QTableWidgetItem(engine['engine']))
self.table_widget.setItem(row, 1, QTableWidgetItem(engine['version']))
self.table_widget.setItem(row, 2, QTableWidgetItem(engine['type']))
self.table_widget.setItem(row, 3, QTableWidgetItem(engine['path']))
self.table_widget.selectRow(0)
self.table_widget.clear()
self.table_widget.setHorizontalHeaderLabels(['Engine', 'Version', 'Type', 'Path'])
self.table_widget.horizontalHeader().setSectionResizeMode(0, QHeaderView.ResizeMode.Fixed)
self.table_widget.horizontalHeader().setSectionResizeMode(1, QHeaderView.ResizeMode.Fixed)
self.table_widget.horizontalHeader().setSectionResizeMode(2, QHeaderView.ResizeMode.Fixed)
self.table_widget.horizontalHeader().setSectionResizeMode(3, QHeaderView.ResizeMode.Stretch)
update_thread = threading.Thread(target=update_table_worker,)
update_thread.start()
def engine_picked(self):
engine_info = self.engine_data[self.table_widget.currentRow()]
self.delete_button.setEnabled(engine_info['type'] == 'managed')
self.launch_button.setEnabled(is_localhost(self.hostname))
def update_download_status(self):
running_tasks = EngineManager.active_downloads()
hide_progress = not bool(running_tasks)
self.progress_bar.setHidden(hide_progress)
self.progress_label.setHidden(hide_progress)
# Update the status labels
if len(running_tasks) == 0:
new_status = ""
elif len(running_tasks) == 1:
task = running_tasks[0]
new_status = f"Downloading {task.engine.capitalize()} {task.version}..."
else:
new_status = f"Downloading {len(running_tasks)} engines..."
self.progress_label.setText(new_status)
def launch_button_click(self):
engine_info = self.engine_data[self.table_widget.currentRow()]
launch_url(engine_info['path'])
def install_button_click(self):
self.update_download_status()
def delete_button_click(self):
engine_info = self.engine_data[self.table_widget.currentRow()]
reply = QMessageBox.question(self, f"Delete {engine_info['engine']} {engine_info['version']}?",
f"Do you want to delete {engine_info['engine']} {engine_info['version']}?",
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No)
if reply is not QMessageBox.StandardButton.Yes:
return
result = RenderServerProxy(self.hostname).delete_engine_download(
engine_info['engine'], engine_info['version'], engine_info.get('system_os'), engine_info.get('cpu'),
)
if result.ok:
self.update_table()
else:
QMessageBox.warning(self, f"Delete {engine_info['engine']} {engine_info['version']} Failed",
f"Failed to delete {engine_info['engine']} {engine_info['version']}.",
QMessageBox.StandardButton.Ok)
+30
View File
@@ -0,0 +1,30 @@
import requests
from PyQt6.QtGui import QFont
from PyQt6.QtWidgets import QMainWindow, QVBoxLayout, QWidget, QPlainTextEdit
class EngineHelpViewer(QMainWindow):
def __init__(self, log_path):
super().__init__()
self.help_path = log_path
self.setGeometry(100, 100, 600, 800)
self.setWindowTitle("Help Output")
self.text_edit = QPlainTextEdit(self)
self.text_edit.setReadOnly(True)
self.text_edit.setFont(QFont("Courier", 10))
layout = QVBoxLayout()
layout.addWidget(self.text_edit)
layout.setContentsMargins(0, 0, 0, 0)
central_widget = QWidget()
central_widget.setLayout(layout)
self.setCentralWidget(central_widget)
self.fetch_help()
def fetch_help(self):
result = requests.get(self.help_path, timeout=10)
self.text_edit.setPlainText(result.text)
+30
View File
@@ -0,0 +1,30 @@
import requests
from PyQt6.QtGui import QFont
from PyQt6.QtWidgets import QMainWindow, QVBoxLayout, QWidget, QPlainTextEdit
class LogViewer(QMainWindow):
def __init__(self, log_path):
super().__init__()
self.log_path = log_path
self.setGeometry(100, 100, 600, 800)
self.setWindowTitle("Log Output")
self.text_edit = QPlainTextEdit(self)
self.text_edit.setReadOnly(True)
self.text_edit.setFont(QFont("Courier", 10))
layout = QVBoxLayout()
layout.addWidget(self.text_edit)
layout.setContentsMargins(0, 0, 0, 0)
central_widget = QWidget()
central_widget.setLayout(layout)
self.setCentralWidget(central_widget)
self.fetch_logs()
def fetch_logs(self):
result = requests.get(self.log_path, timeout=10)
self.text_edit.setPlainText(result.text)
+693
View File
@@ -0,0 +1,693 @@
''' app/ui/main_window.py '''
import ast
import datetime
import io
import logging
import os
import sys
import threading
import time
from typing import List, Dict, Any, Optional
import PIL
import humanize
from PIL import Image
from PyQt6.QtCore import Qt, QByteArray, QBuffer, QIODevice, QThread, pyqtSignal
from PyQt6.QtGui import QPixmap, QImage, QFont, QIcon
from PyQt6.QtWidgets import QMainWindow, QWidget, QHBoxLayout, QListWidget, QTableWidget, QAbstractItemView, \
QTableWidgetItem, QLabel, QVBoxLayout, QHeaderView, QMessageBox, QGroupBox, QPushButton, QListWidgetItem, \
QFileDialog
from src.api.api_server import API_VERSION
from src.api.serverproxy_manager import ServerProxyManager
from src.render_queue import RenderQueue
from src.ui.add_job_window import NewRenderJobForm
from src.ui.console_window import ConsoleWindow
from src.ui.engine_browser import EngineBrowserWindow
from src.ui.log_window import LogViewer
from src.ui.widgets.menubar import MenuBar
from src.ui.widgets.proportional_image_label import ProportionalImageLabel
from src.ui.widgets.statusbar import StatusBar
from src.ui.widgets.toolbar import ToolBar
from src.utilities.misc_helper import get_time_elapsed, resources_dir, is_localhost
from src.utilities.misc_helper import launch_url
from src.utilities.status_utils import RenderStatus
from src.utilities.zeroconf_server import ZeroconfServer
from src.version import APP_NAME
logger = logging.getLogger()
class MainWindow(QMainWindow):
"""
MainWindow
Args:
QMainWindow (QMainWindow): Inheritance
"""
def __init__(self) -> None:
"""
Initialize the Main-Window.
"""
super().__init__()
# Load the queue
self.job_list_view: Optional[QTableWidget] = None
self.server_info_ram: Optional[str] = None
self.server_info_cpu: Optional[str] = None
self.server_info_os: Optional[str] = None
self.server_info_gpu: Optional[List[Dict[str, Any]]] = None
self.server_info_hostname: Optional[str] = None
self.engine_browser_window = None
self.server_info_group = None
self.current_hostname = None
self.subprocess_runner = None
# To pass to console
self.buffer_handler = None
# Window-Settings
self.setWindowTitle(APP_NAME)
self.setGeometry(100, 100, 900, 800)
central_widget = QWidget(self)
self.setCentralWidget(central_widget)
main_layout = QHBoxLayout(central_widget)
# Create a QLabel widget to display the image
self.image_label = ProportionalImageLabel()
self.image_label.setMaximumSize(700, 500)
self.image_label.setFixedHeight(300)
self.image_label.setAlignment(Qt.AlignmentFlag.AlignTop | Qt.AlignmentFlag.AlignHCenter)
self.load_image_path(os.path.join(resources_dir(), 'Rectangle.png'))
# Server list
self.server_list_view = QListWidget()
self.server_list_view.itemClicked.connect(self.server_picked)
list_font = QFont()
list_font.setPointSize(16)
self.server_list_view.setFont(list_font)
self.added_hostnames = []
self.setup_ui(main_layout)
# Add Widgets to Window
# self.custom_menu_bar =
self.setMenuBar(MenuBar(self))
self.setStatusBar(StatusBar(self))
self.create_toolbars()
# start background update
self.found_servers = []
self.job_data = {}
self.bg_update_thread = BackgroundUpdater(window=self)
self.bg_update_thread.updated_signal.connect(self.update_ui_data)
self.bg_update_thread.start()
# Setup other windows
self.new_job_window = None
self.console_window = None
self.log_viewer_window = None
# Pick default job
self.job_picked()
def setup_ui(self, main_layout: QVBoxLayout) -> None:
"""Setup the main user interface layout.
Args:
main_layout: The main layout container for the UI widgets.
"""
# Servers
server_list_group = QGroupBox("Available Servers")
list_layout = QVBoxLayout()
list_layout.addWidget(self.server_list_view)
list_layout.setContentsMargins(0, 0, 0, 0)
server_list_group.setLayout(list_layout)
server_info_group = QGroupBox("Server Info")
# Server Info Group
self.server_info_hostname = QLabel()
self.server_info_os = QLabel()
self.server_info_cpu = QLabel()
self.server_info_ram = QLabel()
self.server_info_gpu = QLabel()
server_info_engines_button = QPushButton("Render Engines")
server_info_engines_button.clicked.connect(self.engine_browser)
server_info_layout = QVBoxLayout()
server_info_layout.addWidget(self.server_info_hostname)
server_info_layout.addWidget(self.server_info_os)
server_info_layout.addWidget(self.server_info_cpu)
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_group.setLayout(server_info_layout)
# Server Button Layout
server_button_layout = QHBoxLayout()
add_server_button = QPushButton(text="+")
remove_server_button = QPushButton(text="-")
server_button_layout.addWidget(add_server_button)
server_button_layout.addWidget(remove_server_button)
# Layouts
info_layout = QVBoxLayout()
info_layout.addWidget(server_list_group, stretch=True)
info_layout.addWidget(server_info_group)
info_layout.setContentsMargins(0, 0, 0, 0)
server_list_group.setFixedWidth(260)
self.server_picked()
# Job list
self.job_list_view = QTableWidget()
self.job_list_view.setRowCount(0)
self.job_list_view.setColumnCount(8)
self.job_list_view.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows)
self.job_list_view.verticalHeader().setVisible(False)
self.job_list_view.itemSelectionChanged.connect(self.job_picked)
self.job_list_view.setEditTriggers(QAbstractItemView.EditTrigger.NoEditTriggers)
# Setup Job Headers
self.job_list_view.setHorizontalHeaderLabels(["ID", "Name", "Engine", "Priority", "Status",
"Time Elapsed", "Frames", "Date Created"])
self.job_list_view.setColumnHidden(0, True)
self.job_list_view.horizontalHeader().setSectionResizeMode(1, QHeaderView.ResizeMode.Stretch)
self.job_list_view.horizontalHeader().setSectionResizeMode(2, QHeaderView.ResizeMode.ResizeToContents)
self.job_list_view.horizontalHeader().setSectionResizeMode(3, QHeaderView.ResizeMode.ResizeToContents)
self.job_list_view.horizontalHeader().setSectionResizeMode(4, QHeaderView.ResizeMode.ResizeToContents)
self.job_list_view.horizontalHeader().setSectionResizeMode(5, QHeaderView.ResizeMode.ResizeToContents)
self.job_list_view.horizontalHeader().setSectionResizeMode(6, QHeaderView.ResizeMode.ResizeToContents)
self.job_list_view.horizontalHeader().setSectionResizeMode(7, QHeaderView.ResizeMode.ResizeToContents)
# Job List Layout
job_list_group = QGroupBox("Job Preview")
job_list_layout = QVBoxLayout(job_list_group)
job_list_layout.setContentsMargins(0, 0, 0, 0)
job_list_layout.addWidget(self.image_label)
job_list_layout.addWidget(self.job_list_view, stretch=True)
# Add them all to the window
main_layout.addLayout(info_layout)
right_layout = QVBoxLayout()
right_layout.setContentsMargins(0, 0, 0, 0)
right_layout.addWidget(job_list_group)
main_layout.addLayout(right_layout)
def closeEvent(self, event):
"""Handle window close event with job running confirmation.
Args:
event: The close event triggered by user.
"""
running_jobs = len(RenderQueue.running_jobs())
if running_jobs:
reply = QMessageBox.question(self, "Running Jobs",
f"You have {running_jobs} jobs running.\n"
f"Quitting will cancel these renders. Continue?",
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.Cancel,
QMessageBox.StandardButton.Cancel)
if reply == QMessageBox.StandardButton.Yes:
event.accept()
else:
event.ignore()
# -- Server Code -- #
def refresh_job_list(self):
"""Refresh the job list display."""
self.job_list_view.clearContents()
self.bg_update_thread.needs_update = True
@property
def current_server_proxy(self):
return ServerProxyManager.get_proxy_for_hostname(self.current_hostname)
def server_picked(self):
"""Update the UI elements relevant to the server selection."""
current_item = self.server_list_view.currentItem()
if current_item is None:
return
new_hostname = current_item.text()
if new_hostname == self.current_hostname:
return
self.current_hostname = new_hostname
self.job_list_view.setRowCount(0)
self.refresh_job_list()
if self.job_list_view.rowCount():
self.job_list_view.selectRow(0)
self.update_server_info_display(new_hostname)
def update_server_info_display(self, hostname):
"""Updates the server information section of the UI."""
self.server_info_hostname.setText(f"Name: {hostname}")
server_info = ZeroconfServer.get_hostname_properties(hostname)
# 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', '')}"
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_cpu.setText(cpu_info)
self.server_info_ram.setText(memory_info)
self.server_info_gpu.setText(gpu_info)
def update_ui_data(self):
"""Update UI data with current server and job information."""
self.update_servers()
if not self.current_server_proxy:
return
server_job_data = self.job_data.get(self.current_server_proxy.hostname)
if server_job_data is None:
return
num_jobs = len(server_job_data)
self.job_list_view.setRowCount(num_jobs)
for row, job in enumerate(server_job_data):
display_status = job['status'] if job['status'] != RenderStatus.RUNNING.value else \
('%.0f%%' % (job['percent_complete'] * 100)) # if running, show percent, otherwise just show status
tags = (job['status'],)
start_time = datetime.datetime.fromisoformat(job['start_time']) if job['start_time'] else None
end_time = datetime.datetime.fromisoformat(job['end_time']) if job['end_time'] else None
time_elapsed = "" if (job['status'] != RenderStatus.RUNNING.value and not end_time) else \
get_time_elapsed(start_time, end_time)
name = job.get('name') or os.path.basename(job.get('input_path', ''))
engine_name = f"{job.get('engine', '')}-{job.get('engine_version')}"
priority = str(job.get('priority', ''))
total_frames = str(job.get('total_frames', ''))
converted_time = datetime.datetime.fromisoformat(job['date_created'])
humanized_time = humanize.naturaltime(converted_time)
items = [QTableWidgetItem(job['id']), QTableWidgetItem(name), QTableWidgetItem(engine_name),
QTableWidgetItem(priority), QTableWidgetItem(display_status), QTableWidgetItem(time_elapsed),
QTableWidgetItem(total_frames), QTableWidgetItem(humanized_time)]
for col, item in enumerate(items):
self.job_list_view.setItem(row, col, item)
# -- Job Code -- #
def job_picked(self):
def fetch_preview(job_id):
try:
default_image_path = "error.png"
before_fetch_hostname = self.current_server_proxy.hostname
response = self.current_server_proxy.request(f'jobs/{job_id}/thumbnail?size=big')
if response.ok:
try:
with io.BytesIO(response.content) as image_data_stream:
image = Image.open(image_data_stream)
if self.current_server_proxy.hostname == before_fetch_hostname and job_id == \
self.selected_job_ids()[0]:
self.load_image_data(image)
return
except PIL.UnidentifiedImageError:
default_image_path = response.text
else:
default_image_path = default_image_path or response.text
self.load_image_path(os.path.join(resources_dir(), default_image_path))
except ConnectionError as e:
logger.error(f"Connection error fetching image: {e}")
except Exception as e:
logger.error(f"Error fetching image: {e}")
job_id = self.selected_job_ids()[0] if self.selected_job_ids() else None
local_server = is_localhost(self.current_hostname)
if job_id:
fetch_thread = threading.Thread(target=fetch_preview, args=(job_id,))
fetch_thread.daemon = True
fetch_thread.start()
selected_row = self.job_list_view.selectionModel().selectedRows()[0]
current_status = self.job_list_view.item(selected_row.row(), 4).text()
# show / hide the stop button
show_stop_button = "%" in current_status
self.topbar.actions_call['Stop Job'].setEnabled(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'].setVisible(not show_stop_button)
self.topbar.actions_call['Render Log'].setEnabled(True)
self.topbar.actions_call['Download'].setEnabled(not local_server)
self.topbar.actions_call['Download'].setVisible(not local_server)
self.topbar.actions_call['Open Files'].setEnabled(local_server)
self.topbar.actions_call['Open Files'].setVisible(local_server)
else:
# load default
default_image_path = os.path.join(resources_dir(), 'Rectangle.png')
self.load_image_path(default_image_path)
self.topbar.actions_call['Stop Job'].setVisible(False)
self.topbar.actions_call['Stop Job'].setEnabled(False)
self.topbar.actions_call['Delete Job'].setEnabled(False)
self.topbar.actions_call['Render Log'].setEnabled(False)
self.topbar.actions_call['Download'].setEnabled(False)
self.topbar.actions_call['Download'].setVisible(True)
self.topbar.actions_call['Open Files'].setEnabled(False)
self.topbar.actions_call['Open Files'].setVisible(False)
def selected_job_ids(self):
"""Get list of selected job IDs from the job list.
Returns:
List[str]: List of selected job ID strings.
"""
try:
selected_rows = self.job_list_view.selectionModel().selectedRows()
job_ids = []
for selected_row in selected_rows:
id_item = self.job_list_view.item(selected_row.row(), 0)
job_ids.append(id_item.text())
return job_ids
except AttributeError as e:
logger.error(f"AttributeError in selected_job_ids: {e}")
return []
# -- Image Code -- #
def load_image_path(self, image_path):
"""Load and display an image from file path.
Args:
image_path: Path to the image file to load.
"""
# Load and set image using QPixmap
try:
pixmap = QPixmap(image_path)
if not pixmap:
logger.error("Error loading image")
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):
try:
# Convert the Pillow Image to a QByteArray (byte buffer)
byte_array = QByteArray()
buffer = QBuffer(byte_array)
buffer.open(QIODevice.OpenModeFlag.WriteOnly)
pillow_image.save(buffer, "PNG")
buffer.close()
# Create a QImage from the QByteArray
image = QImage.fromData(byte_array)
# Create a QPixmap from the QImage
pixmap = QPixmap.fromImage(image)
if not pixmap:
logger.error("Error loading image")
return
self.image_label.setPixmap(pixmap)
except Exception as e:
logger.error(f"Error loading image data: {e}")
def update_servers(self):
# Always make sure local hostname is first
if self.found_servers and not is_localhost(self.found_servers[0]):
for hostname in self.found_servers:
if is_localhost(hostname):
self.found_servers.remove(hostname)
self.found_servers.insert(0, hostname)
break
old_count = self.server_list_view.count()
# Update proxys
for hostname in self.found_servers:
ServerProxyManager.get_proxy_for_hostname(hostname) # setup background updates
# Add in all the missing servers
current_server_list = []
for i in range(self.server_list_view.count()):
current_server_list.append(self.server_list_view.item(i).text())
for hostname in self.found_servers:
if hostname not in current_server_list:
properties = ZeroconfServer.get_hostname_properties(hostname)
image_path = os.path.join(resources_dir(), f"{properties.get('system_os', 'Monitor')}.png")
list_widget = QListWidgetItem(QIcon(image_path), hostname)
self.server_list_view.addItem(list_widget)
# find any servers that shouldn't be shown any longer
servers_to_remove = []
for i in range(self.server_list_view.count()):
name = self.server_list_view.item(i).text()
if name not in self.found_servers:
servers_to_remove.append(name)
# remove any servers that shouldn't be shown any longer
for server in servers_to_remove:
# Find and remove the item with the specified text
for i in range(self.server_list_view.count()):
item = self.server_list_view.item(i)
if item is not None and item.text() == server:
self.server_list_view.takeItem(i)
break # Stop searching after the first match is found
if not old_count and self.server_list_view.count():
self.server_list_view.setCurrentRow(0)
self.server_picked()
elif self.server_list_view.count() and self.server_list_view.currentItem() is None:
self.server_list_view.setCurrentRow(0)
self.server_picked()
def create_toolbars(self) -> None:
"""
Creates and adds the top and right toolbars to the main window.
"""
# Top Toolbar [PyQt6.QtWidgets.QToolBar]
self.topbar = ToolBar(self, orientation=Qt.Orientation.Horizontal,
style=Qt.ToolButtonStyle.ToolButtonTextUnderIcon, icon_size=(24, 24))
self.topbar.setMovable(False)
resources_directory = resources_dir()
# Top Toolbar Buttons
self.topbar.add_button(
"Settings", f"{resources_directory}/Gear.png", self.menuBar().show_settings)
self.topbar.add_button(
"Console", f"{resources_directory}/Console.png", self.open_console_window)
self.topbar.add_separator()
self.topbar.add_button(
"Stop Job", f"{resources_directory}/StopSign.png", self.stop_job)
self.topbar.add_button(
"Delete Job", f"{resources_directory}/Trash.png", self.delete_job)
self.topbar.add_button(
"Render Log", f"{resources_directory}/Document.png", self.job_logs)
self.topbar.add_button(
"Download", f"{resources_directory}/Download.png", self.download_files)
self.topbar.add_button(
"Open Files", f"{resources_directory}/SearchFolder.png", self.open_files)
self.topbar.add_button(
"New Job", f"{resources_directory}/AddProduct.png", self.new_job)
self.addToolBar(Qt.ToolBarArea.TopToolBarArea, self.topbar)
# -- Toolbar Buttons -- #
def open_console_window(self) -> None:
"""
Event handler for the "Open Console" button
"""
self.console_window = ConsoleWindow(self.buffer_handler)
self.console_window.buffer_handler = self.buffer_handler
self.console_window.show()
def engine_browser(self):
self.engine_browser_window = EngineBrowserWindow(hostname=self.current_hostname)
self.engine_browser_window.show()
def job_logs(self) -> None:
"""Open log viewer for selected job.
Opens a log viewer window showing the logs for the currently selected job.
"""
selected_job_ids = self.selected_job_ids()
if selected_job_ids:
url = (f'http://{self.current_server_proxy.hostname}:{self.current_server_proxy.port}'
f'/api/jobs/{selected_job_ids[0]}/logs')
self.log_viewer_window = LogViewer(url)
self.log_viewer_window.show()
def stop_job(self, event):
"""Stop selected render jobs with user confirmation.
Args:
event: The button click event.
"""
job_ids = self.selected_job_ids()
if not job_ids:
return
if len(job_ids) == 1:
job = next((job for job in self.current_server_proxy.get_jobs() if job.get('id') == job_ids[0]), None)
if job:
display_name = job.get('name', os.path.basename(job.get('input_path', '')))
message = f"Are you sure you want to stop job: {display_name}?"
else:
return # Job not found, handle this case as needed
else:
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
msg_box = QMessageBox(QMessageBox.Icon.Warning, "Stop Job", message,
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No, self)
if msg_box.exec() == QMessageBox.StandardButton.Yes:
for job_id in job_ids:
self.current_server_proxy.cancel_job(job_id, confirm=True)
self.refresh_job_list()
def delete_job(self, event):
"""Delete selected render jobs with user confirmation.
Args:
event: The button click event.
"""
job_ids = self.selected_job_ids()
if not job_ids:
return
if len(job_ids) == 1:
job = next((job for job in self.current_server_proxy.get_jobs() if job.get('id') == job_ids[0]), None)
if job:
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}?"
else:
return # Job not found, handle this case as needed
else:
message = f"Are you sure you want to delete these {len(job_ids)} jobs?"
# Display the message box and check the response in one go
msg_box = QMessageBox(QMessageBox.Icon.Warning, "Delete Job", message,
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No, self)
if msg_box.exec() == QMessageBox.StandardButton.Yes:
for job_id in job_ids:
self.current_server_proxy.delete_job(job_id, confirm=True)
self.refresh_job_list()
def download_files(self, event):
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/jobs/{job_ids[0]}/download_all')
webbrowser.open(download_url)
def open_files(self, event):
job_ids = self.selected_job_ids()
if not job_ids:
return
for job_id in job_ids:
job_info = self.current_server_proxy.get_job(job_id)
path = os.path.dirname(job_info['output_path'])
launch_url(path)
def new_job(self) -> None:
file_name, _ = QFileDialog.getOpenFileName(self, "Select Scene File")
if file_name:
self.new_job_window = NewRenderJobForm(file_name)
self.new_job_window.show()
class BackgroundUpdater(QThread):
"""Worker class to fetch job and server information and update the UI"""
updated_signal = pyqtSignal()
error_signal = pyqtSignal(str)
def __init__(self, window):
super().__init__()
self.window = window
self.needs_update = True
def run(self):
"""Main background thread execution loop.
Continuously fetches server and job data, updating the main UI
every second or when updates are needed.
"""
try:
last_run = 0
while True:
now = time.monotonic()
if now - last_run >= 1.0 or self.needs_update:
self.window.found_servers = list(set(ZeroconfServer.found_hostnames() + self.window.added_hostnames))
self.window.found_servers = [x for x in self.window.found_servers if
ZeroconfServer.get_hostname_properties(x)['api_version'] == API_VERSION]
if self.window.current_server_proxy:
self.window.job_data[self.window.current_server_proxy.hostname] = \
self.window.current_server_proxy.get_jobs(ignore_token=False)
self.needs_update = False
self.updated_signal.emit()
time.sleep(0.05)
except Exception as e:
print(f"ERROR: {e}")
self.error_signal.emit(str(e))
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())
+552
View File
@@ -0,0 +1,552 @@
import os
import socket
from datetime import datetime
from pathlib import Path
import humanize
from PyQt6 import QtCore
from PyQt6.QtCore import Qt, QSettings, pyqtSignal as Signal, QThread, pyqtSignal, QTimer
from PyQt6.QtGui import QIcon
from PyQt6.QtWidgets import QApplication, QMainWindow, QListWidget, QListWidgetItem, QStackedWidget, QVBoxLayout, \
QWidget, QLabel, QCheckBox, QLineEdit, \
QPushButton, QHBoxLayout, QGroupBox, QTableWidget, QAbstractItemView, QTableWidgetItem, QHeaderView, \
QMessageBox, QProgressBar
from src.api.server_proxy import RenderServerProxy
from src.engines.engine_manager import EngineManager
from src.utilities.config import Config
from src.utilities.misc_helper import launch_url
from src.version import APP_AUTHOR, APP_NAME
settings = QSettings(APP_AUTHOR, APP_NAME)
class GetEngineInfoWorker(QThread):
"""
The GetEngineInfoWorker class fetches engine information from a server in a background thread.
Attributes:
done: A signal emitted when the engine information is retrieved.
Methods:
run(self): Fetches engine information from the server.
"""
done = pyqtSignal(object) # emits the result when finished
def __init__(self, parent=None):
super().__init__(parent)
self.parent = parent
def run(self):
data = RenderServerProxy(socket.gethostname()).get_engines()
self.done.emit(data)
class SettingsWindow(QMainWindow):
"""
The SettingsWindow class provides a user interface for managing engine settings.
"""
def __init__(self):
super().__init__()
self.engine_download_progress_bar = None
self.engines_last_update_label = None
self.check_for_engine_updates_checkbox = None
self.delete_engine_button = None
self.launch_engine_button = None
self.show_password_button = None
self.network_password_line = None
self.enable_network_password_checkbox = None
self.check_for_new_engines_button = None
if not EngineManager.engines_path: # fix issue where sometimes path was not set
EngineManager.engines_path = Path(Config.upload_folder).expanduser() / "engines"
self.installed_engines_table = None
self.setWindowTitle("Settings")
# Create the main layout
main_layout = QVBoxLayout()
# Create the sidebar (QListWidget) for navigation
self.sidebar = QListWidget()
self.sidebar.setFixedWidth(150)
# Set the icon size
self.sidebar.setIconSize(QtCore.QSize(32, 32)) # Increase the icon size to 32x32 pixels
# Adjust the font size for the sidebar items
font = self.sidebar.font()
font.setPointSize(12) # Increase the font size
self.sidebar.setFont(font)
# Add items with icons to the sidebar
resources_dir = os.path.join(Path(__file__).resolve().parent.parent.parent, 'resources')
self.add_sidebar_item("General", os.path.join(resources_dir, "Gear.png"))
self.add_sidebar_item("Server", os.path.join(resources_dir, "Server.png"))
self.add_sidebar_item("Engines", os.path.join(resources_dir, "Blender.png"))
self.sidebar.setCurrentRow(0)
# Create the stacked widget to hold different settings pages
self.stacked_widget = QStackedWidget()
# Create pages for each section
general_page = self.create_general_page()
network_page = self.create_network_page()
engines_page = self.create_engines_page()
# Add pages to the stacked widget
self.stacked_widget.addWidget(general_page)
self.stacked_widget.addWidget(network_page)
self.stacked_widget.addWidget(engines_page)
# Connect the sidebar to the stacked widget
self.sidebar.currentRowChanged.connect(self.stacked_widget.setCurrentIndex)
# Create a horizontal layout to hold the sidebar and stacked widget
content_layout = QHBoxLayout()
content_layout.addWidget(self.sidebar)
content_layout.addWidget(self.stacked_widget)
# Add the content layout to the main layout
main_layout.addLayout(content_layout)
# Add the "OK" button at the bottom
ok_button = QPushButton("OK")
ok_button.clicked.connect(self.close)
ok_button.setFixedWidth(80)
ok_button.setDefault(True)
main_layout.addWidget(ok_button, alignment=Qt.AlignmentFlag.AlignRight)
# Create a central widget and set the layout
central_widget = QWidget()
central_widget.setLayout(main_layout)
self.setCentralWidget(central_widget)
self.setMinimumSize(700, 400)
# timers for background download UI updates
self.timer = QTimer(self)
self.timer.timeout.connect(self.update_engine_download_status)
def add_sidebar_item(self, name, icon_path):
"""Add an item with an icon to the sidebar."""
item = QListWidgetItem(QIcon(icon_path), name)
self.sidebar.addItem(item)
def create_general_page(self):
"""Create the General settings page."""
page = QWidget()
layout = QVBoxLayout()
# Startup Settings Group
startup_group = QGroupBox("Startup Settings")
startup_layout = QVBoxLayout()
# startup_layout.addWidget(QCheckBox("Start application on system startup"))
check_for_updates_checkbox = QCheckBox("Check for updates automatically")
check_for_updates_checkbox.setChecked(settings.value("auto_check_for_updates", True, type=bool))
check_for_updates_checkbox.stateChanged.connect(lambda state: settings.setValue("auto_check_for_updates", bool(state)))
startup_layout.addWidget(check_for_updates_checkbox)
startup_group.setLayout(startup_layout)
# Local Files Group
data_path = Path(Config.upload_folder).expanduser()
path_size = sum(f.stat().st_size for f in Path(data_path).rglob('*') if f.is_file())
database_group = QGroupBox("Local Files")
database_layout = QVBoxLayout()
database_layout.addWidget(QLabel(f"Local Directory: {data_path}"))
database_layout.addWidget(QLabel(f"Size: {humanize.naturalsize(path_size, binary=True)}"))
open_database_path_button = QPushButton("Open Directory")
open_database_path_button.clicked.connect(lambda: launch_url(data_path))
open_database_path_button.setFixedWidth(200)
database_layout.addWidget(open_database_path_button)
database_group.setLayout(database_layout)
# Render Settings Group
render_settings_group = QGroupBox("Render Engine Settings")
render_settings_layout = QVBoxLayout()
render_settings_layout.addWidget(QLabel("Restrict to render nodes with same:"))
require_same_engine_checkbox = QCheckBox("Renderer Version")
require_same_engine_checkbox.setChecked(settings.value("render_require_same_engine_version", False, type=bool))
require_same_engine_checkbox.stateChanged.connect(lambda state: settings.setValue("render_require_same_engine_version", bool(state)))
render_settings_layout.addWidget(require_same_engine_checkbox)
require_same_cpu_checkbox = QCheckBox("CPU Architecture")
require_same_cpu_checkbox.setChecked(settings.value("render_require_same_cpu_type", False, type=bool))
require_same_cpu_checkbox.stateChanged.connect(lambda state: settings.setValue("render_require_same_cpu_type", bool(state)))
render_settings_layout.addWidget(require_same_cpu_checkbox)
require_same_os_checkbox = QCheckBox("Operating System")
require_same_os_checkbox.setChecked(settings.value("render_require_same_os", False, type=bool))
require_same_os_checkbox.stateChanged.connect(lambda state: settings.setValue("render_require_same_os", bool(state)))
render_settings_layout.addWidget(require_same_os_checkbox)
render_settings_group.setLayout(render_settings_layout)
layout.addWidget(startup_group)
layout.addWidget(database_group)
layout.addWidget(render_settings_group)
layout.addStretch() # Add a stretch to push content to the top
page.setLayout(layout)
return page
def create_network_page(self):
"""Create the Network settings page."""
page = QWidget()
layout = QVBoxLayout()
# Sharing Settings Group
sharing_group = QGroupBox("Sharing Settings")
sharing_layout = QVBoxLayout()
enable_sharing_checkbox = QCheckBox("Enable other computers on the network to render to this machine")
enable_sharing_checkbox.setChecked(settings.value("enable_network_sharing", False, type=bool))
enable_sharing_checkbox.stateChanged.connect(self.toggle_render_sharing)
sharing_layout.addWidget(enable_sharing_checkbox)
password_enabled = (settings.value("enable_network_sharing", False, type=bool) and
settings.value("enable_network_password", False, type=bool))
password_layout = QHBoxLayout()
password_layout.setContentsMargins(0, 0, 0, 0)
self.enable_network_password_checkbox = QCheckBox("Enable network password:")
self.enable_network_password_checkbox.setChecked(settings.value("enable_network_password", False, type=bool))
self.enable_network_password_checkbox.stateChanged.connect(self.enable_network_password_changed)
self.enable_network_password_checkbox.setEnabled(settings.value("enable_network_sharing", False, type=bool))
sharing_layout.addWidget(self.enable_network_password_checkbox)
self.network_password_line = QLineEdit()
self.network_password_line.setPlaceholderText("Enter a password")
self.network_password_line.setEchoMode(QLineEdit.EchoMode.Password)
self.network_password_line.setEnabled(password_enabled)
password_layout.addWidget(self.network_password_line)
self.show_password_button = QPushButton("Show")
self.show_password_button.setEnabled(password_enabled)
self.show_password_button.clicked.connect(self.show_password_button_pressed)
password_layout.addWidget(self.show_password_button)
sharing_layout.addLayout(password_layout)
sharing_group.setLayout(sharing_layout)
layout.addWidget(sharing_group)
layout.addStretch() # Add a stretch to push content to the top
page.setLayout(layout)
return page
def toggle_render_sharing(self, enable_sharing):
settings.setValue("enable_network_sharing", enable_sharing)
self.enable_network_password_checkbox.setEnabled(enable_sharing)
enable_password = enable_sharing and settings.value("enable_network_password", False, type=bool)
self.network_password_line.setEnabled(enable_password)
self.show_password_button.setEnabled(enable_password)
def enable_network_password_changed(self, new_value):
settings.setValue("enable_network_password", new_value)
self.network_password_line.setEnabled(new_value)
self.show_password_button.setEnabled(new_value)
def show_password_button_pressed(self):
# toggle showing / hiding the password
show_pass = self.show_password_button.text() == "Show"
self.show_password_button.setText("Hide" if show_pass else "Show")
self.network_password_line.setEchoMode(QLineEdit.EchoMode.Normal if show_pass else QLineEdit.EchoMode.Password)
def create_engines_page(self):
"""Create the Engines settings page."""
page = QWidget()
layout = QVBoxLayout()
# Installed Engines Group
installed_group = QGroupBox("Installed Engines")
installed_layout = QVBoxLayout()
# Setup table
self.installed_engines_table = EngineTableWidget()
self.installed_engines_table.row_selected.connect(self.engine_table_selected)
installed_layout.addWidget(self.installed_engines_table)
# Ignore system installs
engine_ignore_system_installs_checkbox = QCheckBox("Ignore system installs")
engine_ignore_system_installs_checkbox.setChecked(settings.value("engines_ignore_system_installs", False, type=bool))
engine_ignore_system_installs_checkbox.stateChanged.connect(self.change_ignore_system_installs)
installed_layout.addWidget(engine_ignore_system_installs_checkbox)
# Engine Launch / Delete buttons
installed_buttons_layout = QHBoxLayout()
self.launch_engine_button = QPushButton("Launch")
self.launch_engine_button.setEnabled(False)
self.launch_engine_button.clicked.connect(self.launch_selected_engine)
self.delete_engine_button = QPushButton("Delete")
self.delete_engine_button.setEnabled(False)
self.delete_engine_button.clicked.connect(self.delete_selected_engine)
installed_buttons_layout.addWidget(self.launch_engine_button)
installed_buttons_layout.addWidget(self.delete_engine_button)
installed_layout.addLayout(installed_buttons_layout)
installed_group.setLayout(installed_layout)
# Engine Updates Group
engine_updates_group = QGroupBox("Auto-Install")
engine_updates_layout = QVBoxLayout()
engine_download_layout = QHBoxLayout()
engine_download_layout.addWidget(QLabel("Enable Downloads for:"))
at_least_one_downloadable = False
for engine in EngineManager.downloadable_engines():
engine_download_check = QCheckBox(engine.name())
is_checked = settings.value(f"engine_download-{engine.name()}", False, type=bool)
at_least_one_downloadable |= is_checked
engine_download_check.setChecked(is_checked)
# Capture the checkbox correctly using a default argument in lambda
engine_download_check.clicked.connect(
lambda state, checkbox=engine_download_check: self.engine_download_settings_changed(state, checkbox.text())
)
engine_download_layout.addWidget(engine_download_check)
engine_updates_layout.addLayout(engine_download_layout)
self.check_for_engine_updates_checkbox = QCheckBox("Check for new versions on launch")
self.check_for_engine_updates_checkbox.setChecked(settings.value('check_for_engine_updates_on_launch', True, type=bool))
self.check_for_engine_updates_checkbox.setEnabled(at_least_one_downloadable)
self.check_for_engine_updates_checkbox.stateChanged.connect(
lambda state: settings.setValue("check_for_engine_updates_on_launch", bool(state)))
engine_updates_layout.addWidget(self.check_for_engine_updates_checkbox)
self.engines_last_update_label = QLabel()
self.update_last_checked_label()
self.engines_last_update_label.setEnabled(at_least_one_downloadable)
engine_updates_layout.addWidget(self.engines_last_update_label)
self.engine_download_progress_bar = QProgressBar()
engine_updates_layout.addWidget(self.engine_download_progress_bar)
self.engine_download_progress_bar.setHidden(True)
self.check_for_new_engines_button = QPushButton("Check for New Versions...")
self.check_for_new_engines_button.setEnabled(at_least_one_downloadable)
self.check_for_new_engines_button.clicked.connect(self.check_for_new_engines)
engine_updates_layout.addWidget(self.check_for_new_engines_button)
engine_updates_group.setLayout(engine_updates_layout)
layout.addWidget(installed_group)
layout.addWidget(engine_updates_group)
layout.addStretch() # Add a stretch to push content to the top
page.setLayout(layout)
return page
def change_ignore_system_installs(self, value):
settings.setValue("engines_ignore_system_installs", bool(value))
self.installed_engines_table.update_engines_table()
def update_last_checked_label(self):
"""Retrieve the last check timestamp and return a human-friendly string."""
last_checked_str = settings.value("engines_last_update_time", None)
if not last_checked_str:
time_string = "Never"
else:
last_checked_dt = datetime.fromisoformat(last_checked_str)
now = datetime.now()
time_string = humanize.naturaltime(now - last_checked_dt)
self.engines_last_update_label.setText(f"Last Updated: {time_string}")
def engine_download_settings_changed(self, state, engine_name):
settings.setValue(f"engine_download-{engine_name}", state)
at_least_one_downloadable = False
for engine in EngineManager.downloadable_engines():
at_least_one_downloadable |= settings.value(f"engine_download-{engine.name()}", False, type=bool)
self.check_for_new_engines_button.setEnabled(at_least_one_downloadable)
self.check_for_engine_updates_checkbox.setEnabled(at_least_one_downloadable)
self.engines_last_update_label.setEnabled(at_least_one_downloadable)
def delete_selected_engine(self):
engine_info = self.installed_engines_table.selected_engine_data()
reply = QMessageBox.question(self, f"Delete {engine_info['engine']} {engine_info['version']}?",
f"Do you want to delete {engine_info['engine']} {engine_info['version']}?",
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No)
if reply is not QMessageBox.StandardButton.Yes:
return
delete_result = EngineManager.delete_engine_download(engine_info.get('engine'),
engine_info.get('version'),
engine_info.get('system_os'),
engine_info.get('cpu'))
self.installed_engines_table.update_engines_table(use_cached=False)
if delete_result:
QMessageBox.information(self, f"{engine_info['engine']} {engine_info['version']} Deleted",
f"{engine_info['engine']} {engine_info['version']} deleted successfully",
QMessageBox.StandardButton.Ok)
else:
QMessageBox.warning(self, f"Unknown Error",
f"Unknown error while deleting {engine_info['engine']} {engine_info['version']}.",
QMessageBox.StandardButton.Ok)
def launch_selected_engine(self):
engine_info = self.installed_engines_table.selected_engine_data()
if engine_info:
launch_url(engine_info['path'])
def engine_table_selected(self):
engine_data = self.installed_engines_table.selected_engine_data()
if engine_data:
self.launch_engine_button.setEnabled(bool(engine_data.get('path') or True))
self.delete_engine_button.setEnabled(engine_data.get('type') == 'managed')
else:
self.launch_engine_button.setEnabled(False)
self.delete_engine_button.setEnabled(False)
def check_for_new_engines(self):
ignore_system = settings.value("engines_ignore_system_installs", False, type=bool)
messagebox_shown = False
for engine in EngineManager.downloadable_engines():
if settings.value(f'engine_download-{engine.name()}', False, type=bool):
result = EngineManager.is_engine_update_available(engine, ignore_system_installs=ignore_system)
if result:
result['name'] = engine.name()
msg_box = QMessageBox()
msg_box.setWindowTitle(f"{result['name']} ({result['version']}) Available")
msg_box.setText(f"A new version of {result['name']} is available ({result['version']}).\n\n"
f"Would you like to download it now?")
msg_box.setIcon(QMessageBox.Icon.Question)
msg_box.setStandardButtons(QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No)
msg_result = msg_box.exec()
messagebox_shown = True
if msg_result == QMessageBox.StandardButton.Yes:
EngineManager.download_engine(engine_name=engine.name(), version=result['version'], background=True,
ignore_system=ignore_system)
self.engine_download_progress_bar.setHidden(False)
self.engine_download_progress_bar.setValue(0)
self.engine_download_progress_bar.setMaximum(100)
self.check_for_new_engines_button.setEnabled(False)
self.timer.start(1000)
if not messagebox_shown:
msg_box = QMessageBox()
msg_box.setWindowTitle("No Updates Available")
msg_box.setText("No Updates Available.")
msg_box.setIcon(QMessageBox.Icon.Information)
msg_box.setStandardButtons(QMessageBox.StandardButton.Ok)
msg_box.exec()
settings.setValue("engines_last_update_time", datetime.now().isoformat())
self.update_engine_download_status()
def update_engine_download_status(self):
running_tasks = EngineManager.active_downloads()
if not running_tasks:
self.timer.stop()
self.engine_download_progress_bar.setHidden(True)
self.installed_engines_table.update_engines_table(use_cached=False)
self.update_last_checked_label()
self.check_for_new_engines_button.setEnabled(True)
return
percent_complete = int(running_tasks[0].percent_complete * 100)
self.engine_download_progress_bar.setValue(percent_complete)
if percent_complete == 100:
status_update = f"Installing {running_tasks[0].engine.capitalize()} {running_tasks[0].version}..."
else:
status_update = f"Downloading {running_tasks[0].engine.capitalize()} {running_tasks[0].version}..."
self.engines_last_update_label.setText(status_update)
class EngineTableWidget(QWidget):
"""
The EngineTableWidget class displays a table of installed engines.
Attributes:
table: A table widget displaying engine information.
Methods:
on_selection_changed(self): Emits a signal when the user selects a different row in the table.
"""
row_selected = Signal()
def __init__(self):
super().__init__()
self.__get_engine_info_worker = None
self.table = QTableWidget(0, 4)
self.table.setHorizontalHeaderLabels(["Engine", "Version", "Type", "Path"])
self.table.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows)
self.table.verticalHeader().setVisible(False)
# self.table_widget.itemSelectionChanged.connect(self.engine_picked)
self.table.setEditTriggers(QAbstractItemView.EditTrigger.NoEditTriggers)
self.table.selectionModel().selectionChanged.connect(self.on_selection_changed)
layout = QVBoxLayout(self)
layout.setContentsMargins(0, 0, 0, 0)
layout.setSpacing(0)
layout.addWidget(self.table)
self.raw_server_data = None
def showEvent(self, event):
"""Runs when the widget is about to be shown."""
self.update_engines_table()
super().showEvent(event) # Ensure normal event processing
def engine_data_ready(self, raw_server_data):
self.raw_server_data = raw_server_data
self.update_engines_table()
def update_engines_table(self, use_cached=True):
if not self.raw_server_data or not use_cached:
self.__get_engine_info_worker = GetEngineInfoWorker(self)
self.__get_engine_info_worker.done.connect(self.engine_data_ready)
self.__get_engine_info_worker.start()
if not self.raw_server_data:
return
table_data = [] # convert the data into a flat list
for _, engine_data in self.raw_server_data.items():
table_data.extend(engine_data['versions'])
if settings.value("engines_ignore_system_installs", False, type=bool):
table_data = [x for x in table_data if x['type'] != 'system']
self.table.clear()
self.table.setRowCount(len(table_data))
self.table.setColumnCount(4)
self.table.setHorizontalHeaderLabels(['Engine', 'Version', 'Type', 'Path'])
self.table.horizontalHeader().setSectionResizeMode(0, QHeaderView.ResizeMode.Fixed)
self.table.horizontalHeader().setSectionResizeMode(1, QHeaderView.ResizeMode.Fixed)
self.table.horizontalHeader().setSectionResizeMode(2, QHeaderView.ResizeMode.Fixed)
self.table.horizontalHeader().setSectionResizeMode(3, QHeaderView.ResizeMode.Stretch)
for row, engine in enumerate(table_data):
self.table.setItem(row, 0, QTableWidgetItem(engine['engine']))
self.table.setItem(row, 1, QTableWidgetItem(engine['version']))
self.table.setItem(row, 2, QTableWidgetItem(engine['type']))
self.table.setItem(row, 3, QTableWidgetItem(engine['path']))
self.table.selectRow(0)
def selected_engine_data(self):
"""Returns the data from the selected row as a dictionary."""
row = self.table.currentRow() # Get the selected row index
if row < 0 or not len(self.table.selectedItems()): # No row selected
return None
data = {
"engine": self.table.item(row, 0).text(),
"version": self.table.item(row, 1).text(),
"type": self.table.item(row, 2).text(),
"path": self.table.item(row, 3).text(),
}
return data
def on_selection_changed(self):
self.row_selected.emit()
if __name__ == "__main__":
app = QApplication([])
window = SettingsWindow()
window.show()
app.exec()
View File
+105
View File
@@ -0,0 +1,105 @@
''' app/ui/widgets/menubar.py '''
from PyQt6.QtGui import QAction
from PyQt6.QtWidgets import QMenuBar, QApplication, QMessageBox, QDialog, QVBoxLayout, QLabel, QPushButton
class MenuBar(QMenuBar):
"""
Initialize the menu bar.
Args:
parent: The parent widget.
"""
def __init__(self, parent=None) -> None:
super().__init__(parent)
self.settings_window = None
# setup menus
file_menu = self.addMenu("File")
# edit_menu = self.addMenu("Edit")
# view_menu = self.addMenu("View")
help_menu = self.addMenu("Help")
# --file menu--
# new job
new_job_action = QAction("New Job...", self)
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)
# 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):
from src.ui.settings_window import SettingsWindow
self.settings_window = SettingsWindow()
self.settings_window.show()
@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()
@@ -0,0 +1,40 @@
from PyQt6.QtCore import QRectF
from PyQt6.QtGui import QPainter
from PyQt6.QtWidgets import QLabel
class ProportionalImageLabel(QLabel):
def __init__(self):
super().__init__()
def setPixmap(self, pixmap):
self._pixmap = pixmap
super().setPixmap(self._pixmap)
def paintEvent(self, event):
if self._pixmap.isNull():
super().paintEvent(event)
return
painter = QPainter(self)
targetRect = event.rect()
# Calculate the aspect ratio of the pixmap
aspectRatio = self._pixmap.width() / self._pixmap.height()
# Calculate the size of the pixmap within the target rectangle while maintaining the aspect ratio
if aspectRatio > targetRect.width() / targetRect.height():
scaledWidth = targetRect.width()
scaledHeight = targetRect.width() / aspectRatio
else:
scaledHeight = targetRect.height()
scaledWidth = targetRect.height() * aspectRatio
# Calculate the position to center the pixmap within the target rectangle
x = targetRect.x() + (targetRect.width() - scaledWidth) / 2
y = targetRect.y() + (targetRect.height() - scaledHeight) / 2
sourceRect = QRectF(0.0, 0.0, self._pixmap.width(), self._pixmap.height())
targetRect = QRectF(x, y, scaledWidth, scaledHeight)
painter.drawPixmap(targetRect, self._pixmap, sourceRect)
+72
View File
@@ -0,0 +1,72 @@
''' app/ui/widgets/statusbar.py '''
import os.path
import socket
import threading
import time
from PyQt6.QtCore import Qt, QTimer
from PyQt6.QtGui import QPixmap
from PyQt6.QtWidgets import QStatusBar, QLabel
from src.api.server_proxy import RenderServerProxy
from src.engines.engine_manager import EngineManager
from src.utilities.misc_helper import resources_dir
class StatusBar(QStatusBar):
"""
Initialize the status bar.
Args:
parent: The parent widget.
"""
def __init__(self, parent) -> None:
super().__init__(parent)
def background_update():
proxy = RenderServerProxy(socket.gethostname())
proxy.start_background_update()
image_names = {'Ready': 'GreenCircle.png', 'Offline': "RedSquare.png"}
# Check for status change every 1s on background thread
while True:
try:
# update status label - get download status
new_status = proxy.status()
active_downloads = EngineManager.active_downloads()
if active_downloads:
if len(active_downloads) == 1:
task = active_downloads[0]
new_status = f"{new_status} | Downloading {task.engine.capitalize()} {task.version}..."
else:
new_status = f"{new_status} | Downloading {len(active_downloads)} engines"
self.messageLabel.setText(new_status)
# update status image
new_image_name = image_names.get(new_status, 'Synchronize.png')
new_image_path = os.path.join(resources_dir(), new_image_name)
self.label.setPixmap((QPixmap(new_image_path).scaled(16, 16, Qt.AspectRatioMode.KeepAspectRatio)))
except RuntimeError: # ignore runtime errors during shutdown
pass
time.sleep(1)
background_thread = threading.Thread(target=background_update,)
background_thread.daemon = True
background_thread.start()
# Create a label that holds an image
self.label = QLabel()
image_path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), 'resources',
'RedSquare.png')
pixmap = (QPixmap(image_path).scaled(16, 16, Qt.AspectRatioMode.KeepAspectRatio))
self.label.setPixmap(pixmap)
self.addWidget(self.label)
# Create a label for the message
self.messageLabel = QLabel()
self.addWidget(self.messageLabel)
# Call this method to display a message
self.messageLabel.setText("Loading...")
+49
View File
@@ -0,0 +1,49 @@
''' app/ui/widgets/toolbar.py '''
from PyQt6.QtCore import Qt, QSize
from PyQt6.QtGui import QAction, QIcon
from PyQt6.QtWidgets import QToolBar, QWidget, QSizePolicy
class ToolBar(QToolBar):
"""
Initialize the toolbar.
Args:
parent: The parent widget.
orientation: The toolbar's orientation.
style: The toolbar's tool button style.
icon_size: The toolbar's icon size.
"""
def __init__(self, parent,
orientation: Qt.Orientation = Qt.Orientation.Horizontal,
style: Qt.ToolButtonStyle = Qt.ToolButtonStyle.ToolButtonTextUnderIcon,
icon_size: tuple[int, int] = (32, 32)) -> None:
super().__init__(parent)
self.actions_call = {}
self.setOrientation(orientation)
self.setToolButtonStyle(style)
self.setIconSize(QSize(icon_size[0], icon_size[1]))
def add_button(self, text: str, icon: str, trigger_action) -> None:
"""
Add a button to the toolbar.
Args:
text: The button's text.
icon: The button's icon.
trigger_action: The action to be executed when the button is clicked.
"""
self.actions_call[text] = QAction(QIcon(icon), text, self)
self.actions_call[text].triggered.connect(trigger_action)
self.addAction(self.actions_call[text])
def add_separator(self) -> None:
"""
Add a separator to the toolbar.
"""
separator = QWidget(self)
separator.setSizePolicy(
QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
self.addWidget(separator)
+29
View File
@@ -0,0 +1,29 @@
''' app/ui/widgets/treeview.py '''
from PyQt6.QtWidgets import QTreeView
from PyQt6.QtGui import QFileSystemModel
from PyQt6.QtCore import QDir
class TreeView(QTreeView):
"""
Initialize the TreeView widget.
Args:
parent (QWidget, optional): Parent widget of the TreeView. Defaults to None.
"""
def __init__(self, parent=None) -> None:
super().__init__(parent)
self.file_system_model: QFileSystemModel = QFileSystemModel()
self.file_system_model.setRootPath(QDir.currentPath())
self.setModel(self.file_system_model)
self.setRootIndex(self.file_system_model.index(QDir.currentPath()))
self.setColumnWidth(0, 100)
self.setFixedWidth(150)
self.setSortingEnabled(True)
def clear_view(self) -> None:
"""
Clearing the TreeView
"""
self.destroy(destroySubWindows=True)
+78
View File
@@ -0,0 +1,78 @@
import concurrent.futures
import os
import time
import logging
logger = logging.getLogger()
def cpu_workload(n):
# Simple arithmetic operation for workload
while n > 0:
n -= 1
return n
def cpu_benchmark(duration_seconds=10):
# Determine the number of available CPU cores
num_cores = os.cpu_count()
# Calculate workload per core, assuming a large number for the workload
workload_per_core = 10000000
# Record start time
start_time = time.time()
# Use ProcessPoolExecutor to utilize all CPU cores
with concurrent.futures.ProcessPoolExecutor() as executor:
# Launching tasks for each core
futures = [executor.submit(cpu_workload, workload_per_core) for _ in range(num_cores)]
# Wait for all futures to complete, with a timeout to limit the benchmark duration
concurrent.futures.wait(futures, timeout=duration_seconds)
# Record end time
end_time = time.time()
# Calculate the total number of operations (workload) done by all cores
total_operations = workload_per_core * num_cores
# Calculate the total time taken
total_time = end_time - start_time
# Calculate operations per second as the score
score = total_operations / total_time
score = score * 0.0001
return int(score)
def disk_io_benchmark(file_size_mb=100, filename='benchmark_test_file'):
write_speed = None
read_speed = None
# Measure write speed
start_time = time.time()
with open(filename, 'wb') as f:
f.write(os.urandom(file_size_mb * 1024 * 1024)) # Write random bytes to file
end_time = time.time()
write_time = end_time - start_time
write_speed = file_size_mb / write_time
# Measure read speed
start_time = time.time()
with open(filename, 'rb') as f:
content = f.read()
end_time = time.time()
read_time = end_time - start_time
read_speed = file_size_mb / read_time
# Cleanup
os.remove(filename)
logger.debug(f"Disk Write Speed: {write_speed:.2f} MB/s")
logger.debug(f"Disk Read Speed: {read_speed:.2f} MB/s")
return write_speed, read_speed
if __name__ == '__main__':
print(cpu_benchmark())
print(disk_io_benchmark())
+94
View File
@@ -0,0 +1,94 @@
import os
from pathlib import Path
from typing import Optional
import yaml
from src.utilities.misc_helper import current_system_os, copy_directory_contents
_CONFIG_ATTRS = [
'upload_folder', 'update_engines_on_launch', 'max_content_path',
'server_log_level', 'log_buffer_length', 'worker_process_timeout',
'flask_log_level', 'flask_debug_enable', 'queue_eval_seconds',
'port_number', 'enable_split_jobs', 'download_timeout_seconds',
]
class Config:
_default_instance: Optional['Config'] = None
# Class-level defaults — mutated by _sync_class() so existing
# callers (Config.upload_folder) continue to work during the
# migration to instance-based access.
upload_folder = "~/zordon-uploads/"
update_engines_on_launch = True
max_content_path = 100000000
server_log_level = 'debug'
log_buffer_length = 250
worker_process_timeout = 120
flask_log_level = 'error'
flask_debug_enable = False
queue_eval_seconds = 1
port_number = 8080
enable_split_jobs = True
download_timeout_seconds = 120
def __init__(self) -> None:
for attr in _CONFIG_ATTRS:
setattr(self, attr, getattr(Config, attr))
def load(self, config_path: Path) -> None:
with open(config_path, 'r') as ymlfile:
cfg = yaml.safe_load(ymlfile)
for attr in _CONFIG_ATTRS:
if attr in cfg:
setattr(self, attr, cfg[attr])
self.upload_folder = str(Path(self.upload_folder).expanduser())
@classmethod
def _sync_class(cls) -> None:
if cls._default_instance is not None:
for attr in _CONFIG_ATTRS:
setattr(cls, attr, getattr(cls._default_instance, attr))
@classmethod
def load_config(cls, config_path: Path) -> None:
instance = Config()
instance.load(config_path)
cls._default_instance = instance
cls._sync_class()
@classmethod
def config_dir(cls) -> Path:
# Set up the config path
if current_system_os() == 'macos':
local_config_path = Path('~/Library/Application Support/Zordon').expanduser()
elif current_system_os() == 'windows':
local_config_path = Path(os.environ['APPDATA']) / 'Zordon'
else:
local_config_path = Path('~/.config/Zordon').expanduser()
return local_config_path
@classmethod
def setup_config_dir(cls):
# Set up the config path
local_config_dir = cls.config_dir()
if os.path.exists(local_config_dir):
return
try:
# Create the local configuration directory
os.makedirs(local_config_dir)
# Determine the template path
resource_environment_path = os.environ.get('RESOURCEPATH')
if resource_environment_path:
template_path = Path(resource_environment_path) / 'config'
else:
template_path = Path(__file__).resolve().parents[2] / 'config'
# Copy contents from the template to the local configuration directory
copy_directory_contents(template_path, local_config_dir)
except Exception as e:
print(f"An error occurred while setting up the config directory: {e}")
raise
+6 -5
View File
@@ -4,17 +4,18 @@ from src.engines.ffmpeg.ffmpeg_engine import FFMPEG
def image_sequence_to_video(source_glob_pattern, output_path, framerate=24, encoder="prores_ks", profile=4,
start_frame=1):
subprocess.run([FFMPEG.default_renderer_path(), "-framerate", str(framerate), "-start_number", str(start_frame), "-i",
f"{source_glob_pattern}", "-c:v", encoder, "-profile:v", str(profile), '-pix_fmt', 'yuva444p10le',
output_path], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=True)
subprocess.run([FFMPEG.default_engine_path(), "-framerate", str(framerate), "-start_number",
str(start_frame), "-i", f"{source_glob_pattern}", "-c:v", encoder, "-profile:v", str(profile),
'-pix_fmt', 'yuva444p10le', output_path], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
check=True)
def save_first_frame(source_path, dest_path, max_width=1280):
subprocess.run([FFMPEG.default_renderer_path(), '-i', source_path, '-vf', f'scale={max_width}:-1',
subprocess.run([FFMPEG.default_engine_path(), '-i', source_path, '-vf', f'scale={max_width}:-1',
'-vframes', '1', dest_path], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=True)
def generate_thumbnail(source_path, dest_path, max_width=240, fps=12):
subprocess.run([FFMPEG.default_renderer_path(), '-i', source_path, '-vf',
subprocess.run([FFMPEG.default_engine_path(), '-i', source_path, '-vf',
f"scale={max_width}:trunc(ow/a/2)*2,format=yuv420p", '-r', str(fps), '-c:v', 'libx264', '-preset',
'ultrafast', '-an', dest_path], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=True)
+309 -39
View File
@@ -1,24 +1,44 @@
import logging
import json
import os
import platform
import re
import shutil
import socket
import string
import subprocess
import sys
from datetime import datetime
from typing import Optional, List, Dict, Any
logger = logging.getLogger()
def launch_url(url):
if subprocess.run(['which', 'xdg-open'], capture_output=True).returncode == 0:
subprocess.run(['xdg-open', url]) # linux
elif subprocess.run(['which', 'open'], capture_output=True).returncode == 0:
subprocess.run(['open', url]) # macos
elif subprocess.run(['which', 'start'], capture_output=True).returncode == 0:
subprocess.run(['start', url]) # windows - need to validate this works
def launch_url(url: str) -> None:
logger = logging.getLogger(__name__)
if shutil.which('xdg-open'):
opener = 'xdg-open'
elif shutil.which('open'):
opener = 'open'
elif shutil.which('cmd'):
opener = 'start'
else:
logger.error(f"No valid launchers found to launch url: {url}")
error_message = f"No valid launchers found to launch URL: {url}"
logger.error(error_message)
raise OSError(error_message)
try:
if opener == 'start':
# For Windows, use 'cmd /c start'
subprocess.run(['cmd', '/c', 'start', url], shell=False)
else:
subprocess.run([opener, url])
except Exception as e:
logger.error(f"Failed to launch URL: {url}. Error: {e}")
def file_exists_in_mounts(filepath):
def file_exists_in_mounts(filepath: str) -> Optional[str]:
"""
Check if a file exists in any mounted directory.
It searches for the file in common mount points like '/Volumes', '/mnt', and '/media'.
@@ -33,9 +53,9 @@ def file_exists_in_mounts(filepath):
path = os.path.normpath(path)
components = []
while True:
path, component = os.path.split(path)
if component:
components.append(component)
path, comp = os.path.split(path)
if comp:
components.append(comp)
else:
if path:
components.append(path)
@@ -59,22 +79,19 @@ def file_exists_in_mounts(filepath):
return possible_mount_path
def get_time_elapsed(start_time=None, end_time=None):
from string import Template
class DeltaTemplate(Template):
delimiter = "%"
def get_time_elapsed(start_time: Optional[datetime] = None, end_time: Optional[datetime] = None) -> str:
def strfdelta(tdelta, fmt='%H:%M:%S'):
d = {"D": tdelta.days}
days = tdelta.days
hours, rem = divmod(tdelta.seconds, 3600)
minutes, seconds = divmod(rem, 60)
d["H"] = '{:02d}'.format(hours)
d["M"] = '{:02d}'.format(minutes)
d["S"] = '{:02d}'.format(seconds)
t = DeltaTemplate(fmt)
return t.substitute(**d)
# Using f-strings for formatting
formatted_str = fmt.replace('%D', f'{days}')
formatted_str = formatted_str.replace('%H', f'{hours:02d}')
formatted_str = formatted_str.replace('%M', f'{minutes:02d}')
formatted_str = formatted_str.replace('%S', f'{seconds:02d}')
return formatted_str
# calculate elapsed time
elapsed_time = None
@@ -89,10 +106,10 @@ def get_time_elapsed(start_time=None, end_time=None):
return elapsed_time_string
def get_file_size_human(file_path):
def get_file_size_human(file_path: str) -> str:
size_in_bytes = os.path.getsize(file_path)
# Convert size to a human readable format
# Convert size to a human-readable format
if size_in_bytes < 1024:
return f"{size_in_bytes} B"
elif size_in_bytes < 1024 ** 2:
@@ -105,21 +122,274 @@ def get_file_size_human(file_path):
return f"{size_in_bytes / 1024 ** 4:.2f} TB"
# Convert path to the appropriate format for the current platform
def system_safe_path(path):
if platform.system().lower() == "windows":
return os.path.normpath(path)
return path.replace("\\", "/")
def current_system_os():
def current_system_os() -> str:
return platform.system().lower().replace('darwin', 'macos')
def current_system_os_version():
return platform.mac_ver()[0] if current_system_os() == 'macos' else platform.release().lower()
def current_system_os_version() -> str:
return platform.release()
def current_system_cpu():
# convert all x86 64 to "x64"
return platform.machine().lower().replace('amd64', 'x64').replace('x86_64', 'x64')
def current_system_cpu() -> str:
return platform.machine().lower().replace('amd64', 'x64')
def current_system_cpu_brand() -> str:
"""Fast cross-platform CPU brand string"""
if sys.platform.startswith('darwin'): # macOS
try:
return subprocess.check_output(['sysctl', '-n', 'machdep.cpu.brand_string']).decode().strip()
except Exception:
pass
elif sys.platform.startswith('win'): # Windows
from winreg import HKEY_LOCAL_MACHINE, OpenKey, QueryValueEx
try:
# Open the registry key where Windows stores the CPU name
key = OpenKey(HKEY_LOCAL_MACHINE, r"HARDWARE\DESCRIPTION\System\CentralProcessor\0")
# The value name is "ProcessorNameString"
value, _ = QueryValueEx(key, "ProcessorNameString")
return value.strip() # Usually perfect, with full marketing name
except Exception:
# Fallback: sometimes the key is under a different index, try 1
try:
key = OpenKey(HKEY_LOCAL_MACHINE, r"HARDWARE\DESCRIPTION\System\CentralProcessor\1")
value, _ = QueryValueEx(key, "ProcessorNameString")
return value.strip()
except Exception:
return "Unknown CPU"
elif sys.platform.startswith('linux'):
try:
with open('/proc/cpuinfo') as f:
for line in f:
if line.startswith('model name'):
return line.split(':', 1)[1].strip()
except Exception:
pass
# Ultimate fallback
return platform.processor() or 'Unknown CPU'
def resources_dir() -> str:
return os.path.join(os.path.dirname(__file__), '..', '..', 'resources')
def copy_directory_contents(src_dir: str, dst_dir: str) -> None:
for item in os.listdir(src_dir):
src_path = os.path.join(src_dir, item)
dst_path = os.path.join(dst_dir, item)
if os.path.isdir(src_path):
shutil.copytree(src_path, dst_path)
else:
shutil.copy2(src_path, dst_path)
def check_for_updates(repo_name: str, repo_owner: str, app_name: str, current_version: str) -> Optional[Dict[str, Any]]:
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 None
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
return None
def is_localhost(comparison_hostname: str) -> bool:
return comparison_hostname in ['localhost', '127.0.0.1', socket.gethostname()]
def num_to_alphanumeric(num: int) -> str:
return string.ascii_letters[num % 26] + str(num // 26)
def get_gpu_info() -> List[Dict[str, Any]]:
"""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:
if current_system_cpu() == "arm64":
# don't bother with system_profiler with Apple ARM - we know its integrated
return [{'name': current_system_cpu_brand(), 'memory': 'Integrated'}]
result = subprocess.run(['system_profiler', 'SPDisplaysDataType', '-detailLevel', 'mini', '-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 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()
COMMON_RESOLUTIONS = {
# SD
"SD_480p": (640, 480),
"NTSC_DVD": (720, 480),
"PAL_DVD": (720, 576),
# HD
"HD_720p": (1280, 720),
"HD_900p": (1600, 900),
"HD_1080p": (1920, 1080),
# Cinema / Film
"2K_DCI": (2048, 1080),
"4K_DCI": (4096, 2160),
# UHD / Consumer
"UHD_4K": (3840, 2160),
"UHD_5K": (5120, 2880),
"UHD_8K": (7680, 4320),
# Ultrawide / Aspect Variants
"UW_1080p": (2560, 1080),
"UW_1440p": (3440, 1440),
"UW_5K": (5120, 2160),
# Mobile / Social
"VERTICAL_1080x1920": (1080, 1920),
"SQUARE_1080": (1080, 1080),
# Classic / Legacy
"VGA": (640, 480),
"SVGA": (800, 600),
"XGA": (1024, 768),
"WXGA": (1280, 800),
}
COMMON_FRAME_RATES = {
"23.976 (NTSC Film)": 23.976,
"24 (Cinema)": 24.0,
"25 (PAL)": 25.0,
"29.97 (NTSC)": 29.97,
"30": 30.0,
"48 (HFR Film)": 48.0,
"50 (PAL HFR)": 50.0,
"59.94": 59.94,
"60": 60.0,
"72": 72.0,
"90 (VR)": 90.0,
"120": 120.0,
"144 (Gaming)": 144.0,
"240 (HFR)": 240.0,
}
+186 -33
View File
@@ -1,47 +1,200 @@
import logging
import os
import subprocess
import threading
import zipfile
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()
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(job_id=subjob_id) or []
# Simple thread to generate thumbs in background
def generate_thumb_thread(source):
in_progress_path = thumb_video_path + '_IN-PROGRESS'
subprocess.run(['touch', in_progress_path])
try:
logger.debug(f"Generating video thumbnail for {source}")
generate_thumbnail(source_path=source, dest_path=thumb_video_path, max_width=max_width)
except subprocess.CalledProcessError as err:
logger.error(f"Error generating video thumbnail for {source}: {err}")
for subjob_filename in subjob_files:
if subjob_filename not in local_files:
try:
logger.debug(f"Downloading new file '{subjob_filename}' from {subjob_hostname}")
local_save_path = os.path.join(os.path.dirname(local_job.output_path), subjob_filename)
subjob_proxy.download_job_file(job_id=subjob_id, job_filename=subjob_filename,
save_path=local_save_path)
logger.debug(f'Downloaded successfully - {local_save_path}')
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
source_files = job.file_list() or [job.input_path]
if source_files:
video_formats = ['.mp4', '.mov', '.avi', '.mpg', '.mpeg', '.mxf', '.m4v', 'mkv']
image_formats = ['.jpg', '.png', '.exr']
def download_all_from_subjob(local_job, subjob_id, subjob_hostname):
"""
Downloads and extracts files from a completed subjob on a remote server.
image_files = [f for f in source_files if os.path.splitext(f)[-1].lower() in image_formats]
video_files = [f for f in source_files if os.path.splitext(f)[-1].lower() in video_formats]
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.
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:
path_of_source = image_files[0] if image_files else video_files[0]
logger.debug(f"Generating image thumbnail for {path_of_source}")
save_first_frame(source_path=path_of_source, dest_path=thumb_image_path, max_width=max_width)
except Exception as e:
logger.error(f"Exception saving first frame: {e}")
benchmark = requests.get(f'http://{server["hostname"]}:{ZeroconfServer.server_port}'
f'/api/cpu_benchmark', timeout=15).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}')
if video_files and not os.path.exists(thumb_video_path):
x = threading.Thread(target=generate_thumb_thread, args=(video_files[0],))
x.start()
# 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
+136 -56
View File
@@ -1,86 +1,166 @@
import logging
import socket
from typing import Dict, List, Optional
from zeroconf import Zeroconf, ServiceInfo, ServiceBrowser, ServiceStateChange
from pubsub import pub
from zeroconf import Zeroconf, ServiceInfo, ServiceBrowser, ServiceStateChange, NonUniqueNameException, \
NotRunningException
logger = logging.getLogger()
class ZeroconfServer:
service_type = None
server_name = None
server_port = None
server_ip = None
zeroconf = Zeroconf()
service_info = None
client_cache = {}
properties = {}
_default_instance: Optional['ZeroconfServer'] = None
service_type: Optional[str] = None
server_name: Optional[str] = None
server_port: Optional[int] = None
properties: Dict = {}
def __init__(self) -> None:
self.service_type: Optional[str] = None
self.server_name: Optional[str] = None
self.server_port: Optional[int] = None
self.server_ip: Optional[str] = None
self.zeroconf: Zeroconf = Zeroconf()
self.service_info: Optional[ServiceInfo] = None
self.client_cache: Dict = {}
self.properties: Dict = {}
def _configure(self, service_type: str, server_name: str, server_port: int) -> None:
self.service_type = service_type
self.server_name = server_name
self.server_port = server_port
try:
socket.gethostbyname(socket.gethostname())
except socket.gaierror:
self.stop()
def _start(self, listen_only: bool = False) -> None:
if not self.service_type:
raise RuntimeError("The 'configure' method must be run before starting the zeroconf server")
if not listen_only:
logger.debug("Starting zeroconf service")
self._register_service()
else:
logger.debug("Starting zeroconf service - Listen only mode")
self._browse_services()
def _stop(self) -> None:
logger.debug("Stopping zeroconf service")
self._unregister_service()
if self.zeroconf:
self.zeroconf.close()
def _register_service(self) -> None:
try:
self.server_ip = socket.gethostbyname(socket.gethostname())
info = ServiceInfo(
self.service_type,
f"{self.server_name}.{self.service_type}",
addresses=[socket.inet_aton(self.server_ip)],
port=self.server_port,
properties=self.properties,
)
self.service_info = info
self.zeroconf.register_service(info)
logger.info(f"Registered zeroconf service: {self.service_info.name}")
except (NonUniqueNameException, socket.gaierror) as e:
logger.error(f"Error establishing zeroconf: {e}")
def _unregister_service(self) -> None:
if self.service_info:
self.zeroconf.unregister_service(self.service_info)
logger.info(f"Unregistered zeroconf service: {self.service_info.name}")
self.service_info = None
def _browse_services(self) -> None:
ServiceBrowser(self.zeroconf, self.service_type, [self._on_service_discovered])
def _on_service_discovered(self, zeroconf, service_type, name, state_change) -> None:
try:
info = zeroconf.get_service_info(service_type, name)
hostname = name.split(f'.{self.service_type}')[0]
logger.debug(f"Zeroconf: {hostname} {state_change}")
if service_type == self.service_type:
if state_change in (ServiceStateChange.Added, ServiceStateChange.Updated):
self.client_cache[hostname] = info
else:
self.client_cache.pop(hostname, None)
pub.sendMessage('zeroconf_state_change', hostname=hostname, state_change=state_change)
except NotRunningException:
pass
@classmethod
def _sync_class(cls) -> None:
if cls._default_instance is not None:
inst = cls._default_instance
cls.service_type = inst.service_type
cls.server_name = inst.server_name
cls.server_port = inst.server_port
cls.server_ip = inst.server_ip
cls.properties = inst.properties
def _found_hostnames(self) -> List[str]:
local_hostname = socket.gethostname()
def sort_key(hostname):
return False if hostname == local_hostname else True
sorted_hostnames = sorted(self.client_cache.keys(), key=sort_key)
return sorted_hostnames
def _get_hostname_properties(self, hostname: str) -> Dict:
server_info = self.client_cache.get(hostname)
if server_info is None:
return {}
decoded_server_info = {key.decode('utf-8'): value.decode('utf-8') for key, value in server_info.properties.items()}
return decoded_server_info
# --- Forwarders for backward compatibility ---
@classmethod
def configure(cls, service_type, server_name, server_port):
cls.service_type = service_type
cls.server_name = server_name
cls.server_port = server_port
if cls._default_instance is not None:
cls._default_instance._configure(service_type, server_name, server_port)
cls._sync_class()
@classmethod
def start(cls, listen_only=False):
if not listen_only:
cls._register_service()
cls._browse_services()
if cls._default_instance is not None:
cls._default_instance._start(listen_only)
@classmethod
def stop(cls):
cls._unregister_service()
cls.zeroconf.close()
if cls._default_instance is not None:
cls._default_instance._stop()
@classmethod
def _register_service(cls):
cls.server_ip = socket.gethostbyname(socket.gethostname())
info = ServiceInfo(
cls.service_type,
f"{cls.server_name}.{cls.service_type}",
addresses=[socket.inet_aton(cls.server_ip)],
port=cls.server_port,
properties=cls.properties,
)
cls.service_info = info
cls.zeroconf.register_service(info)
logger.info(f"Registered zeroconf service: {cls.service_info.name}")
def found_hostnames(cls):
if cls._default_instance is not None:
return cls._default_instance._found_hostnames()
return []
@classmethod
def _unregister_service(cls):
if cls.service_info:
cls.zeroconf.unregister_service(cls.service_info)
logger.info(f"Unregistered zeroconf service: {cls.service_info.name}")
cls.service_info = None
@classmethod
def _browse_services(cls):
browser = ServiceBrowser(cls.zeroconf, cls.service_type, [cls._on_service_discovered])
browser.is_alive()
@classmethod
def _on_service_discovered(cls, zeroconf, service_type, name, state_change):
info = zeroconf.get_service_info(service_type, name)
logger.debug(f"Zeroconf: {name} {state_change}")
if service_type == cls.service_type:
if state_change == ServiceStateChange.Added or state_change == ServiceStateChange.Updated:
cls.client_cache[name] = info
else:
cls.client_cache.pop(name)
@classmethod
def found_clients(cls):
return [x.split(f'.{cls.service_type}')[0] for x in cls.client_cache.keys()]
def get_hostname_properties(cls, hostname):
if cls._default_instance is not None:
return cls._default_instance._get_hostname_properties(hostname)
return {}
# Example usage:
if __name__ == "__main__":
import time
logging.basicConfig(level=logging.DEBUG)
ZeroconfServer.configure("_zordon._tcp.local.", "foobar.local", 8080)
try:
ZeroconfServer.start()
input("Server running - Press enter to end")
while True:
time.sleep(0.1)
except KeyboardInterrupt:
pass
finally:
ZeroconfServer.stop()
+8
View File
@@ -0,0 +1,8 @@
APP_NAME = "Zordon"
APP_VERSION = "0.8.0"
APP_AUTHOR = "Brett Williams"
APP_DESCRIPTION = "Distributed Render Farm Tools"
APP_COPYRIGHT_YEAR = "2026"
APP_LICENSE = "MIT License"
APP_REPO_NAME = APP_NAME
APP_REPO_OWNER = "blw1138"
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Some files were not shown because too many files have changed in this diff Show More