Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #4350 from ynput/bugfix/push_to_project_hierarchy
Browse files Browse the repository at this point in the history
PushToProject: Fix hierarchy of project change
  • Loading branch information
iLLiCiTiT authored Jan 19, 2023
2 parents 4b0b6e6 + 281f8bc commit e81e4b2
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 26 deletions.
2 changes: 1 addition & 1 deletion openpype/pipeline/anatomy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
71 changes: 48 additions & 23 deletions openpype/tools/push_to_project/control_integrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__(
Expand Down Expand Up @@ -326,6 +332,26 @@ 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

@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.
Expand Down Expand Up @@ -407,9 +433,9 @@ 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 = repre_path.replace("\\", "/")
repre_path = StringTemplate.format_template(
template, fill_repre_context)
repre_path = self._clean_path(repre_path)
src_dirpath, src_basename = os.path.split(repre_path)
src_basename = (
re.escape(src_basename)
Expand All @@ -418,21 +444,20 @@ 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_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
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):
Expand All @@ -458,21 +483,21 @@ 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 = file_info["path"].replace("\\", "/")
filepath = filepath_template.format(root=self._roots)
if filepath_template == repre_path:
src_files.append(SourceFile(filepath))
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
filepath_template = self._clean_path(file_info["path"])
filepath = self._clean_path(
filepath_template.format(root=self._roots))

if filepath_template.lower() == repre_path.lower():
src_files.append(
SourceFile(repre_path.format(root=self._roots))
)
else:
relative_path = self._get_relative_path(
filepath_template, src_dirpath
)
resource_files.append(
ResourceFile(filepath, relative_path)
)
Expand Down
8 changes: 6 additions & 2 deletions openpype/tools/push_to_project/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit e81e4b2

Please sign in to comment.