From 281f8bc86e716de0ff822d31052ccd46ea52b84b Mon Sep 17 00:00:00 2001 From: Jakub Trllo Date: Thu, 19 Jan 2023 15:40:44 +0100 Subject: [PATCH] handle lowered paths in representation files --- .../push_to_project/control_integrate.py | 45 ++++++++++++------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/openpype/tools/push_to_project/control_integrate.py b/openpype/tools/push_to_project/control_integrate.py index 8457f2d9107..bb95fdb26f9 100644 --- a/openpype/tools/push_to_project/control_integrate.py +++ b/openpype/tools/push_to_project/control_integrate.py @@ -84,6 +84,12 @@ def __init__(self, path, relative_path): def __repr__(self): return "<{}> '{}'".format(self.__class__.__name__, self.relative_path) + @property + def is_valid_file(self): + if not self.relative_path: + return False + return super(ResourceFile, self).is_valid_file + class ProjectPushItem: def __init__( @@ -333,6 +339,19 @@ def _clean_path(path): new_value = new_value.replace("//", "/") return new_value + @staticmethod + def _get_relative_path(path, src_dirpath): + dirpath, basename = os.path.split(path) + if not dirpath.lower().startswith(src_dirpath.lower()): + return None + + relative_dir = dirpath[len(src_dirpath):].lstrip("/") + if relative_dir: + relative_path = "/".join([relative_dir, basename]) + else: + relative_path = basename + return relative_path + @property def frame(self): """First frame of representation files. @@ -429,20 +448,16 @@ def _get_source_files_with_frames(self): filepath = self._clean_path( filepath_template.format(root=self._roots) ) - dirpath, basename = os.path.split(filepath_template) if ( - dirpath != src_dirpath + dirpath.lower() != src_dirpath.lower() or not src_basename_regex.match(basename) ): - relative_dir = dirpath.replace(src_dirpath, "") - if relative_dir: - relative_path = "/".join([relative_dir, basename]) - else: - relative_path = basename + relative_path = self._get_relative_path(filepath, src_dirpath) resource_files.append(ResourceFile(filepath, relative_path)) continue + filepath = os.path.join(src_dirpath, basename) frame = None udim = None for item in src_basename_regex.finditer(basename): @@ -475,16 +490,14 @@ def _get_source_files(self): filepath = self._clean_path( filepath_template.format(root=self._roots)) - if filepath_template == repre_path: - src_files.append(SourceFile(filepath)) + if filepath_template.lower() == repre_path.lower(): + src_files.append( + SourceFile(repre_path.format(root=self._roots)) + ) else: - dirpath, basename = os.path.split(filepath_template) - relative_dir = dirpath.replace(src_dirpath, "") - if relative_dir: - relative_path = "/".join([relative_dir, basename]) - else: - relative_path = basename - + relative_path = self._get_relative_path( + filepath_template, src_dirpath + ) resource_files.append( ResourceFile(filepath, relative_path) )