Skip to content

Commit fbdff8f

Browse files
committed
Compress round logs after tournament
1 parent ac1b506 commit fbdff8f

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

codeclash/tournaments/pvp.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
"""
44

55
import json
6+
import shutil
7+
import subprocess
68
from concurrent.futures import ThreadPoolExecutor
79
from pathlib import Path
810

@@ -127,7 +129,29 @@ def _save(self) -> None:
127129
self.local_output_dir.mkdir(parents=True, exist_ok=True)
128130
(self.local_output_dir / "metadata.json").write_text(json.dumps(self.get_metadata(), indent=2))
129131

132+
def _compress_round_logs(self) -> None:
133+
self.logger.info("Compressing round logs, this might take a while...")
134+
rounds_dir = self.game.log_local / "rounds"
135+
if not rounds_dir.exists():
136+
return
137+
138+
cmd = [
139+
"tar",
140+
"-zcf",
141+
str(self.game.log_local / "rounds.tar.gz"),
142+
"-C",
143+
str(self.game.log_local),
144+
"rounds",
145+
]
146+
result = subprocess.run(cmd, capture_output=True, text=True)
147+
if result.returncode != 0:
148+
raise RuntimeError(f"Command failed with exit code {result.returncode}:\n{result.stderr}")
149+
# Remove the original round logs
150+
shutil.rmtree(self.game.log_local / "rounds")
151+
self.logger.info("Round logs compressed successfully")
152+
130153
def end(self) -> None:
131154
"""Save output files, clean up game resources and push agents if requested."""
132155
self._save()
133156
self.game.end(self.cleanup_on_end)
157+
self._compress_round_logs()

0 commit comments

Comments
 (0)