Skip to content

Commit

Permalink
Convert actions to tk-multi-loader2 schema
Browse files Browse the repository at this point in the history
Changing references of `sg_data` to `sg_publish_data`
  • Loading branch information
Ahuge committed Mar 11, 2021
1 parent a6659b4 commit 763afed
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 88 deletions.
38 changes: 19 additions & 19 deletions hooks/general_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class GeneralActions(HookBaseClass):
General Shotgun Panel Actions that apply to all DCCs
"""

def generate_actions(self, sg_data, actions, ui_area):
def generate_actions(self, sg_publish_data, actions, ui_area):
"""
Returns a list of action instances for a particular object.
The data returned from this hook will be used to populate the
Expand All @@ -37,15 +37,15 @@ def generate_actions(self, sg_data, actions, ui_area):
- If it will be shown in the main browsing area, "main" is passed.
- If it will be shown in the details area, "details" is passed.
:param sg_data: Shotgun data dictionary with a set of standard fields.
:param sg_publish_data: Shotgun data dictionary with a set of standard fields.
:param actions: List of action strings which have been defined in the app configuration.
:param ui_area: String denoting the UI Area (see above).
:returns List of dictionaries, each with keys name, params, caption, group and description
"""
app = self.parent
app.log_debug(
"Generate actions called for UI element %s. "
"Actions: %s. Shotgun Data: %s" % (ui_area, actions, sg_data)
"Actions: %s. Shotgun Data: %s" % (ui_area, actions, sg_publish_data)
)

action_instances = []
Expand Down Expand Up @@ -74,7 +74,7 @@ def generate_actions(self, sg_data, actions, ui_area):

if "quicktime_clipboard" in actions:

if sg_data.get("sg_path_to_movie"):
if sg_publish_data.get("sg_path_to_movie"):
# path to movie exists, so show the action
action_instances.append(
{
Expand All @@ -88,7 +88,7 @@ def generate_actions(self, sg_data, actions, ui_area):

if "sequence_clipboard" in actions:

if sg_data.get("sg_path_to_frames"):
if sg_publish_data.get("sg_path_to_frames"):
# path to frames exists, so show the action
action_instances.append(
{
Expand All @@ -102,7 +102,7 @@ def generate_actions(self, sg_data, actions, ui_area):

if "publish_clipboard" in actions:

if "path" in sg_data and sg_data["path"].get("local_path"):
if "path" in sg_publish_data and sg_publish_data["path"].get("local_path"):
# path field exists and the local path is populated
action_instances.append(
{
Expand All @@ -124,7 +124,7 @@ def generate_actions(self, sg_data, actions, ui_area):
playlists = self.parent.shotgun.find(
"Playlist",
[
["project", "is", sg_data.get("project")],
["project", "is", sg_publish_data.get("project")],
{
"filter_operator": "any",
"filters": [
Expand All @@ -139,7 +139,7 @@ def generate_actions(self, sg_data, actions, ui_area):
)

# playlists this version is already part of
existing_playlist_ids = [x["id"] for x in sg_data.get("playlists", [])]
existing_playlist_ids = [x["id"] for x in sg_publish_data.get("playlists", [])]

for playlist in playlists:
if playlist["id"] in existing_playlist_ids:
Expand Down Expand Up @@ -171,20 +171,20 @@ def generate_actions(self, sg_data, actions, ui_area):

return action_instances

def execute_action(self, name, params, sg_data):
def execute_action(self, name, params, sg_publish_data):
"""
Execute a given action. The data sent to this be method will
represent one of the actions enumerated by the generate_actions method.
:param name: Action name string representing one of the items returned by generate_actions.
:param params: Params data, as specified by generate_actions.
:param sg_data: Shotgun data dictionary
:param sg_publish_data: Shotgun data dictionary
:returns: No return value expected.
"""
app = self.parent
app.log_debug(
"Execute action called for action %s. "
"Parameters: %s. Shotgun Data: %s" % (name, params, sg_data)
"Parameters: %s. Shotgun Data: %s" % (name, params, sg_publish_data)
)

if name == "assign_task":
Expand All @@ -197,35 +197,35 @@ def execute_action(self, name, params, sg_data):
)

data = app.shotgun.find_one(
"Task", [["id", "is", sg_data["id"]]], ["task_assignees"]
"Task", [["id", "is", sg_publish_data["id"]]], ["task_assignees"]
)
assignees = data["task_assignees"] or []
assignees.append(app.context.user)
app.shotgun.update("Task", sg_data["id"], {"task_assignees": assignees})
app.shotgun.update("Task", sg_publish_data["id"], {"task_assignees": assignees})

elif name == "add_to_playlist":
app.shotgun.update(
"Version",
sg_data["id"],
sg_publish_data["id"],
{"playlists": [{"type": "Playlist", "id": params["playlist_id"]}]},
multi_entity_update_modes={"playlists": "add"},
)
self.logger.debug(
"Updated playlist %s to include version %s"
% (params["playlist_id"], sg_data["id"])
% (params["playlist_id"], sg_publish_data["id"])
)

elif name == "task_to_ip":
app.shotgun.update("Task", sg_data["id"], {"sg_status_list": "ip"})
app.shotgun.update("Task", sg_publish_data["id"], {"sg_status_list": "ip"})

elif name == "quicktime_clipboard":
self._copy_to_clipboard(sg_data["sg_path_to_movie"])
self._copy_to_clipboard(sg_publish_data["sg_path_to_movie"])

elif name == "sequence_clipboard":
self._copy_to_clipboard(sg_data["sg_path_to_frames"])
self._copy_to_clipboard(sg_publish_data["sg_path_to_frames"])

elif name == "publish_clipboard":
self._copy_to_clipboard(sg_data["path"]["local_path"])
self._copy_to_clipboard(sg_publish_data["path"]["local_path"])

def _copy_to_clipboard(self, text):
"""
Expand Down
26 changes: 13 additions & 13 deletions hooks/tk-3dsmaxplus_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class MaxActions(HookBaseClass):
Shotgun Panel Actions for 3dsMax
"""

def generate_actions(self, sg_data, actions, ui_area):
def generate_actions(self, sg_publish_data, actions, ui_area):
"""
Returns a list of action instances for a particular object.
The data returned from this hook will be used to populate the
Expand All @@ -38,7 +38,7 @@ def generate_actions(self, sg_data, actions, ui_area):
- If it will be shown in the main browsing area, "main" is passed.
- If it will be shown in the details area, "details" is passed.
:param sg_data: Shotgun data dictionary with all the standard shotgun fields.
:param sg_publish_data: Shotgun data dictionary with all the standard shotgun fields.
:param actions: List of action strings which have been defined in the app configuration.
:param ui_area: String denoting the UI Area (see above).
:returns List of dictionaries, each with keys name, params, caption and description
Expand All @@ -47,15 +47,15 @@ def generate_actions(self, sg_data, actions, ui_area):
app = self.parent
app.log_debug(
"Generate actions called for UI element %s. "
"Actions: %s. Shotgun Data: %s" % (ui_area, actions, sg_data)
"Actions: %s. Shotgun Data: %s" % (ui_area, actions, sg_publish_data)
)

action_instances = []

try:
# call base class first
action_instances += HookBaseClass.generate_actions(
self, sg_data, actions, ui_area
self, sg_publish_data, actions, ui_area
)
except AttributeError:
# base class doesn't have the method, so ignore and continue
Expand Down Expand Up @@ -93,25 +93,25 @@ def generate_actions(self, sg_data, actions, ui_area):

return action_instances

def execute_action(self, name, params, sg_data):
def execute_action(self, name, params, sg_publish_data):
"""
Execute a given action. The data sent to this be method will
represent one of the actions enumerated by the generate_actions method.
:param name: Action name string representing one of the items returned by generate_actions.
:param params: Params data, as specified by generate_actions.
:param sg_data: Shotgun data dictionary
:param sg_publish_data: Shotgun data dictionary
:returns: No return value expected.
"""
app = self.parent
app.log_debug(
"Execute action called for action %s. "
"Parameters: %s. Shotgun Data: %s" % (name, params, sg_data)
"Parameters: %s. Shotgun Data: %s" % (name, params, sg_publish_data)
)

if sg_data["type"] == sgtk.util.get_published_file_entity_type(self.sgtk):
if sg_publish_data["type"] == sgtk.util.get_published_file_entity_type(self.sgtk):
# resolve path
path = self.get_publish_path(sg_data)
path = self.get_publish_path(sg_publish_data)

# If this is an Alembic cache, then we can import that.
if name == "merge" and path.lower().endswith(".abc"):
Expand All @@ -127,14 +127,14 @@ def execute_action(self, name, params, sg_data):
)
return
elif name == "merge":
return self._merge(path, sg_data)
return self._merge(path, sg_publish_data)
elif name == "xref_scene":
return self._xref_scene(path, sg_data)
return self._xref_scene(path, sg_publish_data)
elif name == "texture_node":
return self._create_texture_node(path, sg_data)
return self._create_texture_node(path, sg_publish_data)

try:
HookBaseClass.execute_action(self, name, params, sg_data)
HookBaseClass.execute_action(self, name, params, sg_publish_data)
except AttributeError:
# base class doesn't have the method, so ignore and continue
pass
Expand Down
16 changes: 8 additions & 8 deletions hooks/tk-flame_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class FlameActions(HookBaseClass):
Shotgun Panel Actions for Flame
"""

def generate_actions(self, sg_data, actions, ui_area):
def generate_actions(self, sg_publish_data, actions, ui_area):
"""
Returns a list of action instances for a particular object.
The data returned from this hook will be used to populate the
Expand All @@ -36,48 +36,48 @@ def generate_actions(self, sg_data, actions, ui_area):
- If it will be shown in the main browsing area, "main" is passed.
- If it will be shown in the details area, "details" is passed.
:param sg_data: Shotgun data dictionary with all the standard publish fields.
:param sg_publish_data: Shotgun data dictionary with all the standard publish fields.
:param actions: List of action strings which have been defined in the app configuration.
:param ui_area: String denoting the UI Area (see above).
:returns List of dictionaries, each with keys name, params, caption and description
"""
app = self.parent
app.log_debug(
"Generate actions called for UI element %s. "
"Actions: %s. Shotgun Data: %s" % (ui_area, actions, sg_data)
"Actions: %s. Shotgun Data: %s" % (ui_area, actions, sg_publish_data)
)

action_instances = []

try:
# call base class first
action_instances += HookBaseClass.generate_actions(
self, sg_data, actions, ui_area
self, sg_publish_data, actions, ui_area
)
except AttributeError as e:
# base class doesn't have the method, so ignore and continue
pass

return action_instances

def execute_action(self, name, params, sg_data):
def execute_action(self, name, params, sg_publish_data):
"""
Execute a given action. The data sent to this be method will
represent one of the actions enumerated by the generate_actions method.
:param name: Action name string representing one of the items returned by generate_actions.
:param params: Params data, as specified by generate_actions.
:param sg_data: Shotgun data dictionary
:param sg_publish_data: Shotgun data dictionary
:returns: No return value expected.
"""
app = self.parent
app.log_debug(
"Execute action called for action %s. "
"Parameters: %s. Shotgun Data: %s" % (name, params, sg_data)
"Parameters: %s. Shotgun Data: %s" % (name, params, sg_publish_data)
)

try:
HookBaseClass.execute_action(self, name, params, sg_data)
HookBaseClass.execute_action(self, name, params, sg_publish_data)
except AttributeError as e:
# base class doesn't have the method, so ignore and continue
pass
24 changes: 12 additions & 12 deletions hooks/tk-houdini_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class HoudiniActions(HookBaseClass):
Shotgun Panel Actions for Maya
"""

def generate_actions(self, sg_data, actions, ui_area):
def generate_actions(self, sg_publish_data, actions, ui_area):
"""
Returns a list of action instances for a particular object.
The data returned from this hook will be used to populate the
Expand All @@ -41,23 +41,23 @@ def generate_actions(self, sg_data, actions, ui_area):
- If it will be shown in the main browsing area, "main" is passed.
- If it will be shown in the details area, "details" is passed.
:param sg_data: Shotgun data dictionary with all the standard shotgun fields.
:param sg_publish_data: Shotgun data dictionary with all the standard shotgun fields.
:param actions: List of action strings which have been defined in the app configuration.
:param ui_area: String denoting the UI Area (see above).
:returns List of dictionaries, each with keys name, params, caption and description
"""
app = self.parent
app.log_debug(
"Generate actions called for UI element %s. "
"Actions: %s. Publish Data: %s" % (ui_area, actions, sg_data)
"Actions: %s. Publish Data: %s" % (ui_area, actions, sg_publish_data)
)

action_instances = []

try:
# call base class first
action_instances += HookBaseClass.generate_actions(
self, sg_data, actions, ui_area
self, sg_publish_data, actions, ui_area
)
except AttributeError as e:
# base class doesn't have the method, so ignore and continue
Expand Down Expand Up @@ -94,37 +94,37 @@ def generate_actions(self, sg_data, actions, ui_area):

return action_instances

def execute_action(self, name, params, sg_data):
def execute_action(self, name, params, sg_publish_data):
"""
Execute a given action. The data sent to this be method will
represent one of the actions enumerated by the generate_actions method.
:param name: Action name string representing one of the items returned by generate_actions.
:param params: Params data, as specified by generate_actions.
:param sg_data: Shotgun data dictionary with all the standard publish fields.
:param sg_publish_data: Shotgun data dictionary with all the standard publish fields.
:returns: No return value expected.
"""
app = self.parent
app.log_debug(
"Execute action called for action %s. "
"Parameters: %s. Publish Data: %s" % (name, params, sg_data)
"Parameters: %s. Publish Data: %s" % (name, params, sg_publish_data)
)

# resolve path
path = self.get_publish_path(sg_data)
path = self.get_publish_path(sg_publish_data)

if name == "merge":
self._merge(path, sg_data)
self._merge(path, sg_publish_data)

elif name == "import":
self._import(path, sg_data)
self._import(path, sg_publish_data)

elif name == "file_cop":
self._file_cop(path, sg_data)
self._file_cop(path, sg_publish_data)

else:
try:
HookBaseClass.execute_action(self, name, params, sg_data)
HookBaseClass.execute_action(self, name, params, sg_publish_data)
except AttributeError as e:
# base class doesn't have the method, so ignore and continue
pass
Expand Down
Loading

0 comments on commit 763afed

Please sign in to comment.