Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* Ran python-modernize

* Ran the pre commit hook, black made changes.

* Added black and Hound badges to the README

* Added Azure config.
  • Loading branch information
pscadding authored Feb 6, 2020
1 parent 1935dd7 commit 41c2416
Show file tree
Hide file tree
Showing 32 changed files with 513 additions and 382 deletions.
39 changes: 39 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright (c) 2019 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.

# Styles the code properly
# Exclude the UI files, as they are auto-generated.
exclude: "ui\/.*py$"
# List of super useful formatters.
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.4.0
hooks:
# Ensures the code is syntaxically correct
- id: check-ast
language_version: python3
# Ensures a file name will resolve on all platform
- id: check-case-conflict
# Checks files with the execute bit set have shebangs
- id: check-executables-have-shebangs
# Ensure there's no incomplete merges
- id: check-merge-conflict
# Adds an empty line if missing at the end of a file.
- id: end-of-file-fixer
# Makes sure requirements.txt is properly formatted
- id: requirements-txt-fixer
# Removes trailing whitespaces.
- id: trailing-whitespace
# Leave black at the bottom so all touchups are done before it is run.
- repo: https://github.com/ambv/black
rev: 19.10b0
hooks:
- id: black
language_version: python3
14 changes: 7 additions & 7 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ Version: 7/07/2013

Shotgun Software Inc. ("Company") provides the Shotgun Pipeline Toolkit,
software, including source code, in this package or repository folder (the
"Shotgun Toolkit Code") subject to your acceptance of and compliance with
"Shotgun Toolkit Code") subject to your acceptance of and compliance with
the following terms and conditions (the "License Terms"). By accessing,
downloading, copying, using or modifying any of the Shotgun Toolkit Code,
downloading, copying, using or modifying any of the Shotgun Toolkit Code,
you agree to these License Terms.

Eligibility
Expand All @@ -33,7 +33,7 @@ to the Shotgun Toolkit Code or any of Company's other software or intellectual
property rights. You agree not to take any action with respect to the Shotgun
Toolkit Code that is not expressly authorized above.

You must keep intact (and, in the case of copies, reproduce) all copyright
You must keep intact (and, in the case of copies, reproduce) all copyright
and other proprietary notices, including all references to and copies of these
License Terms, as originally included on, in, or with the Shotgun Toolkit
Code. You must ensure that all derivative works you make of the Shotgun
Expand Down Expand Up @@ -64,7 +64,7 @@ Company).
Liability

You agree to be solely responsible for your use and modifications of the
Shotgun Toolkit Code, and for any harm or liability arising out of such use
Shotgun Toolkit Code, and for any harm or liability arising out of such use
or modifications, including but not limited to any liability for infringement
of third-party intellectual property rights.

Expand All @@ -78,7 +78,7 @@ advised of the possibility of such damages; and (b) in any event, Company's
aggregate liability under these License Terms or in connection with the
Shotgun Toolkit Code, regardless of the form of action and under any theory
(whether in contract, tort, statutory, or otherwise), will not exceed the
greater of $50 or the amount (if any) that you actually paid for access to
greater of $50 or the amount (if any) that you actually paid for access to
the Shotgun Toolkit Code.

Ownership
Expand Down Expand Up @@ -115,7 +115,7 @@ Company grants you a non-exclusive right to continue to modify, make
derivative works of, reproduce, and use the Contribution for your
non-commercial or internal business purposes, and to further Company's
development of Company Programs. This grant does not: (a) limit Company's
rights, (b) grant you any rights with respect to the Company Programs; nor
rights, (b) grant you any rights with respect to the Company Programs; nor
(c) permit you to distribute, operate for the benefit of third parties (for
example, on a hosted basis), or otherwise commercially exploit the
Contribution.
Expand Down Expand Up @@ -143,4 +143,4 @@ employees, and agents against any and all claims, actions or damages
account of a breach or alleged breach of the foregoing warranty. You make no
other express or implied warranty (including without limitation any warranty
of merchantability or fitness for a particular purpose) regarding the
Contribution.
Contribution.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Linting](https://img.shields.io/badge/PEP8%20by-Hound%20CI-a873d1.svg)](https://houndci.com)

## Documentation
This repository is a part of the Shotgun Pipeline Toolkit.

Expand Down
102 changes: 50 additions & 52 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@
import sys
import os

class MultiBreakdown(Application):

class MultiBreakdown(Application):
def init_app(self):
"""
Called as the application is being initialized
"""
tk_multi_breakdown = self.import_module("tk_multi_breakdown")
cb = lambda : tk_multi_breakdown.show_dialog(self)
self.engine.register_command("Scene Breakdown...", cb, { "short_name": "breakdown" })

cb = lambda: tk_multi_breakdown.show_dialog(self)
self.engine.register_command(
"Scene Breakdown...", cb, {"short_name": "breakdown"}
)

@property
def context_change_allowed(self):
Expand All @@ -35,44 +36,42 @@ def context_change_allowed(self):
"""
return True


def show_breakdown_dialog(self):
"""
Show the breakdown UI as a dialog.
This is a helper method to make it easy to programatically access the breakdown UI.
External code could then do something like:
>>> import sgtk
>>> e = sgtk.platform.current_engine()
>>> e.apps["tk-multi-breakdown"].show_breakdown_dialog()
"""
"""
tk_multi_breakdown = self.import_module("tk_multi_breakdown")
fn = lambda : tk_multi_breakdown.show_dialog(self)
fn = lambda: tk_multi_breakdown.show_dialog(self)
self.engine.execute_in_main_thread(fn)



def analyze_scene(self):
"""
Runs the scene analysis and returns a list of scene items.
Each item is represented by a dictionary with a number of keys to
Each item is represented by a dictionary with a number of keys to
describe the item. This method uses the same logic that the main UI
uses to determine the list of files.
Only files whose path corresponds to a template in the toolkit templates
file will be detected. Files do not need to exist as publishes in Shotgun
however if they do, this method will return basic Shotgun publish metadata
for them.
The two keys node_name and node_type are used to return a DCC-centric
The two keys node_name and node_type are used to return a DCC-centric
"address" or representation which makes it possible to identify the path
within the DCC. In for example Maya and Nuke, this will return the
node name and type. The logic for this is implemented in the hooks and
within the DCC. In for example Maya and Nuke, this will return the
node name and type. The logic for this is implemented in the hooks and
will vary between DCCs.
Here is an example of what the return data typically looks like:
{'fields': {'Sequence': 'aaa',
'Shot': 'aaa_00010',
'Step': 'Comp',
Expand All @@ -83,10 +82,10 @@ def analyze_scene(self):
'version': 1,
'width': 2048},
'template': <Sgtk TemplatePath nuke_shot_render_pub_mono_dpx>,
'node_name': 'Read2',
'node_type': 'Read',
'sg_data': {'code': 'aaa_00010_test_output_v001.%04d.dpx',
'entity': {'id': 1660, 'name': 'aaa_00010', 'type': 'Shot'},
'id': 1424,
Expand All @@ -99,52 +98,52 @@ def analyze_scene(self):
'project': {'id': 234, 'name': 'Climp', 'type': 'Project'},
'version_number': 1},
}
This method will attempt to connect to shotgun, but the number of calls made are
constant and independent of the scene complexity.
Below is an example showing how to retrieve the scene breakdown and update all items
that are not using the latest version.
# find the breakdown app instance
import sgtk
engine = sgtk.platform.current_engine()
breakdown_app = engine.apps["tk-multi-breakdown"]
# get list of breakdown items
items = breakdown_app.analyze_scene()
# now loop over all items
for item in items:
# get the latest version on disk
latest_version = breakdown_app.compute_highest_version(item["template"], item["fields"])
# if our current version is out of date, update it!
current_version = item["fields"]["version"]
if latest_version > current_version:
# make a fields dictionary representing the latest version
latest_fields = copy.copy(item["fields"])
latest_fields["version"] = latest_version
# request that the breakdown updates to the latest version
breakdown_app.update_item(item["node_type"], item["node_name"], item["template"], latest_fields)
:returns: List of dictionaries, see above for example.
"""
tk_multi_breakdown = self.import_module("tk_multi_breakdown")

# first, scan the scene and get a list of items
items = tk_multi_breakdown.get_breakdown_items()

# if shotgun data is returned for an item, trim this down
# to return a more basic listing than the one returned
# from get_breakdown_items:
for item in items:

if item["sg_data"]:
new_sg_data = {}
new_sg_data["id"] = item["sg_data"]["id"]
Expand All @@ -155,36 +154,38 @@ def analyze_scene(self):
new_sg_data["entity"] = item["sg_data"]["entity"]
new_sg_data["project"] = item["sg_data"]["project"]
new_sg_data["version_number"] = item["sg_data"]["version_number"]
new_sg_data["published_file_type"] = item["sg_data"]["published_file_type"]
new_sg_data["published_file_type"] = item["sg_data"][
"published_file_type"
]
item["sg_data"] = new_sg_data

return items

return items

def compute_highest_version(self, template, fields):
"""
Given a template and some fields, return the highest version number found on disk.
The template key containing the version number is assumed to be named {version}.
This will perform a scan on disk to determine the highest version.
For a usage example, see the analyze_scene() method.
:param template: Template object to calculate for
:param fields: A complete set of fields for the template
:returns: The highest version number found
"""
return self.execute_hook("hook_get_version_number", template=template, curr_fields=fields)


return self.execute_hook(
"hook_get_version_number", template=template, curr_fields=fields
)

def update_item(self, node_type, node_name, template, fields):
"""
Request that the breakdown updates an given node with a new version.
This is similar to running the update in the breakdown UI. The actual
This is similar to running the update in the breakdown UI. The actual
update call will be dispatched to a hook which handles the DCC specific logic.
For a usage example, see the analyze_scene() method.
:param node_type: Node type of the item to update, as returned by analyze_scene()
:param node_name: Node name of the item to update, as returned by analyze_scene()
:param template: Template object representing the path pattern to update
Expand All @@ -195,9 +196,6 @@ def update_item(self, node_type, node_name, template, fields):
item["node"] = node_name
item["type"] = node_type
item["path"] = template.apply_fields(fields)

# call out to hook
return self.execute_hook_method("hook_scene_operations", "update", items=[item])



32 changes: 32 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Imports the shared Azure CI tools from the master branch of shotgunsoftware/tk-ci-tools
resources:
repositories:
- repository: templates
type: github
name: shotgunsoftware/tk-ci-tools
ref: refs/heads/master
endpoint: shotgunsoftware

# We want builds to trigger for 3 reasons:
# - The master branch sees new commits
# - Each PR should get rebuilt when commits are added to it.
# - When we tag something
trigger:
branches:
include:
- master
tags:
include:
- v*
pr:
branches:
include:
- "*"

# This pulls in a variable group from Azure. Variables can be encrypted or not.
variables:
- group: deploy-secrets

# Launch into the build pipeline.
jobs:
- template: build-pipeline.yml@templates
6 changes: 5 additions & 1 deletion hooks/get_version_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
# the template key we use to find the version number
VERSION_KEY = "version"


class GetVersionNumber(HookBaseClass):
"""
Hook called to scan the disk and determine the highest version.
Given a template and some fields, return the highest version number found on disk.
The template key containing the version number is assumed to be named {version}.
"""

def execute(self, template, curr_fields, **kwargs):
"""
Main hook entry point.
Expand Down Expand Up @@ -53,7 +55,9 @@ def execute(self, template, curr_fields, **kwargs):
skip_keys = [k for k in abstract_keys] + [VERSION_KEY, "eye"]

# then find all files, skipping these keys
all_versions = self.sgtk.paths_from_template(template, curr_fields, skip_keys=skip_keys)
all_versions = self.sgtk.paths_from_template(
template, curr_fields, skip_keys=skip_keys
)

# if we didn't find anything then something has gone wrong with our
# logic as we should have at least one file so error out:
Expand Down
Loading

0 comments on commit 41c2416

Please sign in to comment.