From 74c74dc97d53d52536a82c2591102534aafb1d57 Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Tue, 27 Jul 2021 15:13:31 +0200 Subject: [PATCH 1/6] Settings: adding workfile tool start attribute --- .../defaults/project_settings/global.json | 7 ++++ .../schemas/schema_global_tools.json | 32 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/openpype/settings/defaults/project_settings/global.json b/openpype/settings/defaults/project_settings/global.json index 43053c38c07..636acc0d17a 100644 --- a/openpype/settings/defaults/project_settings/global.json +++ b/openpype/settings/defaults/project_settings/global.json @@ -260,6 +260,13 @@ "enabled": true } ], + "open_workfile_tool_on_startup": [ + { + "hosts": [], + "tasks": [], + "enabled": false + } + ], "sw_folders": { "compositing": [ "nuke", diff --git a/openpype/settings/entities/schemas/projects_schema/schemas/schema_global_tools.json b/openpype/settings/entities/schemas/projects_schema/schemas/schema_global_tools.json index 8c92a45a569..a9fe27c24b0 100644 --- a/openpype/settings/entities/schemas/projects_schema/schemas/schema_global_tools.json +++ b/openpype/settings/entities/schemas/projects_schema/schemas/schema_global_tools.json @@ -97,6 +97,38 @@ ] } }, + { + "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", + "key": "hosts", + "label": "Hosts", + "multiselection": true + }, + { + "key": "tasks", + "label": "Tasks", + "type": "list", + "object_type": "text" + }, + { + "type": "splitter" + }, + { + "type": "boolean", + "key": "enabled", + "label": "Enabled" + } + ] + } + }, { "type": "dict-modifiable", "collapsible": true, From 08b0b3035a02d1a41274a8b0e9b4f64f419b5434 Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Tue, 27 Jul 2021 15:14:03 +0200 Subject: [PATCH 2/6] global: adding workfile start at launch attribute search func --- openpype/lib/applications.py | 119 +++++++++++++++++++++++++---------- 1 file changed, 86 insertions(+), 33 deletions(-) diff --git a/openpype/lib/applications.py b/openpype/lib/applications.py index e1b304a3518..01bc0cddf87 100644 --- a/openpype/lib/applications.py +++ b/openpype/lib/applications.py @@ -1302,10 +1302,18 @@ def _prepare_last_workfile(data, workdir): ) data["start_last_workfile"] = start_last_workfile + workfile_startup = should_workfile_tool_start( + 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"]["WORKFILE_STARTUP"] = ( + str(int(bool(workfile_startup))) + ) _sub_msg = "" if start_last_workfile else " not" log.debug( @@ -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_preset( + 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() @@ -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_preset( + 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 + `WORKFILE_STARTUP`, 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"] + ["open_workfile_tool_on_startup"] + ) + + if not startup_presets: + return default_output + + return get_option_from_preset( + 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() From d23f31da7edf5723d571a774e200f0056bbb0032 Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Tue, 27 Jul 2021 15:14:22 +0200 Subject: [PATCH 3/6] Nuke: refactory workfile launch callback --- openpype/hosts/nuke/api/lib.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/openpype/hosts/nuke/api/lib.py b/openpype/hosts/nuke/api/lib.py index eefbcc5d204..fce92f08d51 100644 --- a/openpype/hosts/nuke/api/lib.py +++ b/openpype/hosts/nuke/api/lib.py @@ -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="WORKFILE_STARTUP", + default=None) # return if none is defined if not open_at_start: From 6a2bd167b5fdadf6283dbfdbc783cb44c1efbab4 Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Wed, 28 Jul 2021 14:08:41 +0200 Subject: [PATCH 4/6] global: better env var name --- openpype/lib/applications.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/openpype/lib/applications.py b/openpype/lib/applications.py index 01bc0cddf87..ada194f15f1 100644 --- a/openpype/lib/applications.py +++ b/openpype/lib/applications.py @@ -1311,7 +1311,7 @@ def _prepare_last_workfile(data, workdir): data["env"]["AVALON_OPEN_LAST_WORKFILE"] = ( str(int(bool(start_last_workfile))) ) - data["env"]["WORKFILE_STARTUP"] = ( + data["env"]["OPENPYPE_WORKFILE_TOOL_ON_START"] = ( str(int(bool(workfile_startup))) ) @@ -1352,7 +1352,7 @@ def _prepare_last_workfile(data, workdir): data["last_workfile_path"] = last_workfile_path -def get_option_from_preset( +def get_option_from_settings( startup_presets, host_name, task_name, default_output ): host_name_lowered = host_name.lower() @@ -1432,7 +1432,7 @@ def should_start_last_workfile( if not startup_presets: return default_output - return get_option_from_preset( + return get_option_from_settings( startup_presets, host_name, task_name, default_output) @@ -1442,7 +1442,7 @@ def should_workfile_tool_start( """Define if host should start workfile tool at host launch. Default output is `False`. Can be overriden with environment variable - `WORKFILE_STARTUP`, valid values without case sensitivity are + `OPENPYPE_WORKFILE_TOOL_ON_START`, valid values without case sensitivity are `"0", "1", "true", "false", "yes", "no"`. Args: @@ -1470,7 +1470,7 @@ def should_workfile_tool_start( if not startup_presets: return default_output - return get_option_from_preset( + return get_option_from_settings( startup_presets, host_name, task_name, default_output) From 95b7ee57ec0952c6bcaa829ec63ab0d36bb6032a Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Wed, 28 Jul 2021 14:09:11 +0200 Subject: [PATCH 5/6] settings: add filter to host which are supported now --- .../schemas/projects_schema/schemas/schema_global_tools.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/openpype/settings/entities/schemas/projects_schema/schemas/schema_global_tools.json b/openpype/settings/entities/schemas/projects_schema/schemas/schema_global_tools.json index 211a8d00579..9e39eeb39e7 100644 --- a/openpype/settings/entities/schemas/projects_schema/schemas/schema_global_tools.json +++ b/openpype/settings/entities/schemas/projects_schema/schemas/schema_global_tools.json @@ -125,7 +125,10 @@ "type": "hosts-enum", "key": "hosts", "label": "Hosts", - "multiselection": true + "multiselection": true, + "hosts_filter": [ + "nuke" + ] }, { "key": "tasks", From 9f018cb6fb840551fbb084eb263b3cf96dc00a94 Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Wed, 28 Jul 2021 14:09:29 +0200 Subject: [PATCH 6/6] nuke: improving env var name --- openpype/hosts/nuke/api/lib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openpype/hosts/nuke/api/lib.py b/openpype/hosts/nuke/api/lib.py index 442c0122be6..7e7cd27f902 100644 --- a/openpype/hosts/nuke/api/lib.py +++ b/openpype/hosts/nuke/api/lib.py @@ -1665,7 +1665,7 @@ def launch_workfiles_app(): ) # get all imortant settings open_at_start = env_value_to_bool( - env_key="WORKFILE_STARTUP", + env_key="OPENPYPE_WORKFILE_TOOL_ON_START", default=None) # return if none is defined