-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add util to copy published data using the entity structure
- Loading branch information
Showing
4 changed files
with
92 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
designsafe/apps/api/projects_v2/migration_utils/publication_file_operations.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
"""Operations to format published data in accordance with the project structure""" | ||
|
||
import shutil | ||
import os | ||
from pathlib import Path | ||
from designsafe.apps.api.projects_v2.migration_utils.graph_constructor import ( | ||
transform_pub_entities, | ||
) | ||
|
||
|
||
def format_publication_data( | ||
project_id, | ||
version=None, | ||
v1_pubs_root="/corral-repl/tacc/NHERI/published", | ||
v2_pubs_root="/corral-repl/tacc/NHERI/published-v2", | ||
): | ||
""" | ||
Format publication data in accordance with the project structure. | ||
Hard links are used for "copying" files in order to avoid duplicating them on disk. | ||
""" | ||
pub_graph, path_mappings = transform_pub_entities(project_id, version) | ||
|
||
base_project = next( | ||
( | ||
node | ||
for node in pub_graph | ||
if pub_graph.nodes[node]["name"] == "designsafe.project" | ||
) | ||
) | ||
prj_value = pub_graph.nodes[base_project] | ||
|
||
if prj_value["value"]["projectType"] == "other": | ||
base_path = prj_value["basePath"] | ||
v1_full_path = Path(v1_pubs_root) / Path(project_id) | ||
v2_full_path = Path(v2_pubs_root) / Path(base_path.lstrip("/")) / "data" | ||
os.makedirs(str(v2_full_path.parent), exist_ok=True) | ||
shutil.copytree(v1_full_path, v2_full_path, dirs_exist_ok=True) | ||
return | ||
|
||
for mapping in path_mappings: | ||
for v1_path, v2_path in mapping.items(): | ||
v1_full_path = ( | ||
Path(v1_pubs_root) / Path(project_id) / Path(v1_path.lstrip("/")) | ||
) | ||
v2_full_path = Path(v2_pubs_root) / Path(v2_path.lstrip("/")) | ||
os.makedirs(str(v2_full_path.parent), exist_ok=True) | ||
if v1_full_path.is_dir(): | ||
shutil.copytree( | ||
v1_full_path, | ||
v2_full_path, | ||
dirs_exist_ok=True, | ||
) | ||
else: | ||
shutil.copy2(v1_full_path, v2_full_path) | ||
|
||
|
||
def format_publication_data_symlink( | ||
project_id, | ||
version=None, | ||
v1_pubs_root="/corral-repl/tacc/NHERI/published", | ||
v2_pubs_root="/corral-repl/tacc/NHERI/published-v2", | ||
): | ||
""" | ||
Format publication data in accordance with the project structure. | ||
Hard links are used for "copying" files in order to avoid duplicating them on disk. | ||
""" | ||
_, path_mappings = transform_pub_entities(project_id, version) | ||
|
||
for mapping in path_mappings: | ||
for v1_path, v2_path in mapping.items(): | ||
v1_full_path = ( | ||
Path(v1_pubs_root) / Path(project_id) / Path(v1_path.lstrip("/")) | ||
) | ||
v2_full_path = Path(v2_pubs_root) / Path(v2_path.lstrip("/")) | ||
os.makedirs(str(v2_full_path.parent), exist_ok=True) | ||
os.symlink(v1_full_path, v2_full_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters