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

[QUAD] Enhancement : Report case sensitivity issues for create folder structure operation #6291

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (87 > 79 characters)

# Even if there are case sensitivity issues, the folders have been created,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (87 > 79 characters)

# so we still need to create the entities and trigger the event normally
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (84 > 79 characters)

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])
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (91 > 79 characters)


# 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 "
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (104 > 79 characters)

"and its probably an issue (only the first folder path of every pair "
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (107 > 79 characters)

"should exists):\n{}".format(path_list_str)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (80 > 79 characters)

},
{
"type": "label",
"value": "Please move content and delete duplicate folders."
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (88 > 79 characters)

}
],
"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))))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (117 > 79 characters)

# 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
Loading