Skip to content

Commit

Permalink
SHOT-3935 & SHOT-3936 updates to prevent Publish from files saved out…
Browse files Browse the repository at this point in the history
…side template. (#88)

* Jenkins Alias Python API master Build No. 15

* Jenkins Alias Python API PR-44 Build No. 2

* SHOT-3935 & SHOT-3936 updates to prevent Publish from files saved outside template.

* pre-commit hook clean-up.

Co-authored-by: Jenkins <[email protected]>
Co-authored-by: Stacey Oue <[email protected]>
  • Loading branch information
3 people authored Mar 2, 2022
1 parent 348dced commit 33976fd
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 109 deletions.
53 changes: 33 additions & 20 deletions engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,30 +528,43 @@ def get_parent_window():

def open_save_as_dialog(self):
"""
Launch a Qt file browser to select a file, then save the supplied
project to that path.
Try to open tk-multi-workfiles2 Save As... dialog if it exists otherwise
launch a Qt file browser for the Save As...
"""
open_dialog_func = None
kwargs = {}
workfiles = self.apps.get("tk-multi-workfiles2", None)

from sgtk.platform.qt import QtGui
if workfiles:
if hasattr(workfiles, "show_file_save_dlg"):
open_dialog_func = workfiles.show_file_save_dlg
kwargs["use_modal_dialog"] = True

# Alias doesn't appear to have a "save as" dialog accessible via
# python. so open our own Qt file dialog.
file_dialog = QtGui.QFileDialog(
parent=self.get_parent_window(),
caption="Save As",
directory=os.path.expanduser("~"),
filter="Alias file (*.wire)",
)
file_dialog.setLabelText(QtGui.QFileDialog.Accept, "Save")
file_dialog.setLabelText(QtGui.QFileDialog.Reject, "Cancel")
file_dialog.setOption(QtGui.QFileDialog.DontResolveSymlinks)
file_dialog.setOption(QtGui.QFileDialog.DontUseNativeDialog)
if not file_dialog.exec_():
return
path = file_dialog.selectedFiles()[0]
if open_dialog_func:
open_dialog_func(**kwargs)

else:
# Alias doesn't appear to have a "save as" dialog accessible via
# python. so open our own Qt file dialog.

from sgtk.platform.qt import QtGui

file_dialog = QtGui.QFileDialog(
parent=self.get_parent_window(),
caption="Save As",
directory=os.path.expanduser("~"),
filter="Alias file (*.wire)",
)
file_dialog.setLabelText(QtGui.QFileDialog.Accept, "Save")
file_dialog.setLabelText(QtGui.QFileDialog.Reject, "Cancel")
file_dialog.setOption(QtGui.QFileDialog.DontResolveSymlinks)
file_dialog.setOption(QtGui.QFileDialog.DontUseNativeDialog)
if not file_dialog.exec_():
return
path = file_dialog.selectedFiles()[0]

if os.path.splitext(path)[-1] != ".wire":
path = "{0}.wire".format(path)
if os.path.splitext(path)[-1] != ".wire":
path = "{0}.wire".format(path)

if path:
self.save_file_as(path)
Expand Down
40 changes: 9 additions & 31 deletions hooks/tk-multi-publish2/basic/publish_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ def accept(self, settings, item):
# provide a save button. the session will need to be saved before
# validation will succeed.
self.logger.warn(
"The Alias session has not been saved.", extra=_get_save_as_action()
"The Alias session has not been saved.",
extra=sgtk.platform.current_engine().open_save_as_dialog,
)

self.logger.info(
Expand Down Expand Up @@ -204,7 +205,9 @@ def validate(self, settings, item):
# the session still requires saving. provide a save button.
# validation fails.
error_msg = "The Alias session has not been saved."
self.logger.error(error_msg, extra=_get_save_as_action())
self.logger.error(
error_msg, extra=sgtk.platform.current_engine().open_save_as_dialog
)
raise Exception(error_msg)

# ---- check that references exist, display warning for invalid refs
Expand All @@ -229,19 +232,19 @@ def validate(self, settings, item):
work_template = item.properties.get("work_template")
if work_template:
if not work_template.validate(path):
error_msg = "The current session does not match the configured work file template."
self.logger.warning(
"The current session does not match the configured work "
"file template.",
error_msg,
extra={
"action_button": {
"label": "Save File",
"tooltip": "Save the current Alias session to a "
"different file name",
# will launch wf2 if configured
"callback": _get_save_as_action(),
"callback": sgtk.platform.current_engine().open_save_as_dialog,
}
},
)
raise Exception(error_msg)
else:
self.logger.debug("Work template configured and matches session file.")
else:
Expand Down Expand Up @@ -364,28 +367,3 @@ def _session_path():
"""

return alias_api.get_current_path()


def _get_save_as_action():
"""
Simple helper for returning a log action dict for saving the session
"""

engine = sgtk.platform.current_engine()

# default save callback
callback = engine.open_save_as_dialog

# if workfiles2 is configured, use that for file save
if "tk-multi-workfiles2" in engine.apps:
app = engine.apps["tk-multi-workfiles2"]
if hasattr(app, "show_file_save_dlg"):
callback = app.show_file_save_dlg

return {
"action_button": {
"label": "Save As...",
"tooltip": "Save the current session",
"callback": callback,
}
}
35 changes: 6 additions & 29 deletions hooks/tk-multi-publish2/basic/publish_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ def accept(self, settings, item):
# provide a save button. the session will need to be saved before
# validation will succeed.
self.logger.warn(
"The Alias session has not been saved.", extra=_get_save_as_action()
"The Alias session has not been saved.",
extra=sgtk.platform.current_engine().open_save_as_dialog,
)

self.logger.info(
Expand Down Expand Up @@ -202,7 +203,9 @@ def validate(self, settings, item):
# the session still requires saving. provide a save button.
# validation fails.
error_msg = "The Alias session has not been saved."
self.logger.error(error_msg, extra=_get_save_as_action())
self.logger.error(
error_msg, extra=sgtk.platform.current_engine().open_save_as_dialog
)
raise Exception(error_msg)

# ---- check the session against any attached work template
Expand All @@ -225,8 +228,7 @@ def validate(self, settings, item):
"label": "Save File",
"tooltip": "Save the current VRED session to a "
"different file name",
# will launch wf2 if configured
"callback": _get_save_as_action(),
"callback": sgtk.platform.current_engine().open_save_as_dialog,
}
},
)
Expand Down Expand Up @@ -478,28 +480,3 @@ def _session_path():
"""

return alias_api.get_current_path()


def _get_save_as_action():
"""
Simple helper for returning a log action dict for saving the session
"""

engine = sgtk.platform.current_engine()

# default save callback
callback = engine.open_save_as_dialog

# if workfiles2 is configured, use that for file save
if "tk-multi-workfiles2" in engine.apps:
app = engine.apps["tk-multi-workfiles2"]
if hasattr(app, "show_file_save_dlg"):
callback = app.show_file_save_dlg

return {
"action_button": {
"label": "Save As...",
"tooltip": "Save the current session",
"callback": callback,
}
}
37 changes: 8 additions & 29 deletions hooks/tk-multi-publish2/basic/start_version_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ def accept(self, settings, item):
# provide a save button. the session will need to be saved before
# validation will succeed.
self.logger.warn(
"The Alias session has not been saved.", extra=_get_save_as_action()
"The Alias session has not been saved.",
extra=sgtk.platform.current_engine().open_save_as_dialog,
)

self.logger.info(
Expand Down Expand Up @@ -167,7 +168,9 @@ def validate(self, settings, item):
# the session still requires saving. provide a save button.
# validation fails
error_msg = "The Alias session has not been saved."
self.logger.error(error_msg, extra=_get_save_as_action())
self.logger.error(
error_msg, extra=sgtk.platform.current_engine().open_save_as_dialog
)
raise Exception(error_msg)

# NOTE: If the plugin is attached to an item, that means no version
Expand All @@ -183,7 +186,9 @@ def validate(self, settings, item):
"A file already exists with a version number. Please "
"choose another name."
)
self.logger.error(error_msg, extra=_get_save_as_action())
self.logger.error(
error_msg, extra=sgtk.platform.current_engine().open_save_as_dialog
)
raise Exception(error_msg)

return True
Expand Down Expand Up @@ -274,32 +279,6 @@ def _session_path():
return alias_api.get_current_path()


def _get_save_as_action():
"""
Simple helper for returning a log action dict for saving the session
"""

engine = sgtk.platform.current_engine()

# default save callback
callback = engine.open_save_as_dialog

# if workfiles2 is configured, use that for file save
if "tk-multi-workfiles2" in engine.apps:
app = engine.apps["tk-multi-workfiles2"]
if hasattr(app, "show_file_save_dlg"):
callback = app.show_file_save_dlg

return {
"action_button": {
"label": "Save As...",
"tooltip": "Save the current session",
"callback": callback,
}
}


def _get_version_docs_action():
"""
Simple helper for returning a log action to show version docs
Expand Down

0 comments on commit 33976fd

Please sign in to comment.