|
19 | 19 | import tempfile |
20 | 20 | import shutil |
21 | 21 | import os |
| 22 | +import gzip |
22 | 23 |
|
23 | 24 | from genesis_devtools.builder import base |
24 | 25 | from genesis_devtools.logger import AbstractLogger, DummyLogger |
@@ -80,10 +81,23 @@ def _build_image( |
80 | 81 | if not os.path.exists(self._images_output_dir): |
81 | 82 | os.makedirs(self._images_output_dir) |
82 | 83 |
|
83 | | - shutil.move( |
84 | | - os.path.join(output_dir, f"{img.name}.{img.format}"), |
85 | | - self._images_output_dir, |
86 | | - ) |
| 84 | + # Determine source path to move. If gzip was requested, |
| 85 | + # compress RAW -> GZ first. |
| 86 | + if img.format == "gz": |
| 87 | + self._logger.info(f"Compressing {img.name} to {img.name}.raw.gz") |
| 88 | + # Source RAW image produced by Packer |
| 89 | + raw_src = os.path.join(output_dir, f"{img.name}.raw") |
| 90 | + gz_tgt = os.path.join( |
| 91 | + self._images_output_dir, f"{img.name}.raw.gz" |
| 92 | + ) |
| 93 | + # Compress using standard library (gzip uses zlib) with level 5 |
| 94 | + with open(raw_src, "rb") as f_in, gzip.open( |
| 95 | + gz_tgt, "wb", compresslevel=5 |
| 96 | + ) as f_out: |
| 97 | + shutil.copyfileobj(f_in, f_out) |
| 98 | + else: |
| 99 | + src_path = os.path.join(output_dir, f"{img.name}.{img.format}") |
| 100 | + shutil.move(src_path, self._images_output_dir) |
87 | 101 |
|
88 | 102 | def fetch_dependency(self, deps_dir: str) -> None: |
89 | 103 | """Fetch common dependencies for elements.""" |
|
0 commit comments