Add-on: Skip BAT-packing when file already in shared storage

When the to-be-submitted blend file is already stored in the shared
storage, and Shaman is disabled, the add-on now skips BAT-packing it.
Instead, the file is copied to `filename.flamenco.blend` and the path is
submitted as-is.
This commit is contained in:
Sybren A. Stüvel 2022-07-21 14:18:48 +02:00
parent a6e3442aa0
commit 344a62f37b
2 changed files with 36 additions and 2 deletions

View File

@ -5,6 +5,7 @@ from typing import TYPE_CHECKING, Optional, Union
import bpy
from .job_types_propgroup import JobTypePropertyGroup
from . import preferences
if TYPE_CHECKING:
from .manager import ApiClient as _ApiClient
@ -84,3 +85,22 @@ def submit_job(job: _SubmittedJob, api_client: _ApiClient) -> _Job:
print("Job submitted: %s (%s)" % (response.name, response.id))
return response
def is_file_inside_job_storage(context: bpy.types.Context, blendfile: Path) -> bool:
"""Check whether current blend file is inside the storage path.
:return: True when the current blend file is inside the Flamenco job storage
directory already. In this case it won't be BAT-packed, as it's assumed
the job storage dir is accessible by the workers already.
"""
blendfile = blendfile.absolute().resolve()
prefs = preferences.get(context)
job_storage = Path(prefs.job_storage).absolute().resolve()
try:
blendfile.relative_to(job_storage)
except ValueError:
return False
return True

View File

@ -170,7 +170,7 @@ class FLAMENCO_OT_submit_job(FlamencoOpMixin, bpy.types.Operator):
self.report({"ERROR"}, "Unable to create job")
return {"CANCELLED"}
return self._bat_pack(context, filepath)
return self._submit_files(context, filepath)
def modal(self, context: bpy.types.Context, event: bpy.types.Event) -> set[str]:
# This function is called for TIMER events to poll the BAT pack thread.
@ -225,7 +225,9 @@ class FLAMENCO_OT_submit_job(FlamencoOpMixin, bpy.types.Operator):
return filepath
def _bat_pack(self, context: bpy.types.Context, blendfile: Path) -> set[str]:
def _submit_files(self, context: bpy.types.Context, blendfile: Path) -> set[str]:
"""Ensure that the files are somewhere in the shared storage."""
from .bat import interface as bat_interface
if bat_interface.is_packing():
@ -239,6 +241,8 @@ class FLAMENCO_OT_submit_job(FlamencoOpMixin, bpy.types.Operator):
# see _on_bat_pack_msg() below.
self.blendfile_on_farm = None
self._bat_pack_shaman(context, blendfile)
elif job_submission.is_file_inside_job_storage(context, blendfile):
self._use_blendfile_directly(context, blendfile)
else:
self.blendfile_on_farm = self._bat_pack_filesystem(context, blendfile)
@ -352,6 +356,16 @@ class FLAMENCO_OT_submit_job(FlamencoOpMixin, bpy.types.Operator):
return {"RUNNING_MODAL"}
def _use_blendfile_directly(self, context: bpy.types.Context, blendfile: Path) -> None:
# The temporary '.flamenco.blend' file should not be deleted, as it
# will be used directly by the render job.
self.temp_blendfile = None
# The blend file is contained in the job storage path, no need to
# copy anything.
self.blendfile_on_farm = PurePosixPath(blendfile.absolute().resolve().as_posix())
self._submit_job(context)
def _submit_job(self, context: bpy.types.Context) -> None:
"""Use the Flamenco API to submit the new Job."""
assert self.job is not None