separate the startup script logic from workfile hook

This commit is contained in:
Jakub Jezek 2023-06-27 11:36:13 +02:00
parent 8b5722c0a2
commit 3e9ac5935d
No known key found for this signature in database
GPG key ID: 730D7C02726179A7
2 changed files with 29 additions and 19 deletions

View file

@ -1,23 +1,17 @@
import os
from openpype.lib import PreLaunchHook
import openpype.hosts.resolve
class ResolveLaunchLastWorkfile(PreLaunchHook):
class PreLaunchResolveLastWorkfile(PreLaunchHook):
"""Special hook to open last workfile for Resolve.
Checks 'start_last_workfile', if set to False, it will not open last
workfile. This property is set explicitly in Launcher.
"""
# Execute after workfile template copy
order = 10
app_groups = ["resolve"]
def execute(self):
self.set_startup_script()
if not self.data.get("start_last_workfile"):
self.log.info("It is set to not start last workfile on start.")
return
@ -32,17 +26,9 @@ class ResolveLaunchLastWorkfile(PreLaunchHook):
return
# Add path to launch environment for the startup script to pick up
self.log.info(f"Setting OPENPYPE_RESOLVE_OPEN_ON_LAUNCH to launch "
f"last workfile: {last_workfile}")
self.log.info(
"Setting OPENPYPE_RESOLVE_OPEN_ON_LAUNCH to launch "
f"last workfile: {last_workfile}"
)
key = "OPENPYPE_RESOLVE_OPEN_ON_LAUNCH"
self.launch_context.env[key] = last_workfile
def set_startup_script(self):
# Set the openpype prelaunch startup script path for easy access
# in the LUA .scriptlib code
op_resolve_root = os.path.dirname(openpype.hosts.resolve.__file__)
script_path = os.path.join(op_resolve_root, "startup.py")
key = "OPENPYPE_RESOLVE_STARTUP_SCRIPT"
self.launch_context.env[key] = script_path
self.log.info("Setting OPENPYPE_RESOLVE_STARTUP_SCRIPT to: "
f"{script_path}")

View file

@ -0,0 +1,24 @@
import os
from openpype.lib import PreLaunchHook
import openpype.hosts.resolve
class PreLaunchResolveStartup(PreLaunchHook):
"""Special hook to configure startup script.
"""
order = 11
app_groups = ["resolve"]
def execute(self):
# Set the openpype prelaunch startup script path for easy access
# in the LUA .scriptlib code
op_resolve_root = os.path.dirname(openpype.hosts.resolve.__file__)
script_path = os.path.join(op_resolve_root, "startup.py")
key = "OPENPYPE_RESOLVE_STARTUP_SCRIPT"
self.launch_context.env[key] = script_path
self.log.info(
f"Setting OPENPYPE_RESOLVE_STARTUP_SCRIPT to: {script_path}"
)