Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Workfile tool start at host launch support #1865

Merged
merged 7 commits into from
Jul 29, 2021
Merged
Show file tree
Hide file tree
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
10 changes: 7 additions & 3 deletions openpype/hosts/nuke/api/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1660,9 +1660,13 @@ def find_free_space_to_paste_nodes(
def launch_workfiles_app():
'''Function letting start workfiles after start of host
'''
# get state from settings
open_at_start = get_current_project_settings()["nuke"].get(
"general", {}).get("open_workfile_at_start")
from openpype.lib import (
env_value_to_bool
)
# get all imortant settings
open_at_start = env_value_to_bool(
env_key="OPENPYPE_WORKFILE_TOOL_ON_START",
default=None)

# return if none is defined
if not open_at_start:
Expand Down
119 changes: 86 additions & 33 deletions openpype/lib/applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -1302,10 +1302,18 @@ def _prepare_last_workfile(data, workdir):
)
data["start_last_workfile"] = start_last_workfile

workfile_startup = should_workfile_tool_start(
iLLiCiTiT marked this conversation as resolved.
Show resolved Hide resolved
project_name, app.host_name, task_name
)
data["workfile_startup"] = workfile_startup

# Store boolean as "0"(False) or "1"(True)
data["env"]["AVALON_OPEN_LAST_WORKFILE"] = (
str(int(bool(start_last_workfile)))
)
data["env"]["OPENPYPE_WORKFILE_TOOL_ON_START"] = (
str(int(bool(workfile_startup)))
)

_sub_msg = "" if start_last_workfile else " not"
log.debug(
Expand Down Expand Up @@ -1344,40 +1352,9 @@ def _prepare_last_workfile(data, workdir):
data["last_workfile_path"] = last_workfile_path


def should_start_last_workfile(
project_name, host_name, task_name, default_output=False
def get_option_from_settings(
startup_presets, host_name, task_name, default_output
):
"""Define if host should start last version workfile if possible.

Default output is `False`. Can be overriden with environment variable
`AVALON_OPEN_LAST_WORKFILE`, valid values without case sensitivity are
`"0", "1", "true", "false", "yes", "no"`.

Args:
project_name (str): Name of project.
host_name (str): Name of host which is launched. In avalon's
application context it's value stored in app definition under
key `"application_dir"`. Is not case sensitive.
task_name (str): Name of task which is used for launching the host.
Task name is not case sensitive.

Returns:
bool: True if host should start workfile.

"""

project_settings = get_project_settings(project_name)
startup_presets = (
project_settings
["global"]
["tools"]
["Workfiles"]
["last_workfile_on_startup"]
)

if not startup_presets:
return default_output

host_name_lowered = host_name.lower()
task_name_lowered = task_name.lower()

Expand Down Expand Up @@ -1421,6 +1398,82 @@ def should_start_last_workfile(
return default_output


def should_start_last_workfile(
project_name, host_name, task_name, default_output=False
):
"""Define if host should start last version workfile if possible.

Default output is `False`. Can be overriden with environment variable
`AVALON_OPEN_LAST_WORKFILE`, valid values without case sensitivity are
`"0", "1", "true", "false", "yes", "no"`.

Args:
project_name (str): Name of project.
host_name (str): Name of host which is launched. In avalon's
application context it's value stored in app definition under
key `"application_dir"`. Is not case sensitive.
task_name (str): Name of task which is used for launching the host.
Task name is not case sensitive.

Returns:
bool: True if host should start workfile.

"""

project_settings = get_project_settings(project_name)
startup_presets = (
project_settings
["global"]
["tools"]
["Workfiles"]
["last_workfile_on_startup"]
)

if not startup_presets:
return default_output

return get_option_from_settings(
startup_presets, host_name, task_name, default_output)


def should_workfile_tool_start(
project_name, host_name, task_name, default_output=False
):
"""Define if host should start workfile tool at host launch.

Default output is `False`. Can be overriden with environment variable
`OPENPYPE_WORKFILE_TOOL_ON_START`, valid values without case sensitivity are
jakubjezek001 marked this conversation as resolved.
Show resolved Hide resolved
`"0", "1", "true", "false", "yes", "no"`.

Args:
project_name (str): Name of project.
host_name (str): Name of host which is launched. In avalon's
application context it's value stored in app definition under
key `"application_dir"`. Is not case sensitive.
task_name (str): Name of task which is used for launching the host.
Task name is not case sensitive.

Returns:
bool: True if host should start workfile.

"""

project_settings = get_project_settings(project_name)
startup_presets = (
project_settings
["global"]
["tools"]
["Workfiles"]
["open_workfile_tool_on_startup"]
)

if not startup_presets:
return default_output

return get_option_from_settings(
startup_presets, host_name, task_name, default_output)


def compile_list_of_regexes(in_list):
"""Convert strings in entered list to compiled regex objects."""
regexes = list()
Expand Down
7 changes: 7 additions & 0 deletions openpype/settings/defaults/project_settings/global.json
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,13 @@
"enabled": true
}
],
"open_workfile_tool_on_startup": [
{
"hosts": [],
"tasks": [],
"enabled": false
}
],
"sw_folders": {
"compositing": [
"nuke",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,41 @@
]
}
},
{
"type": "list",
"key": "open_workfile_tool_on_startup",
"label": "Open workfile tool on launch",
"is_group": true,
"use_label_wrap": true,
"object_type": {
"type": "dict",
"children": [
{
"type": "hosts-enum",
jakubjezek001 marked this conversation as resolved.
Show resolved Hide resolved
"key": "hosts",
"label": "Hosts",
"multiselection": true,
"hosts_filter": [
"nuke"
]
},
{
"key": "tasks",
"label": "Tasks",
"type": "list",
"object_type": "text"
},
{
"type": "splitter"
},
{
"type": "boolean",
"key": "enabled",
"label": "Enabled"
}
]
}
},
{
"type": "dict-modifiable",
"collapsible": true,
Expand Down