From 1a624b99a7172ea9f0be4c760d62e00171dc4339 Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Mon, 31 Jan 2022 21:00:39 +0100 Subject: [PATCH] flame: finalization clip loader --- openpype/hosts/flame/api/plugin.py | 39 +++++++++++-------- .../hosts/flame/plugins/load/load_clip.py | 31 +++++++++++---- 2 files changed, 46 insertions(+), 24 deletions(-) diff --git a/openpype/hosts/flame/api/plugin.py b/openpype/hosts/flame/api/plugin.py index 503971fef7..c28ab0f556 100644 --- a/openpype/hosts/flame/api/plugin.py +++ b/openpype/hosts/flame/api/plugin.py @@ -701,6 +701,8 @@ class OpenClipSolver: out_feed_fps = None out_feed_drop_mode = None + log = log + def __init__(self, openclip_file_path, feed_data): # test if media script paht exists self._validate_media_script_path() @@ -710,6 +712,9 @@ class OpenClipSolver: self.feed_version_name = feed_data["version"] self.feed_colorspace = feed_data.get("colorspace") + if feed_data.get("logger"): + self.log = feed_data["logger"] + # derivate other feed variables self.feed_basename = os.path.basename(feed_path) self.feed_dir = os.path.dirname(feed_path) @@ -726,7 +731,7 @@ class OpenClipSolver: self.tmp_file = os.path.join(self.feed_dir, self.tmp_name) self._clear_tmp_file() - print("Temp File: {}".format(self.tmp_file)) + self.log.info("Temp File: {}".format(self.tmp_file)) def make(self): self._get_media_info_args() @@ -753,9 +758,9 @@ class OpenClipSolver: # execute creation of clip xml template data try: - flib.run_subprocess(cmd_args) + openpype.run_subprocess(cmd_args) except TypeError: - print("Error createing self.tmp_file") + self.log.error("Error createing self.tmp_file") six.reraise(*sys.exc_info()) def _clear_tmp_file(self): @@ -764,11 +769,11 @@ class OpenClipSolver: def _clear_handler(self, xml_object): for handler in xml_object.findall("./handler"): - print("Handler found") + self.log.debug("Handler found") xml_object.remove(handler) def _create_new_open_clip(self): - print("Building new openClip") + self.log.info("Building new openClip") tmp_xml = ET.parse(self.tmp_file) @@ -790,20 +795,20 @@ class OpenClipSolver: xml_new_version.set('type', 'version') xml_data = self._fix_xml_data(tmp_xml) - print("Adding feed version: {}".format(self.feed_basename)) + self.log.info("Adding feed version: {}".format(self.feed_basename)) self._write_result_xml_to_file(xml_data) - print("openClip Updated: %s" % self.tmp_file) + self.log.info("openClip Updated: {}".format(self.tmp_file)) def _update_open_clip(self): - print("Updating openClip ..") + self.log.info("Updating openClip ..") out_xml = ET.parse(self.out_file) tmp_xml = ET.parse(self.tmp_file) - print(">> out_xml: {}".format(out_xml)) - print(">> tmp_xml: {}".format(tmp_xml)) + self.log.debug(">> out_xml: {}".format(out_xml)) + self.log.debug(">> tmp_xml: {}".format(tmp_xml)) # Get new feed from tmp file tmp_xml_feed = tmp_xml.find('tracks/track/feeds/feed') @@ -841,7 +846,7 @@ class OpenClipSolver: out_feeds.set('currentVersion', self.feed_version_name) out_feeds.append(tmp_xml_feed) - print( + self.log.info( "Appending new feed: {}".format( self.feed_version_name)) feed_added = True @@ -860,11 +865,12 @@ class OpenClipSolver: # fist create backup self._create_openclip_backup_file(self.out_file) - print("Adding feed version: {}".format(self.feed_version_name)) + self.log.info("Adding feed version: {}".format( + self.feed_version_name)) self._write_result_xml_to_file(xml_data) - print("openClip Updated: {}".format(self.out_file)) + self.log.info("openClip Updated: {}".format(self.out_file)) self._clear_tmp_file() @@ -885,14 +891,15 @@ class OpenClipSolver: else: continue except Exception as msg: - print(msg) + self.log.warning(msg) def _feed_exists(self, xml_data, path): # loop all available feed paths and check if # the path is not already in file for src_path in xml_data.iter('path'): if path == src_path.text: - print("Not appending file as it already is in .clip file") + self.log.warning( + "Not appending file as it already is in .clip file") return True def _fix_xml_data(self, xml_data): @@ -929,7 +936,7 @@ class OpenClipSolver: def _add_colorspace(self, feed_obj, profile_name): feed_storage_obj = feed_obj.find("storageFormat") feed_clr_obj = feed_storage_obj.find("colourSpace") - if not feed_clr_obj: + if feed_clr_obj is not None: feed_clr_obj = ET.Element( "colourSpace", {"type": "string"}) feed_storage_obj.append(feed_clr_obj) diff --git a/openpype/hosts/flame/plugins/load/load_clip.py b/openpype/hosts/flame/plugins/load/load_clip.py index dd34bc8adb..112571bf09 100644 --- a/openpype/hosts/flame/plugins/load/load_clip.py +++ b/openpype/hosts/flame/plugins/load/load_clip.py @@ -1,6 +1,6 @@ import os import flame -from avalon import io, api +from pprint import pformat import openpype.hosts.flame.api as opfapi @@ -24,7 +24,6 @@ class LoadClip(opfapi.ClipLoader): reel_name = "Loaded" clip_name_template = "{asset}_{subset}_{representation}" - def load(self, context, name, namespace, options): # get flame objects @@ -47,17 +46,27 @@ class LoadClip(opfapi.ClipLoader): # create workfile path workfile_dir = os.environ["AVALON_WORKDIR"] - openclip_path = os.path.join( - workfile_dir, clip_name, clip_name + ".clip" + openclip_dir = os.path.join( + workfile_dir, clip_name ) + openclip_path = os.path.join( + openclip_dir, clip_name + ".clip" + ) + if not os.path.exists(openclip_dir): + os.makedirs(openclip_dir) # prepare clip data from context ad send it to openClipLoader loading_context = { "path": self.fname.replace("\\", "/"), "colorspace": colorspace, - "version": version_name + "version": "v{:0>3}".format(version_name), + "logger": self.log } + self.log.debug(pformat( + loading_context + )) + self.log.debug(openclip_path) # make openpype clip file opfapi.OpenClipSolver(openclip_path, loading_context).make() @@ -102,7 +111,8 @@ class LoadClip(opfapi.ClipLoader): if matching_clip: return matching_clip.pop() else: - return flame.import_clips(clip_path, reel) + created_clips = flame.import_clips(str(clip_path), reel) + return created_clips.pop() def _get_reel(self): @@ -112,7 +122,12 @@ class LoadClip(opfapi.ClipLoader): ] if not matching_rgroup: - reel_group = self.fpd.create_reel_group(self.reel_group_name) + reel_group = self.fpd.create_reel_group(str(self.reel_group_name)) + for _r in reel_group.reels: + if "reel" not in _r.name.get_value().lower(): + continue + self.log.debug("Removing: {}".format(_r.name)) + flame.delete(_r) else: reel_group = matching_rgroup.pop() @@ -122,7 +137,7 @@ class LoadClip(opfapi.ClipLoader): ] if not matching_reel: - reel_group = reel_group.create_reel(self.reel_name) + reel_group = reel_group.create_reel(str(self.reel_name)) else: reel_group = matching_reel.pop()