From 67e10bfd43e0193c755017eb6a6fcf05235e2a27 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Thu, 19 Jan 2023 03:43:48 +0100 Subject: [PATCH 1/6] fix change of project --- openpype/tools/push_to_project/window.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/openpype/tools/push_to_project/window.py b/openpype/tools/push_to_project/window.py index e62650ec534..c0c47fd40ee 100644 --- a/openpype/tools/push_to_project/window.py +++ b/openpype/tools/push_to_project/window.py @@ -230,9 +230,13 @@ def _on_refresh_finish(self, event): item = self._items.pop(item_id, None) if item is None: continue + row = item.row() + if row < 0: + continue parent = item.parent() - if parent is not None: - parent.takeRow(item.row()) + if parent is None: + parent = root_item + parent.takeRow(row) self.items_changed.emit() From bfed990e4fb9b20957d86e2817c2c61669519488 Mon Sep 17 00:00:00 2001 From: Jakub Trllo Date: Thu, 19 Jan 2023 12:38:22 +0100 Subject: [PATCH 2/6] normalize path --- openpype/tools/push_to_project/control_integrate.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/openpype/tools/push_to_project/control_integrate.py b/openpype/tools/push_to_project/control_integrate.py index 819724ad4c2..5cc9dbc3bbd 100644 --- a/openpype/tools/push_to_project/control_integrate.py +++ b/openpype/tools/push_to_project/control_integrate.py @@ -419,7 +419,9 @@ def _get_source_files_with_frames(self): src_basename_regex = re.compile("^{}$".format(src_basename)) for file_info in self._repre_doc["files"]: filepath_template = file_info["path"].replace("\\", "/") - filepath = filepath_template.format(root=self._roots) + filepath = os.path.normpath( + filepath_template.format(root=self._roots) + ) dirpath, basename = os.path.split(filepath_template) if ( dirpath != src_dirpath From 5fa000803a8def99fade6614b0003640cc51edf7 Mon Sep 17 00:00:00 2001 From: Jakub Trllo Date: Thu, 19 Jan 2023 14:36:25 +0100 Subject: [PATCH 3/6] add universal clean path method --- .../push_to_project/control_integrate.py | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/openpype/tools/push_to_project/control_integrate.py b/openpype/tools/push_to_project/control_integrate.py index 5cc9dbc3bbd..7e518d80428 100644 --- a/openpype/tools/push_to_project/control_integrate.py +++ b/openpype/tools/push_to_project/control_integrate.py @@ -326,6 +326,13 @@ def resource_files(self): self.get_source_files() return self._resource_files + @staticmethod + def _clean_path(path): + new_value = path.replace("\\", "/") + while "//" in new_value: + new_value = new_value.replace("//", "/") + return new_value + @property def frame(self): """First frame of representation files. @@ -407,8 +414,8 @@ def _get_source_files_with_frames(self): fill_roots = fill_repre_context["root"] for root_name in tuple(fill_roots.keys()): fill_roots[root_name] = "{{root[{}]}}".format(root_name) - repre_path = StringTemplate.format_template(template, - fill_repre_context) + repre_path = StringTemplate.format_template( + template, fill_repre_context) repre_path = repre_path.replace("\\", "/") src_dirpath, src_basename = os.path.split(repre_path) src_basename = ( @@ -418,10 +425,11 @@ def _get_source_files_with_frames(self): ) src_basename_regex = re.compile("^{}$".format(src_basename)) for file_info in self._repre_doc["files"]: - filepath_template = file_info["path"].replace("\\", "/") - filepath = os.path.normpath( + filepath_template = self._clean_path(file_info["path"]) + filepath = self._clean_path( filepath_template.format(root=self._roots) ) + dirpath, basename = os.path.split(filepath_template) if ( dirpath != src_dirpath @@ -463,8 +471,10 @@ def _get_source_files(self): repre_path = repre_path.replace("\\", "/") src_dirpath = os.path.dirname(repre_path) for file_info in self._repre_doc["files"]: - filepath_template = file_info["path"].replace("\\", "/") - filepath = filepath_template.format(root=self._roots) + filepath_template = self._clean_path(file_info["path"]) + filepath = self._clean_path( + filepath_template.format(root=self._roots)) + if filepath_template == repre_path: src_files.append(SourceFile(filepath)) else: From aab842e4b7223df6b547dce69f62e0f69a599328 Mon Sep 17 00:00:00 2001 From: Jakub Trllo Date: Thu, 19 Jan 2023 15:21:47 +0100 Subject: [PATCH 4/6] fix find of root templates in anatomy --- openpype/pipeline/anatomy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openpype/pipeline/anatomy.py b/openpype/pipeline/anatomy.py index 72f30d85cb0..a18b46d9ac4 100644 --- a/openpype/pipeline/anatomy.py +++ b/openpype/pipeline/anatomy.py @@ -1126,7 +1126,7 @@ def find_root_template_from_path(self, path): if _mod_path.startswith(root_path): result = True replacement = "{" + self.full_key() + "}" - output = replacement + _mod_path[len(root_path):] + output = replacement + mod_path[len(root_path):] break return (result, output) From 813dc264888c6a3a4c136ba07bc93cdf8046434c Mon Sep 17 00:00:00 2001 From: Jakub Trllo Date: Thu, 19 Jan 2023 15:33:32 +0100 Subject: [PATCH 5/6] clean repre path too --- openpype/tools/push_to_project/control_integrate.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openpype/tools/push_to_project/control_integrate.py b/openpype/tools/push_to_project/control_integrate.py index 7e518d80428..8457f2d9107 100644 --- a/openpype/tools/push_to_project/control_integrate.py +++ b/openpype/tools/push_to_project/control_integrate.py @@ -416,7 +416,7 @@ def _get_source_files_with_frames(self): fill_roots[root_name] = "{{root[{}]}}".format(root_name) repre_path = StringTemplate.format_template( template, fill_repre_context) - repre_path = repre_path.replace("\\", "/") + repre_path = self._clean_path(repre_path) src_dirpath, src_basename = os.path.split(repre_path) src_basename = ( re.escape(src_basename) @@ -468,7 +468,7 @@ def _get_source_files(self): fill_roots[root_name] = "{{root[{}]}}".format(root_name) repre_path = StringTemplate.format_template(template, fill_repre_context) - repre_path = repre_path.replace("\\", "/") + repre_path = self._clean_path(repre_path) src_dirpath = os.path.dirname(repre_path) for file_info in self._repre_doc["files"]: filepath_template = self._clean_path(file_info["path"]) From 281f8bc86e716de0ff822d31052ccd46ea52b84b Mon Sep 17 00:00:00 2001 From: Jakub Trllo Date: Thu, 19 Jan 2023 15:40:44 +0100 Subject: [PATCH 6/6] 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) )