Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/new hook - Create directories through create_filesystem_structure. #128

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
40 changes: 40 additions & 0 deletions hooks/file_action.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright (c) 2015 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.

"""
Hook that creates folders if needed
"""

import sgtk

HookBaseClass = sgtk.get_hook_baseclass()


class FileAction(HookBaseClass):
"""
Implementation of the FileAction class
"""

def create_folders(self, context):
"""Create folders on the disk.

:param context: The context for which we need to create folders
:type context: sgtk.Context
"""

ctx_entity = context.task or context.entity or context.project

self.logger.info("Creating filesystem structure...")
self.parent.sgtk.create_filesystem_structure(
ctx_entity.get("type"),
ctx_entity.get("id"),
engine=self.parent.engine.instance_name,
)
self.logger.info("Filesystem structure created.")
9 changes: 7 additions & 2 deletions info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ configuration:
description: Contains methods to retrieve custom user login and push user data when a
work file is saved.

file_action_hook:
type: hook
default_value: "{self}/file_action.py"
description: Hook which creates folders on disk.

# General preferences
#
entities:
Expand All @@ -137,8 +142,8 @@ configuration:
*filters* a list of standard ShotGrid API filters, *hierarchy* a list of fields defining
the grouping in the sub-tree.
The optional *step_filter_on* setting is an Entity type and can be used to restrict
the list of Steps used for filtering to only the Steps for the specified Entity type.
"
the list of Steps used for filtering to only the Steps for the specified Entity type."

# For backward compatibility reasons we don't use the new deferred queries
# by default. Using deferred queries, an Asset/Shot setup could be:
# - caption: Assets (deferred)
Expand Down
16 changes: 7 additions & 9 deletions python/tk_multi_workfiles/actions/file_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ def create_folders(ctx):
# create folders:
QtGui.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor)
try:
# (AD) - does this work with non-standard hierarchies? e.g. /Task/Entity?
ctx_entity = ctx.task or ctx.entity or ctx.project

# FIXME: The launcher uses the defer_keyword setting, which allows to use keywords other
# than the engine instance name, which is the default value in the launch app. Using
# engine.instance_name is the best we can do at the moment because the is no way for workfiles
Expand All @@ -51,13 +48,14 @@ def create_folders(ctx):
# - Look for the settings of the launcher app in the destination context and extract the
# defer_keyword setting and reuse it.
#
# It may very well be that there's no solution that fits everyone and might warrant
# a hook.
app.sgtk.create_filesystem_structure(
ctx_entity.get("type"),
ctx_entity.get("id"),
engine=app.engine.instance_name,
app.execute_hook_method(
"file_action_hook",
"create_folders",
context=ctx,
)
except:
app.log_exception("Failed to execute custom file action!")

finally:
QtGui.QApplication.restoreOverrideCursor()

Expand Down