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

Commit

Permalink
Report case sensitivity issues for create folder structure operation
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyprien CAILLOT committed Sep 11, 2024
1 parent d9731d0 commit 8140cda
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,44 @@ def launch(self, session, entities, event):
}

# Invoking OpenPype API to create the project folders
create_project_folders(project_name, basic_paths)
case_sensitivity_issues = create_project_folders(project_name, basic_paths)
# Even if there are case sensitivity issues, the folders have been created,
# so we still need to create the entities and trigger the event normally
self.create_ftrack_entities(basic_paths, project_entity)

self.trigger_event(
"openpype.project.structure.created",
{"project_name": project_name}
)

# Inform the user of the issues (if any)
if case_sensitivity_issues:
# Prepare the list of pair paths that coexist
path_list_str = ""
for issue in case_sensitivity_issues:
path_list_str = path_list_str + "\n{}\n{}\n".format(issue[0], issue[1])

# Return the issue message form
return {
"type": "form",
"items": [
{
"type": "label",
"value": "#Warning: Case sensitivity issue(s)!"
},
{
"type": "label",
"value": "The following pair of paths coexist in the same parent directory "
"and its probably an issue (only the first folder path of every pair "
"should exists):\n{}".format(path_list_str)
},
{
"type": "label",
"value": "Please move content and delete duplicate folders."
}
],
"title": "Create Project Structure",
"submit_button_label": "I will do the changes"
}
except Exception as exc:
self.log.warning("Creating of structure crashed.", exc_info=True)
session.rollback()
Expand Down
43 changes: 36 additions & 7 deletions openpype/pipeline/project_folders.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import six

from pathlib import Path

from openpype.settings import get_project_settings
from openpype.lib import Logger

Expand Down Expand Up @@ -63,24 +65,51 @@ def fill_paths(path_list, anatomy):

def create_project_folders(project_name, basic_paths=None):
log = Logger.get_logger("create_project_folders")

case_sensitivity_issues = []

anatomy = Anatomy(project_name)
if basic_paths is None:
basic_paths = get_project_basic_paths(project_name)

if not basic_paths:
return
return case_sensitivity_issues

concat_paths = concatenate_splitted_paths(basic_paths, anatomy)
filled_paths = fill_paths(concat_paths, anatomy)

# Create folders
for path in filled_paths:
if os.path.exists(path):
log.debug("Folder already exists: {}".format(path))
else:
log.debug("Creating folder: {}".format(path))
os.makedirs(path)
case_sensitivity_issues = []
for path_str in filled_paths:
path = Path(path_str)

if path.is_dir():
log.debug("Folder already exists: {}".format(path_str))
else:
log.debug("Creating folder: {}".format(path_str))
# Check case-insensitive for the whole path
# Needed for case-sensitive OSs (Unix based)
path_parent = Path(path.absolute().parts[0])
path_parts = path.absolute().parts[1:]
# We need to check for every part of the path because
# os.makedirs can create multiple levels of directory at a time
for path_part in path_parts:
path_current = path_parent.joinpath(path_part)
# Check if the current path already exists
if path_current.exists():
# Set the current dir as the new parent
path_parent = path_current
continue
# Else check for doppelgängers
for dir_child_path_str in os.listdir(path_parent):
if dir_child_path_str.lower() == path_part.lower():
case_sensitivity_issues.append((path_current, str(path_parent.joinpath(dir_child_path_str))))
# Still create the directory
os.makedirs(path_current)
# Set the current dir as the new parent
path_parent = path_current

return case_sensitivity_issues

def _list_path_items(folder_structure):
output = []
Expand Down

0 comments on commit 8140cda

Please sign in to comment.