""" Requires: context -> anatomy context -> anatomyData Provides: instance -> publishDir instance -> resourcesDir """ import os import copy import pyblish.api class CollectResourcesPath(pyblish.api.InstancePlugin): """Generate directory path where the files and resources will be stored. Collects folder name and file name from files, if exists, for in-situ publishing. """ label = "Collect Resources Path" order = pyblish.api.CollectorOrder + 0.495 families = ["workfile", "pointcache", "proxyAbc", "camera", "animation", "model", "mayaAscii", "mayaScene", "setdress", "layout", "ass", "vdbcache", "scene", "vrayproxy", "render", "prerender", "imagesequence", "rendersetup", "rig", "plate", "look", "mvLook", "yetiRig", "yeticache", "nukenodes", "gizmo", "source", "matchmove", "image", "source", "assembly", "fbx", "gltf", "textures", "action", "background", "effect", "staticMesh", "skeletalMesh", "xgen", "yeticacheUE", "tycache" ] def process(self, instance): anatomy = instance.context.data["anatomy"] template_data = copy.deepcopy(instance.data["anatomyData"]) # This is for cases of Deprecated anatomy without `folder` # TODO remove when all clients have solved this issue template_data.update({ "frame": "FRAME_TEMP", "representation": "TEMP" }) # For the first time publish if instance.data.get("hierarchy"): template_data.update({ "hierarchy": instance.data["hierarchy"] }) publish_templates = anatomy.templates_obj["publish"] if "folder" in publish_templates: publish_folder = publish_templates["folder"].format_strict( template_data ) else: # solve deprecated situation when `folder` key is not underneath # `publish` anatomy self.log.warning(( "Deprecation warning: Anatomy does not have set `folder`" " key underneath `publish` (in global of for project `{}`)." ).format(anatomy.project_name)) file_path = publish_templates["path"].format_strict(template_data) publish_folder = os.path.dirname(file_path) publish_folder = os.path.normpath(publish_folder) resources_folder = os.path.join(publish_folder, "resources") instance.data["publishDir"] = publish_folder instance.data["resourcesDir"] = resources_folder self.log.debug("publishDir: \"{}\"".format(publish_folder)) self.log.debug("resourcesDir: \"{}\"".format(resources_folder))