Skip to content

Commit

Permalink
formatted with Black
Browse files Browse the repository at this point in the history
  • Loading branch information
diegogarciahuerta committed May 13, 2020
1 parent 400d4a3 commit 02ff114
Show file tree
Hide file tree
Showing 11 changed files with 230 additions and 239 deletions.
158 changes: 90 additions & 68 deletions engine.py

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,7 @@ def scan_scene(self):
{
"type": "file",
"path": ref_path,
"node": SubstancePainterResource(
res_info, in_use, nice_name
),
"node": SubstancePainterResource(res_info, in_use, nice_name),
}
)

Expand Down
7 changes: 2 additions & 5 deletions hooks/tk-multi-loader2/tk-substancepainter_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,14 @@ def generate_actions(self, sg_publish_data, actions, ui_area):
app = self.parent
app.log_debug(
"Generate actions called for UI element %s. "
"Actions: %s. Publish Data: %s"
% (ui_area, actions, sg_publish_data)
"Actions: %s. Publish Data: %s" % (ui_area, actions, sg_publish_data)
)

published_file_type = sg_publish_data["published_file_type"]["name"]
app.log_debug("published_file_type: %s" % published_file_type)

# check Published File Type Name:
available_actions = publishedfile_type_to_actions.get(
published_file_type
)
available_actions = publishedfile_type_to_actions.get(published_file_type)

action_instances = []

Expand Down
33 changes: 9 additions & 24 deletions hooks/tk-multi-publish2/basic/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,10 @@ def process_current_session(self, settings, parent_item):
"""

# create an item representing the current substance painter session
item = self.collect_current_substancepainter_session(
settings, parent_item
)
item = self.collect_current_substancepainter_session(settings, parent_item)

if item:
publish_as_folder_setting = settings.get(
"Publish Textures as Folder"
)
publish_as_folder_setting = settings.get("Publish Textures as Folder")
if publish_as_folder_setting and publish_as_folder_setting.value:
resource_items = self.collect_textures_as_folder(settings, item)
else:
Expand All @@ -122,16 +118,13 @@ def get_export_path(self, settings):
work_template_setting.value
)

self.logger.debug(
"Work template defined for Substance Painter collection."
)
self.logger.debug("Work template defined for Substance Painter collection.")

work_export_template = None
work_export_template_setting = settings.get("Work Export Template")
if work_export_template_setting:
self.logger.debug(
"Work Export template settings: %s"
% work_export_template_setting
"Work Export template settings: %s" % work_export_template_setting
)

work_export_template = publisher.engine.get_template_by_name(
Expand Down Expand Up @@ -163,8 +156,7 @@ def collect_textures_as_folder(self, settings, parent_item):

engine.show_busy(
"Exporting textures",
"Texture are being exported so they can "
"be published.\n\nPlease wait...",
"Texture are being exported so they can " "be published.\n\nPlease wait...",
)

map_export_info = engine.app.export_document_maps(export_path)
Expand Down Expand Up @@ -202,18 +194,15 @@ def collect_textures(self, settings, parent_item):

engine.show_busy(
"Exporting textures",
"Texture are being exported so they can "
"be published.\n\nPlease wait...",
"Texture are being exported so they can " "be published.\n\nPlease wait...",
)

map_export_info = engine.app.export_document_maps(export_path)
engine.clear_busy()

self.logger.debug("Collecting exported textures...")

icon_path = os.path.join(
self.disk_location, os.pardir, "icons", "texture.png"
)
icon_path = os.path.join(self.disk_location, os.pardir, "icons", "texture.png")

for texture_set_name, texture_set in map_export_info.iteritems():
for texture_id, texture_file in texture_set.iteritems():
Expand Down Expand Up @@ -254,15 +243,11 @@ def collect_current_substancepainter_session(self, settings, parent_item):

# create the session item for the publish hierarchy
session_item = parent_item.create_item(
"substancepainter.session",
"Substance Painter Session",
display_name,
"substancepainter.session", "Substance Painter Session", display_name,
)

# get the icon path to display for this item
icon_path = os.path.join(
self.disk_location, os.pardir, "icons", "session.png"
)
icon_path = os.path.join(self.disk_location, os.pardir, "icons", "session.png")
session_item.set_icon_from_path(icon_path)

# if a work template is defined, add it to the item properties so
Expand Down
29 changes: 9 additions & 20 deletions hooks/tk-multi-publish2/basic/publish_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ def description(self):
contain simple html for formatting.
"""

loader_url = (
"https://support.shotgunsoftware.com/hc/en-us/articles/219033078"
)
loader_url = "https://support.shotgunsoftware.com/hc/en-us/articles/219033078"

return """
Publishes the file to Shotgun. A <b>Publish</b> entry will be
Expand Down Expand Up @@ -115,9 +113,7 @@ def settings(self):
"""

# inherit the settings from the base publish plugin
base_settings = (
super(SubstancePainterSessionPublishPlugin, self).settings or {}
)
base_settings = super(SubstancePainterSessionPublishPlugin, self).settings or {}

# settings specific to this class
substancepainter_publish_settings = {
Expand Down Expand Up @@ -190,8 +186,7 @@ def accept(self, settings, item):
)

self.logger.info(
"Substance Painter '%s' plugin accepted the current session."
% (self.name,)
"Substance Painter '%s' plugin accepted the current session." % (self.name,)
)
return {"accepted": True, "checked": True}

Expand Down Expand Up @@ -246,9 +241,7 @@ def validate(self, settings, item):
},
)
else:
self.logger.debug(
"Work template configured and matches session file."
)
self.logger.debug("Work template configured and matches session file.")
else:
self.logger.debug("No work template configured.")

Expand Down Expand Up @@ -327,12 +320,10 @@ def publish(self, settings, item):
] = _substancepainter_find_additional_session_dependencies()

# let the base class register the publish
super(SubstancePainterSessionPublishPlugin, self).publish(
settings, item
)
item.properties.sg_publish_path = item.properties.sg_publish_data[
"path"
]["local_path"]
super(SubstancePainterSessionPublishPlugin, self).publish(settings, item)
item.properties.sg_publish_path = item.properties.sg_publish_data["path"][
"local_path"
]

def finalize(self, settings, item):
"""
Expand All @@ -346,9 +337,7 @@ def finalize(self, settings, item):
"""

# do the base class finalization
super(SubstancePainterSessionPublishPlugin, self).finalize(
settings, item
)
super(SubstancePainterSessionPublishPlugin, self).finalize(settings, item)

# bump the session file to the next version
self._save_to_next_version(item.properties["path"], item, _save_session)
Expand Down
63 changes: 35 additions & 28 deletions hooks/tk-multi-publish2/basic/publish_texture.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ def description(self):
contain simple html for formatting.
"""

loader_url = (
"https://support.shotgunsoftware.com/hc/en-us/articles/219033078"
)
loader_url = "https://support.shotgunsoftware.com/hc/en-us/articles/219033078"

return """
Publishes the file to Shotgun. A <b>Publish</b> entry will be
Expand Down Expand Up @@ -116,7 +114,9 @@ def settings(self):
"""

# inherit the settings from the base publish plugin
base_settings = super(SubstancePainterTexturesPublishPlugin, self).settings or {}
base_settings = (
super(SubstancePainterTexturesPublishPlugin, self).settings or {}
)

# settings specific to this class
substancepainter_publish_settings = {
Expand Down Expand Up @@ -178,8 +178,7 @@ def accept(self, settings, item):
item.context_change_allowed = False

self.logger.info(
"Substance Painter '%s' plugin accepted to publish textures."
% (self.name,)
"Substance Painter '%s' plugin accepted to publish textures." % (self.name,)
)
return {"accepted": True, "checked": True}

Expand All @@ -199,7 +198,9 @@ def validate(self, settings, item):

# populate the publish template on the item if found
publish_template_setting = settings.get("Publish Template")
publish_template = publisher.engine.get_template_by_name(publish_template_setting.value)
publish_template = publisher.engine.get_template_by_name(
publish_template_setting.value
)
if publish_template:
item.properties["publish_template"] = publish_template
else:
Expand All @@ -209,13 +210,14 @@ def validate(self, settings, item):

path = item.properties["path"]
if not os.path.isfile(path):
error_msg = "Validation failed. Texture path does not exist on disk. %s" % path
error_msg = (
"Validation failed. Texture path does not exist on disk. %s" % path
)
self.logger.error(error_msg)
raise Exception(error_msg)

return True


def publish(self, settings, item):
"""
Executes the publish logic for the given item and settings.
Expand All @@ -229,7 +231,7 @@ def publish(self, settings, item):
publisher = self.parent

publish_template = item.properties["publish_template"]
publish_type = item.properties["publish_type"]
publish_type = item.properties["publish_type"]
src = item.properties["path"]
_, filename = os.path.split(src)
filenamefile, extension = os.path.splitext(filename)
Expand All @@ -239,14 +241,16 @@ def publish(self, settings, item):
ctx_fields = self.parent.context.as_template_fields(publish_template)
fields.update(ctx_fields)

context_entity_type = self.parent.context.entity['type']
context_entity_type = self.parent.context.entity["type"]
publish_name = context_entity_type + "_" + filenamefile

existing_publishes = self._find_publishes(self.parent.context, publish_name, publish_type)
existing_publishes = self._find_publishes(
self.parent.context, publish_name, publish_type
)
version = max([p["version_number"] for p in existing_publishes] or [0]) + 1
fields["version"] = version
fields["channel"] = filenamefile
fields["extension"] = extension[1:] # no dot
fields["extension"] = extension[1:] # no dot
publish_path = publish_template.apply_fields(fields)
publish_path = sgtk.util.ShotgunPath.normalize(publish_path)

Expand All @@ -255,7 +259,7 @@ def publish(self, settings, item):
# make sure destination folder exists
ensure_folder_exists(publish_dir)

sgtk.util.filesystem.copy_file(src, publish_path)
sgtk.util.filesystem.copy_file(src, publish_path)

self.logger.info("A Publish will be created in Shotgun and linked to:")
self.logger.info(" %s" % (publish_path,))
Expand All @@ -265,13 +269,15 @@ def publish(self, settings, item):
# add dependencies
dependency_paths = []
if "sg_publish_path" in item.parent.properties:
self.logger.debug("Added dependency: %s" % item.parent.properties.sg_publish_path)
self.logger.debug(
"Added dependency: %s" % item.parent.properties.sg_publish_path
)
dependency_paths.append(item.parent.properties.sg_publish_path)

self.logger.info("Registering publish...")

publish_data = {
"tk": publisher.sgtk,
"tk": publisher.sgtk,
"context": item.context,
"comment": item.description,
"path": publish_path,
Expand All @@ -289,15 +295,14 @@ def publish(self, settings, item):
"action_show_more_info": {
"label": "Publish Data",
"tooltip": "Show the complete Publish data dictionary",
"text": "<pre>%s</pre>" % (pprint.pformat(publish_data),)
"text": "<pre>%s</pre>" % (pprint.pformat(publish_data),),
}
}
},
)

# create the publish and stash it in the item properties for other
# plugins to use.
item.properties["sg_publish_data"] = sgtk.util.register_publish(
**publish_data)
item.properties["sg_publish_data"] = sgtk.util.register_publish(**publish_data)

# inject the publish path such that children can refer to it when
# updating dependency information
Expand All @@ -308,7 +313,6 @@ def publish(self, settings, item):
# now that we've published. keep a handle on the path that was published
item.properties["path"] = publish_path


def finalize(self, settings, item):
"""
Execute the finalization pass. This pass executes once all the publish
Expand Down Expand Up @@ -340,28 +344,32 @@ def _find_publishes(self, ctx, publish_name, publish_type):
publish_type_field = "published_file_type.PublishedFileType.code"
else:
publish_type_field = "tank_type.TankType.code"

# construct filters from the context:
filters = [["project", "is", ctx.project]]
if ctx.entity:
filters.append(["entity", "is", ctx.entity])
if ctx.task:
filters.append(["task", "is", ctx.task])

# add in name & type:
if publish_name:
filters.append(["name", "is", publish_name])
if publish_type:
filters.append([publish_type_field, "is", publish_type])

# retrieve a list of all matching publishes from Shotgun:
sg_publishes = []
try:
query_fields = ["version_number"]
sg_publishes = self.parent.shotgun.find(publish_entity_type, filters, query_fields)
sg_publishes = self.parent.shotgun.find(
publish_entity_type, filters, query_fields
)
except Exception, e:
self.logger.error("Failed to find publishes of type '%s', called '%s', for context %s: %s"
% (publish_name, publish_type, ctx, e))
self.logger.error(
"Failed to find publishes of type '%s', called '%s', for context %s: %s"
% (publish_name, publish_type, ctx, e)
)
return sg_publishes


Expand All @@ -379,4 +387,3 @@ def _export_path():
path = path.encode("utf-8")

return path

Loading

0 comments on commit 02ff114

Please sign in to comment.