use new method name and fix issues with string conversions

This commit is contained in:
Jakub Trllo 2024-03-19 14:26:05 +01:00
parent eaf580bf3b
commit e5fe964178
27 changed files with 83 additions and 60 deletions

View file

@ -33,7 +33,7 @@ class CollectRenderPath(pyblish.api.InstancePlugin):
m_anatomy_key = self.anatomy_template_key_metadata
# get folder and path for rendering images from celaction
r_template_item = anatomy.get_template("publish", r_anatomy_key)
r_template_item = anatomy.get_template_item("publish", r_anatomy_key)
render_dir = r_template_item["directory"].format_strict(anatomy_data)
render_path = r_template_item["path"].format_strict(anatomy_data)
self.log.debug("__ render_path: `{}`".format(render_path))
@ -50,7 +50,9 @@ class CollectRenderPath(pyblish.api.InstancePlugin):
instance.data["path"] = render_path
# get anatomy for published renders folder path
m_template_item = anatomy.get_template("publish", m_anatomy_key)
m_template_item = anatomy.get_template_item(
"publish", m_anatomy_key, default=None
)
if m_template_item is not None:
metadata_path = m_template_item["directory"].format_strict(
anatomy_data

View file

@ -632,7 +632,9 @@ def sync_avalon_data_to_workfile():
project_name = get_current_project_name()
anatomy = Anatomy(project_name)
work_template = anatomy.get_template("work", "default", "path")
work_template = anatomy.get_template_item(
"work", "default", "path"
)
work_root = anatomy.root_value_for_template(work_template)
active_project_root = (
os.path.join(work_root, project_name)
@ -825,7 +827,7 @@ class PublishAction(QtWidgets.QAction):
# root_node = hiero.core.nuke.RootNode()
#
# anatomy = Anatomy(get_current_project_name())
# work_template = anatomy.get_template("work", "default", "path")
# work_template = anatomy.get_template_item("work", "default", "path")
# root_path = anatomy.root_value_for_template(work_template)
#
# nuke_script.addNode(root_node)

View file

@ -129,7 +129,9 @@ class ExtractWorkfileXgen(publish.Extractor):
template_data = copy.deepcopy(instance.data["anatomyData"])
anatomy = instance.context.data["anatomy"]
publish_template = anatomy.get_template("publish", "default", "file")
publish_template = anatomy.get_template_item(
"publish", "default", "file"
)
published_maya_path = publish_template.format(template_data)
published_basename, _ = os.path.splitext(published_maya_path)

View file

@ -40,7 +40,7 @@ class ExtractXgen(publish.Extractor):
template_data = copy.deepcopy(instance.data["anatomyData"])
template_data.update({"ext": "xgen"})
anatomy = instance.context.data["anatomy"]
file_template = anatomy.get_template("publish", "default", "file")
file_template = anatomy.get_template_item("publish", "default", "file")
xgen_filename = file_template.format(template_data)
xgen_path = os.path.join(

View file

@ -392,13 +392,13 @@ class PhotoshopRoute(WebSocketRoute):
)
data["root"] = anatomy.roots
work_template = anatomy.get_template("work", template_key)
work_template = anatomy.get_template_item("work", template_key)
# Define saving file extension
extensions = host.get_workfile_extensions()
work_root = str(work_template["directory"].format_strict(data))
file_template = str(work_template["file"])
work_root = work_template["directory"].format_strict(data)
file_template = work_template["file"].template
last_workfile_path = get_last_workfile(
work_root, file_template, data, extensions, True
)

View file

@ -80,7 +80,7 @@ class LoadWorkfile(plugin.Loader):
)
data["root"] = anatomy.roots
work_template = anatomy.get_template("work", template_key)
work_template = anatomy.get_template_item("work", template_key)
# Define saving file extension
extensions = host.get_workfile_extensions()
@ -93,9 +93,9 @@ class LoadWorkfile(plugin.Loader):
data["ext"] = extension.lstrip(".")
work_root = str(work_template["directory"].format_strict(data))
work_root = work_template["directory"].format_strict(data)
version = get_last_workfile_with_version(
work_root, str(work_template["file"]), data, extensions
work_root, work_template["file"].template, data, extensions
)[1]
if version is None:

View file

@ -66,7 +66,7 @@ class UnrealPrelaunchHook(PreLaunchHook):
self.host_name,
)
# Fill templates
template_obj = anatomy.get_template(
template_obj = anatomy.get_template_item(
"work", workfile_template_key, "file"
)

View file

@ -1862,9 +1862,9 @@ def _prepare_last_workfile(data, workdir, addons_manager):
project_settings=project_settings
)
# Find last workfile
file_template = str(
anatomy.get_template("work", template_key, "file")
)
file_template = anatomy.get_template_item(
"work", template_key, "file"
).template
workdir_data.update({
"version": 1,

View file

@ -75,7 +75,9 @@ class CelactionSubmitDeadline(pyblish.api.InstancePlugin):
script_name = os.path.basename(script_path)
anatomy = instance.context.data["anatomy"]
publish_template = anatomy.get_template("publish", "default", "path")
publish_template = anatomy.get_template_item(
"publish", "default", "path"
)
for item in instance.context:
if "workfile" in item.data["productType"]:
msg = "Workfile (scene) must be published along"

View file

@ -124,7 +124,9 @@ class FusionSubmitDeadline(
script_path = context.data["currentFile"]
anatomy = instance.context.data["anatomy"]
publish_template = anatomy.get_template("publish", "default", "path")
publish_template = anatomy.get_template_item(
"publish", "default", "path"
)
for item in context:
if "workfile" in item.data["families"]:
msg = "Workfile (scene) must be published along"

View file

@ -198,7 +198,9 @@ class NukeSubmitDeadline(pyblish.api.InstancePlugin,
AbstractSubmitDeadline"""
anatomy = context.data["anatomy"]
# WARNING Hardcoded template name 'default' > may not be used
publish_template = anatomy.get_template("publish", "default", "path")
publish_template = anatomy.get_template_item(
"publish", "default", "path"
)
for instance in context:
if (
instance.data["productType"] != "workfile"

View file

@ -450,7 +450,7 @@ class ProcessSubmittedCacheJobOnFarm(pyblish.api.InstancePlugin,
"type": product_type,
}
render_dir_template = anatomy.get_template(
render_dir_template = anatomy.get_template_item(
"publish", template_name, "directory"
)
return render_dir_template.format_strict(template_data)

View file

@ -573,7 +573,7 @@ class ProcessSubmittedJobOnFarm(pyblish.api.InstancePlugin,
"type": product_type,
}
render_dir_template = anatomy.get_template(
render_dir_template = anatomy.get_template_item(
"publish", template_name, "directory"
)
return render_dir_template.format_strict(template_data)

View file

@ -545,7 +545,7 @@ def get_workdir_from_session(session=None, template_key=None):
)
anatomy = Anatomy(project_name)
template_obj = anatomy.get_template("work", template_key, "directory")
template_obj = anatomy.get_template_item("work", template_key, "directory")
path = template_obj.format_strict(template_data)
if path:
path = os.path.normpath(path)

View file

@ -77,7 +77,9 @@ def check_destination_path(
"""
anatomy_data.update(datetime_data)
path_template = anatomy.get_template("delivery", template_name, "path")
path_template = anatomy.get_template_item(
"delivery", template_name, "path"
)
dest_path = path_template.format(anatomy_data)
report_items = collections.defaultdict(list)
@ -150,7 +152,9 @@ def deliver_single_file(
if format_dict:
anatomy_data = copy.deepcopy(anatomy_data)
anatomy_data["root"] = format_dict["root"]
template_obj = anatomy.get_template("delivery", template_name, "path")
template_obj = anatomy.get_template_item(
"delivery", template_name, "path"
)
delivery_path = template_obj.format_strict(anatomy_data)
# Backwards compatibility when extension contained `.`
@ -220,8 +224,8 @@ def deliver_sequence(
report_items["Source file was not found"].append(msg)
return report_items, 0
delivery_template = anatomy.get_template(
"delivery", template_name, "path"
delivery_template = anatomy.get_template_item(
"delivery", template_name, "path", default=None
)
if delivery_template is None:
msg = (
@ -233,7 +237,7 @@ def deliver_sequence(
# Check if 'frame' key is available in template which is required
# for sequence delivery
if "{frame" not in delivery_template:
if "{frame" not in delivery_template.template:
msg = (
"Delivery template \"{}\" in anatomy of project \"{}\""
"does not contain '{{frame}}' key to fill. Delivery of sequence"
@ -278,8 +282,7 @@ def deliver_sequence(
anatomy_data["frame"] = frame_indicator
if format_dict:
anatomy_data["root"] = format_dict["root"]
template_obj = anatomy.get_template("delivery", template_name, "path")
delivery_path = template_obj.format_strict(anatomy_data)
delivery_path = delivery_template.format_strict(anatomy_data)
delivery_path = os.path.normpath(delivery_path.replace("\\", "/"))
delivery_folder = os.path.dirname(delivery_path)

View file

@ -54,7 +54,7 @@ def from_published_scene(instance, replace_in_path=True):
template_data["comment"] = None
anatomy = instance.context.data['anatomy']
template_obj = anatomy.get_template("publish", "default", "path")
template_obj = anatomy.get_template_item("publish", "default", "path")
template_filled = template_obj.format_strict(template_data)
file_path = os.path.normpath(template_filled)

View file

@ -743,8 +743,8 @@ def get_custom_staging_dir_info(
template_name = profile["template_name"] or TRANSIENT_DIR_TEMPLATE
custom_staging_dir = anatomy.get_template(
"staging", template_name, "directory"
custom_staging_dir = anatomy.get_template_item(
"staging", template_name, "directory", default=None
)
if custom_staging_dir is None:
raise ValueError((
@ -753,7 +753,7 @@ def get_custom_staging_dir_info(
).format(project_name, template_name))
is_persistent = profile["custom_staging_dir_persistent"]
return str(custom_staging_dir), is_persistent
return custom_staging_dir.template, is_persistent
def get_published_workfile_instance(context):
@ -805,7 +805,7 @@ def replace_with_published_scene_path(instance, replace_in_path=True):
template_data["comment"] = None
anatomy = instance.context.data["anatomy"]
template = anatomy.get_template("publish", "default", "path")
template = anatomy.get_template_item("publish", "default", "path")
template_filled = template.format_strict(template_data)
file_path = os.path.normpath(template_filled)

View file

@ -341,8 +341,8 @@ def get_usd_master_path(folder_entity, product_name, representation):
"version": 0, # stub version zero
})
template_obj = anatomy.get_template(
"publish", "default","path"
template_obj = anatomy.get_template_item(
"publish", "default", "path"
)
path = template_obj.format_strict(template_data)

View file

@ -135,7 +135,9 @@ def get_workdir_with_workdir_data(
project_settings
)
template_obj = anatomy.get_template("work", template_key, "directory")
template_obj = anatomy.get_template_item(
"work", template_key, "directory"
)
# Output is TemplateResult object which contain useful data
output = template_obj.format_strict(workdir_data)
if output:

View file

@ -70,7 +70,7 @@ class OpenTaskPath(LauncherAction):
data = get_template_data(project_entity, folder_entity, task_entity)
anatomy = Anatomy(project_name)
workdir = anatomy.get_template(
workdir = anatomy.get_template_item(
"work", "default", "folder"
).format(data)
@ -87,7 +87,7 @@ class OpenTaskPath(LauncherAction):
return valid_workdir
data.pop("task", None)
workdir = anatomy.get_template(
workdir = anatomy.get_template_item(
"work", "default", "folder"
).format(data)
valid_workdir = self._find_first_filled_path(workdir)

View file

@ -43,9 +43,9 @@ class CollectOtioSubsetResources(pyblish.api.InstancePlugin):
template_name = self.get_template_name(instance)
anatomy = instance.context.data["anatomy"]
publish_path_template = anatomy.get_template(
publish_path_template = anatomy.get_template_item(
"publish", template_name, "path"
)
).template
template = os.path.normpath(publish_path_template)
self.log.debug(
">> template: {}".format(template))

View file

@ -79,7 +79,7 @@ class CollectResourcesPath(pyblish.api.InstancePlugin):
"representation": "TEMP"
})
publish_templates = anatomy.get_template(
publish_templates = anatomy.get_template_item(
"publish", "default", "directory"
)
publish_folder = os.path.normpath(

View file

@ -665,9 +665,9 @@ class IntegrateAsset(pyblish.api.InstancePlugin):
self.log.debug("Anatomy template name: {}".format(template_name))
anatomy = instance.context.data["anatomy"]
publish_template = anatomy.get_template("publish", template_name)
publish_template = anatomy.get_template_item("publish", template_name)
path_template_obj = publish_template["path"]
template = os.path.normpath(path_template_obj)
template = path_template_obj.template.replace("\\", "/")
is_udim = bool(repre.get("udim"))

View file

@ -103,7 +103,9 @@ class IntegrateHeroVersion(pyblish.api.InstancePlugin):
project_name = anatomy.project_name
template_key = self._get_template_key(project_name, instance)
hero_template = anatomy.get_template("hero", template_key, "path")
hero_template = anatomy.get_template_item(
"hero", template_key, "path", default=None
)
if hero_template is None:
self.log.warning((
@ -320,7 +322,7 @@ class IntegrateHeroVersion(pyblish.api.InstancePlugin):
try:
src_to_dst_file_paths = []
repre_integrate_data = []
path_template_obj = anatomy.get_template(
path_template_obj = anatomy.get_template_item(
"hero", template_key, "path"
)
for repre_info in published_repres.values():
@ -335,7 +337,9 @@ class IntegrateHeroVersion(pyblish.api.InstancePlugin):
anatomy_data.pop("version", None)
# Get filled path to repre context
template_filled = path_template_obj.format_strict(anatomy_data)
template_filled = path_template_obj.format_strict(
anatomy_data
)
repre_context = template_filled.used_values
for key in self.db_representation_context_keys:
value = anatomy_data.get(key)
@ -538,7 +542,7 @@ class IntegrateHeroVersion(pyblish.api.InstancePlugin):
"originalBasename": instance.data.get("originalBasename")
})
template_obj = anatomy.get_template(
template_obj = anatomy.get_template_item(
"hero", template_key, "directory"
)
publish_folder = os.path.normpath(

View file

@ -973,8 +973,8 @@ class ProjectPushItemProcess:
"version": version_entity["version"]
})
publish_template = anatomy.get_template("publish", template_name)
path_template = publish_template["path"].replace("\\", "/")
publish_template = anatomy.get_template_item("publish", template_name)
path_template = publish_template["path"].template.replace("\\", "/")
file_template = publish_template["file"]
self._log_info("Preparing files to transfer")
processed_repre_items = self._prepare_file_transactions(
@ -1011,7 +1011,7 @@ class ProjectPushItemProcess:
if repre_output_name is not None:
repre_format_data["output"] = repre_output_name
template_obj = anatomy.get_template(
template_obj = anatomy.get_template_item(
"publish", template_name, "directory"
)
folder_path = template_obj.format_strict(formatting_data)

View file

@ -40,7 +40,7 @@ class TextureCopy:
},
})
anatomy = Anatomy(project_name, project_entity=project_entity)
template_obj = anatomy.get_template(
template_obj = anatomy.get_template_item(
"publish", "texture", "path"
)
return template_obj.format_strict(template_data)

View file

@ -253,7 +253,7 @@ class WorkareaModel:
return list(comment_hints), current_comment
def _get_workdir(self, anatomy, template_key, fill_data):
directory_template = anatomy.get_template(
directory_template = anatomy.get_template_item(
"work", template_key, "directory"
)
return directory_template.format_strict(fill_data).normalized()
@ -300,9 +300,12 @@ class WorkareaModel:
workdir = self._get_workdir(anatomy, template_key, fill_data)
file_template = str(
anatomy.get_template("work", template_key, "file")
)
file_template = anatomy.get_template_item(
"work", template_key, "file"
).template
template_has_version = "{version" in file_template
template_has_comment = "{comment" in file_template
comment_hints, comment = self._get_comments_from_root(
file_template,
@ -313,9 +316,6 @@ class WorkareaModel:
)
last_version = self._get_last_workfile_version(
workdir, file_template, fill_data, extensions)
str_file_template = str(file_template)
template_has_version = "{version" in str_file_template
template_has_comment = "{comment" in str_file_template
return {
"template_key": template_key,
@ -344,7 +344,9 @@ class WorkareaModel:
workdir = self._get_workdir(anatomy, template_key, fill_data)
file_template = anatomy.get_template("work", template_key, "file")
file_template = anatomy.get_template_item(
"work", template_key, "file"
).template
if use_last_version:
version = self._get_last_workfile_version(