-
Notifications
You must be signed in to change notification settings - Fork 127
[QUAD] Enhancement : Report case sensitivity issues for create folder structure operation #6291
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
|
||
import six | ||
|
||
from pathlib import Path | ||
|
||
from openpype.settings import get_project_settings | ||
from openpype.lib import Logger | ||
|
||
|
@@ -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)))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 = [] | ||
|
There was a problem hiding this comment.
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)