Skip to content

Commit

Permalink
[SKB-2333] New 'pre_publish' hook to run before showing publish dialog (
Browse files Browse the repository at this point in the history
  • Loading branch information
staceyoue authored Nov 5, 2020
1 parent 4c3243b commit fad5fa4
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 2 deletions.
7 changes: 7 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class MultiPublish2(sgtk.platform.Application):
top-level publish2 interface.
"""

CONFIG_PRE_PUBLISH_HOOK_PATH = "pre_publish"

def init_app(self):
"""
Called as the application is being initialized
Expand All @@ -44,6 +46,11 @@ def init_app(self):
# replace all non alphanumeric characters by '_'
command_name = re.sub(r"[^0-9a-zA-Z]+", "_", command_name)

self.modal = self.get_setting("modal")

pre_publish_hook_path = self.get_setting(self.CONFIG_PRE_PUBLISH_HOOK_PATH)
self.pre_publish_hook = self.create_hook_instance(pre_publish_hook_path)

# register command
cb = lambda: tk_multi_publish2.show_dialog(self)
menu_caption = "%s..." % display_name
Expand Down
29 changes: 29 additions & 0 deletions hooks/pre_publish.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (c) 2018 Shotgun Software Inc.
#
# CONFIDENTIAL AND PROPRIETARY
#
# This work is provided "AS IS" and subject to the Shotgun Pipeline Toolkit
# Source Code License included in this distribution package. See LICENSE.
# By accessing, using, copying or modifying this work you indicate your
# agreement to the Shotgun Pipeline Toolkit Source Code License. All rights
# not expressly granted therein are reserved by Shotgun Software Inc.

import sgtk

HookBaseClass = sgtk.get_hook_baseclass()


class PrePublishHook(HookBaseClass):
"""
This hook defines logic to be executed before showing the publish
dialog. There may be conditions that need to be checked before allowing
the user to proceed to publishing.
"""

def validate(self):
"""
Returns True if the user can proceed to publish. Override thsi hook
method to execute any custom validation steps.
"""

return True
16 changes: 16 additions & 0 deletions info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ configuration:
identification, publish display name, image sequence paths, etc."
default_value: "{self}/path_info.py"

pre_publish:
type: hook
description:
"This hook defines logic to be executed before showing the publish
dialog. There may be conditions that need to be checked before allowing
the user to proceed to publishing."
default_value: "{self}/pre_publish.py"

task_required:
type: bool
description:
Expand Down Expand Up @@ -110,6 +118,14 @@ configuration:
buttons to select files or folders. When false, the feature basically
disable the user ability to add anything to the project."

modal:
type: bool
default_value: false
description:
"If true the app dialog will be opened in modal window mode, else if
false (default) the dialog will be opened in non-modal window mode."


# the Shotgun fields that this app needs in order to operate correctly
requires_shotgun_fields:

Expand Down
13 changes: 11 additions & 2 deletions python/tk_multi_publish2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,14 @@ def show_dialog(app):

display_name = sgtk.platform.current_bundle().get_setting("display_name")

# start ui
app.engine.show_dialog(display_name, app, AppDialog)
if app.pre_publish_hook.validate():
# start ui
if app.modal:
app.engine.show_modal(display_name, app, AppDialog)
else:
app.engine.show_dialog(display_name, app, AppDialog)
else:
app.logger.debug(
"%s validate returned False -- abort publish."
% app.pre_publish_hook.__class__.__name__
)

1 comment on commit fad5fa4

@reformstudios
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@staceyoue Sorry to chip in here, but it occurred to me that calling this a "pre-publish" hook isn't the correct name to use. Historically(tk-multi-publish), pre-publish was the step AFTER collection. This hook would be more accurately labelled "pre-collection".
Publish doesn't occur after this hook; there's collection, validation, THEN publish.

Please sign in to comment.