Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove submitter dependencies that aren't available in KeyShot Python #111

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 32 additions & 9 deletions src/deadline/keyshot_submitter/Submit to AWS Deadline Cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@
import json
import os
import platform
import shlex
import shutil
import subprocess
import tempfile
import glob
from dataclasses import dataclass
from pathlib import Path
from typing import Any, Optional, Tuple

import lux
Expand Down Expand Up @@ -279,9 +276,14 @@ def dump_json_to_dir(contents: dict, directory: str, filename: str) -> None:
file.write(json.dumps(contents))


def substitute_suffix(path: str, suffix: str) -> str:
root, _ext = os.path.splitext(path)
return root + suffix


def load_sticky_settings(scene_filename: str) -> Optional[dict]:
sticky_settings_filename = Path(scene_filename).with_suffix(RENDER_SUBMITTER_SETTINGS_FILE_EXT)
if sticky_settings_filename.exists() and sticky_settings_filename.is_file():
sticky_settings_filename = substitute_suffix(scene_filename, RENDER_SUBMITTER_SETTINGS_FILE_EXT)
if os.path.exists(sticky_settings_filename) and os.path.isfile(sticky_settings_filename):
try:
with open(sticky_settings_filename, encoding="utf8") as f:
return json.load(f)
Expand All @@ -297,7 +299,7 @@ def load_sticky_settings(scene_filename: str) -> Optional[dict]:


def save_sticky_settings(scene_file: str, settings: Settings):
sticky_settings_filename = Path(scene_file).with_suffix(RENDER_SUBMITTER_SETTINGS_FILE_EXT)
sticky_settings_filename = substitute_suffix(scene_file, RENDER_SUBMITTER_SETTINGS_FILE_EXT)
with open(sticky_settings_filename, "w", encoding="utf8") as f:
json.dump(settings.output_sticky_settings(), f, indent=2)

Expand All @@ -314,7 +316,7 @@ def gui_submit(bundle_directory: str) -> Optional[dict[str, Any]]:
shell_executable,
"-i",
"-c",
f'echo "START_DEADLINE_OUTPUT";deadline bundle gui-submit {shlex.quote(bundle_directory)} --output json',
f"echo \"START_DEADLINE_OUTPUT\";deadline bundle gui-submit '{bundle_directory}' --output json",
],
check=True,
capture_output=True,
Expand Down Expand Up @@ -401,9 +403,30 @@ def get_ksp_bundle_files(directory: str) -> Tuple[str, list[str]]:

ksp_dir = os.path.join(directory, "ksp")
unpack_dir = os.path.join(directory, "unpack")
ksp_archive = save_ksp_bundle(ksp_dir, "temp_deadline_cloud.zip")
if platform.system() == "Darwin" or platform.system() == "Linux":
subprocess.run(
["unzip", ksp_archive, "-d", unpack_dir],
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
else:
subprocess.run(
[
"PowerShell",
"-Command",
"Expand-Archive",
"-Path",
ksp_archive,
"-DestinationPath",
unpack_dir,
],
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)

ksp_archive = save_ksp_bundle(ksp_dir, "temp_deadline_cloud.ksp")
shutil.unpack_archive(ksp_archive, unpack_dir, "zip")
input_filenames = [
os.path.join(unpack_dir, file)
for file in os.listdir(unpack_dir)
Expand Down