From 963133bd59f81cdd5d45f83470778f68bdc5adec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Tue, 25 Jun 2024 12:11:20 +0200 Subject: [PATCH] Add-on: allow scripted job submissions from Blender The `bpy.ops.flamenco.submit_job(job_name="jobname")` operator can now be executed from Python. In that case, it will block the main thread until the job submission is complete. --- CHANGELOG.md | 1 + addon/flamenco/operators.py | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef5bf445..329bcec8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ bugs in actually-released versions. - Add `label` to job settings, to have full control over how they are presented in Blender's job submission GUI. If a job setting does not define a label, its `key` is used to generate one (like Flamenco 3.5 and older). - Add `shellSplit(someString)` function to the job compiler scripts. This splits a string into an array of strings using shell/CLI semantics. +- Make it possible to script job submissions in Blender, by executing the `bpy.ops.flamenco.submit_job(job_name="jobname")` operator. ## 3.5 - released 2024-04-16 diff --git a/addon/flamenco/operators.py b/addon/flamenco/operators.py index cb5ca1fc..31760796 100644 --- a/addon/flamenco/operators.py +++ b/addon/flamenco/operators.py @@ -128,6 +128,32 @@ class FLAMENCO_OT_submit_job(FlamencoOpMixin, bpy.types.Operator): job_type = job_types.active_job_type(context.scene) return job_type is not None + def execute(self, context: bpy.types.Context) -> set[str]: + filepath, ok = self._presubmit_check(context) + if not ok: + return {"CANCELLED"} + + is_running = self._submit_files(context, filepath) + if not is_running: + return {"CANCELLED"} + + if self.packthread is None: + # If there is no pack thread running, there isn't much we can do. + return self._quit(context) + + # Keep handling messages from the background thread. + while True: + # Block for 5 seconds at a time. The exact duration doesn't matter, + # as this while-loop is blocking the main thread anyway. + msg = self.packthread.poll(timeout=5) + if not msg: + # No message received, is fine, just wait for another one. + continue + + result = self._on_bat_pack_msg(context, msg) + if "RUNNING_MODAL" not in result: + return result + def invoke(self, context: bpy.types.Context, event: bpy.types.Event) -> set[str]: filepath, ok = self._presubmit_check(context) if not ok: