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 #2755 from Ellipsanime/add-project-anatomy-keys-to…
Browse files Browse the repository at this point in the history
…-create-starting-folder
  • Loading branch information
mkolar authored Jun 27, 2022
2 parents 46647ab + 070e1fb commit 0769c9f
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 29 deletions.
89 changes: 61 additions & 28 deletions openpype/lib/path_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from .anatomy import Anatomy
from .profiles_filtering import filter_profiles

import avalon.api

log = logging.getLogger(__name__)


Expand Down Expand Up @@ -171,45 +173,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 @@ -308,6 +340,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 @@ -401,7 +401,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

0 comments on commit 0769c9f

Please sign in to comment.