Merge branch 'hotfix/delivery_action_paths'

This commit is contained in:
Milan Kolar 2020-08-10 10:04:33 +02:00
commit a580f142d2

View file

@ -11,7 +11,7 @@ from avalon.vendor import filelink
from pype.api import Anatomy
from pype.modules.ftrack.lib import BaseAction, statics_icon
from pype.modules.ftrack.lib.avalon_sync import CustAttrIdKey
from pype.modules.ftrack.lib.avalon_sync import CUST_ATTR_ID_KEY
from pype.modules.ftrack.lib.io_nonsingleton import DbConnector
@ -81,13 +81,15 @@ class Delivery(BaseAction):
anatomy = Anatomy(project_name)
new_anatomies = []
first = None
for key in (anatomy.templates.get("delivery") or {}):
new_anatomies.append({
"label": key,
"value": key
})
if first is None:
first = key
for key, template in (anatomy.templates.get("delivery") or {}).items():
# Use only keys with `{root}` or `{root[*]}` in value
if isinstance(template, str) and "{root" in template:
new_anatomies.append({
"label": key,
"value": key
})
if first is None:
first = key
skipped = False
# Add message if there are any common components
@ -243,7 +245,7 @@ class Delivery(BaseAction):
version = entity["version"]
parent = asset["parent"]
parent_mongo_id = parent["custom_attributes"].get(CustAttrIdKey)
parent_mongo_id = parent["custom_attributes"].get(CUST_ATTR_ID_KEY)
if parent_mongo_id:
parent_mongo_id = ObjectId(parent_mongo_id)
else:
@ -293,6 +295,20 @@ class Delivery(BaseAction):
repres_to_deliver.append(repre)
anatomy = Anatomy(project_name)
format_dict = {}
if location_path:
location_path = location_path.replace("\\", "/")
root_names = anatomy.root_names_from_templates(
anatomy.templates["delivery"]
)
if root_names is None:
format_dict["root"] = location_path
else:
format_dict["root"] = {}
for name in root_names:
format_dict["root"][name] = location_path
for repre in repres_to_deliver:
# Get destination repre path
anatomy_data = copy.deepcopy(repre["context"])
@ -339,25 +355,33 @@ class Delivery(BaseAction):
repre_path = self.path_from_represenation(repre, anatomy)
# TODO add backup solution where root of path from component
# is repalced with root
if not frame:
self.process_single_file(
repre_path, anatomy, anatomy_name, anatomy_data
)
args = (
repre_path,
anatomy,
anatomy_name,
anatomy_data,
format_dict
)
if not frame:
self.process_single_file(*args)
else:
self.process_sequence(
repre_path, anatomy, anatomy_name, anatomy_data
)
self.process_sequence(*args)
self.db_con.uninstall()
return self.report()
def process_single_file(
self, repre_path, anatomy, anatomy_name, anatomy_data
self, repre_path, anatomy, anatomy_name, anatomy_data, format_dict
):
anatomy_filled = anatomy.format(anatomy_data)
delivery_path = anatomy_filled["delivery"][anatomy_name]
if format_dict:
template_result = anatomy_filled["delivery"][anatomy_name]
delivery_path = template_result.rootless.format(**format_dict)
else:
delivery_path = anatomy_filled["delivery"][anatomy_name]
delivery_folder = os.path.dirname(delivery_path)
if not os.path.exists(delivery_folder):
os.makedirs(delivery_folder)
@ -365,7 +389,7 @@ class Delivery(BaseAction):
self.copy_file(repre_path, delivery_path)
def process_sequence(
self, repre_path, anatomy, anatomy_name, anatomy_data
self, repre_path, anatomy, anatomy_name, anatomy_data, format_dict
):
dir_path, file_name = os.path.split(str(repre_path))
@ -408,8 +432,12 @@ class Delivery(BaseAction):
anatomy_data["frame"] = frame_indicator
anatomy_filled = anatomy.format(anatomy_data)
delivery_path = anatomy_filled["delivery"][anatomy_name]
print(delivery_path)
if format_dict:
template_result = anatomy_filled["delivery"][anatomy_name]
delivery_path = template_result.rootless.format(**format_dict)
else:
delivery_path = anatomy_filled["delivery"][anatomy_name]
delivery_folder = os.path.dirname(delivery_path)
dst_head, dst_tail = delivery_path.split(frame_indicator)
dst_padding = src_collection.padding