Skip to content

Commit

Permalink
not use relpath by default
Browse files Browse the repository at this point in the history
  • Loading branch information
samwaseda committed Aug 7, 2024
1 parent a5a56b9 commit e7b5732
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
10 changes: 6 additions & 4 deletions pyiron_base/project/archiving/export_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def update_project(project_instance, directory_to_transfer, archive_directory, d


def copy_files_to_archive(
directory_to_transfer, archive_directory, compress=True, copy_all_files=False
directory_to_transfer, archive_directory, compress=True, copy_all_files=False, arcname=None
):
"""
Copy files from a directory to an archive, optionally compressing the archive.
Expand Down Expand Up @@ -67,6 +67,10 @@ def copy_files(origin, destination, copy_all_files=copy_all_files):
copy_h5_files(origin, destination)

assert isinstance(archive_directory, str) and ".tar.gz" not in archive_directory
if arcname is None:
arcname = os.path.relpath(
os.path.abspath(archive_directory), os.getcwd()
)
dir_name_transfer = getdir(path=directory_to_transfer)
if not compress:
copy_files(
Expand All @@ -81,9 +85,7 @@ def copy_files(origin, destination, copy_all_files=copy_all_files):
with tarfile.open(f"{archive_directory}.tar.gz", "w:gz") as tar:
tar.add(
temp_dir,
arcname=os.path.relpath(
os.path.abspath(archive_directory), os.getcwd()
),
arcname=arcname,
)


Expand Down
11 changes: 7 additions & 4 deletions pyiron_base/project/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1975,11 +1975,13 @@ def pack(
copy_all_files (bool):
"""
if destination_path is None:
destination_path = os.path.dirname(self.path)
destination_path_abs = os.path.abspath(destination_path)
if ".tar.gz" in destination_path_abs:
destination_path_abs = destination_path_abs.split(".tar.gz")[0]
destination_path = self.path
if os.path.isabs(destination_path):
destination_path = os.path.relpath(destination_path, os.getcwd())
if ".tar.gz" in destination_path:
destination_path = destination_path.split(".tar.gz")[0]
compress = True
destination_path_abs = os.path.abspath(destination_path)
directory_to_transfer = os.path.abspath(self.path)
assert not destination_path_abs.endswith(".tar")
assert not destination_path_abs.endswith(".gz")
Expand All @@ -1995,6 +1997,7 @@ def pack(
destination_path_abs,
compress=compress,
copy_all_files=copy_all_files,
arcname=destination_path,
)
df = export_archive.export_database(
self, directory_to_transfer, destination_path_abs
Expand Down

0 comments on commit e7b5732

Please sign in to comment.