From ac17ce13c352bd49aa3060f09fdc233e17e6e672 Mon Sep 17 00:00:00 2001 From: Jendrik Seipp Date: Tue, 26 Nov 2024 18:42:11 +0100 Subject: [PATCH] Use tarfile module for compression step. --- examples/downward/project.py | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/examples/downward/project.py b/examples/downward/project.py index 2464f0d81..95c477ec6 100644 --- a/examples/downward/project.py +++ b/examples/downward/project.py @@ -1,8 +1,10 @@ import contextlib import platform import re +import shutil import subprocess import sys +import tarfile from collections import defaultdict from pathlib import Path @@ -294,22 +296,19 @@ def add_scp_step(exp, login, repos_dir): def add_compress_exp_dir_step(exp): - exp.add_step( - "compress-exp-dir", - subprocess.call, - [ - "tar", - "--verbose", - "--create", - "--dereference", - "--remove-files", - "--xz", - "--file", - f"{exp.name}.tar.xz", - exp.name, - ], - cwd=Path(exp.path).parent, - ) + def compress_exp_dir(): + tar_file_path = Path(exp.path).parent / f"{exp.name}.tar.xz" + exp_dir_path = Path(exp.path) + + with tarfile.open(tar_file_path, mode="w:xz", dereference=True) as tar: + for file in exp_dir_path.rglob("*"): + relpath = file.relative_to(exp_dir_path.parent) + print(f"Adding {relpath}") + tar.add(file, arcname=relpath) + + shutil.rmtree(exp_dir_path) + + exp.add_step("compress-exp-dir", compress_exp_dir) def fetch_algorithm(exp, expname, algo, *, new_algo=None):