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

Add root keys and project keys to create starting folder #2755

Merged
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
90 changes: 61 additions & 29 deletions openpype/lib/path_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
import six

from openpype.settings import get_project_settings
from openpype.settings.lib import get_site_local_overrides

from .anatomy import Anatomy
from .profiles_filtering import filter_profiles

import avalon.api

log = logging.getLogger(__name__)


Expand Down Expand Up @@ -130,45 +131,75 @@ def get_last_version_from_path(path_dir, filter):
return None


def compute_paths(basic_paths_items, project_root):
def concatenate_splitted_paths(split_paths, anatomy):
pattern_array = re.compile(r"\[.*\]")
project_root_key = "__project_root__"
output = []
for path_items in basic_paths_items:
for path_items in split_paths:
clean_items = []
if isinstance(path_items, str):
path_items = [path_items]

for path_item in path_items:
matches = re.findall(pattern_array, path_item)
if len(matches) > 0:
path_item = path_item.replace(matches[0], "")
if path_item == project_root_key:
path_item = project_root
if not re.match(r"{.+}", path_item):
path_item = re.sub(pattern_array, "", path_item)
clean_items.append(path_item)

# backward compatibility
if "__project_root__" in path_items:
for root, root_path in anatomy.roots.items():
if not os.path.exists(str(root_path)):
log.debug("Root {} path path {} not exist on \
computer!".format(root, root_path))
continue
clean_items = ["{{root[{}]}}".format(root),
r"{project[name]}"] + clean_items[1:]
output.append(os.path.normpath(os.path.sep.join(clean_items)))
continue

output.append(os.path.normpath(os.path.sep.join(clean_items)))

return output


def get_format_data(anatomy):
dbcon = avalon.api.AvalonMongoDB()
dbcon.Session["AVALON_PROJECT"] = anatomy.project_name
project_doc = dbcon.find_one({"type": "project"})
project_code = project_doc["data"]["code"]

return {
"root": anatomy.roots,
"project": {
"name": anatomy.project_name,
"code": project_code
},
}


def fill_paths(path_list, anatomy):
format_data = get_format_data(anatomy)
filled_paths = []

for path in path_list:
new_path = path.format(**format_data)
filled_paths.append(new_path)

return filled_paths


def create_project_folders(basic_paths, project_name):
anatomy = Anatomy(project_name)
roots_paths = []
if isinstance(anatomy.roots, dict):
for root in anatomy.roots.values():
roots_paths.append(root.value)
else:
roots_paths.append(anatomy.roots.value)

for root_path in roots_paths:
project_root = os.path.join(root_path, project_name)
full_paths = compute_paths(basic_paths, project_root)
# Create folders
for path in full_paths:
full_path = path.format(project_root=project_root)
if os.path.exists(full_path):
log.debug(
"Folder already exists: {}".format(full_path)
)
else:
log.debug("Creating folder: {}".format(full_path))
os.makedirs(full_path)

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)


def _list_path_items(folder_structure):
Expand Down Expand Up @@ -267,6 +298,7 @@ class HostDirmap:
on_dirmap_enabled: run host code for enabling dirmap
do_dirmap: run host code to do actual remapping
"""

def __init__(self, host_name, project_settings, sync_module=None):
self.host_name = host_name
self.project_settings = project_settings
Expand Down
2 changes: 1 addition & 1 deletion openpype/settings/defaults/project_settings/global.json
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@
]
}
},
"project_folder_structure": "{\"__project_root__\": {\"prod\": {}, \"resources\": {\"footage\": {\"plates\": {}, \"offline\": {}}, \"audio\": {}, \"art_dept\": {}}, \"editorial\": {}, \"assets[ftrack.Library]\": {\"characters[ftrack]\": {}, \"locations[ftrack]\": {}}, \"shots[ftrack.Sequence]\": {\"scripts\": {}, \"editorial[ftrack.Folder]\": {}}}}",
"project_folder_structure": "{\"__project_root__\": {\"prod\": {}, \"resources\": {\"footage\": {\"plates\": {}, \"offline\": {}}, \"audio\": {}, \"art_dept\": {}}, \"editorial\": {}, \"assets\": {\"characters\": {}, \"locations\": {}}, \"shots\": {}}}",
"sync_server": {
"enabled": false,
"config": {
Expand Down