further deployment implementation to .config directory
This commit is contained in:
@@ -16,6 +16,7 @@ import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import time
|
||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||
from pathlib import Path
|
||||
from typing import Iterator, Sequence
|
||||
@@ -195,27 +196,50 @@ def zip_sequence(seq_dir: Path, zip_path: Path) -> None:
|
||||
if SEVEN_Z_EXE is None:
|
||||
raise RuntimeError("7z compression requested but 7z executable not found in PATH")
|
||||
zip_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
# Remove existing zip file if it exists to avoid corruption issues
|
||||
if zip_path.exists():
|
||||
try:
|
||||
zip_path.unlink()
|
||||
except OSError:
|
||||
# If deletion fails, try to overwrite with -aoa flag
|
||||
pass
|
||||
|
||||
# Build list of files to archive with relative paths
|
||||
file_list = []
|
||||
for file_path in iter_sequence_files(seq_dir):
|
||||
rel_path = file_path.relative_to(seq_dir).as_posix()
|
||||
file_list.append(rel_path)
|
||||
|
||||
# Use a temporary list file to avoid Windows command line length limits
|
||||
with tempfile.NamedTemporaryFile(mode="w", suffix=".lst", delete=False, encoding="utf-8") as list_file:
|
||||
list_file_path = Path(list_file.name)
|
||||
for rel_path in file_list:
|
||||
list_file.write(rel_path + "\n")
|
||||
if not file_list:
|
||||
raise RuntimeError(f"No files found to archive in {seq_dir}")
|
||||
|
||||
# Use a temporary list file to avoid Windows command line length limits
|
||||
list_file_path = None
|
||||
try:
|
||||
# Create list file with absolute path
|
||||
fd, temp_path = tempfile.mkstemp(suffix=".lst", text=True)
|
||||
list_file_path = Path(temp_path)
|
||||
with os.fdopen(fd, "w", encoding="utf-8") as list_file:
|
||||
for rel_path in file_list:
|
||||
list_file.write(rel_path + "\n")
|
||||
list_file.flush()
|
||||
os.fsync(list_file.fileno()) # Ensure data is written to disk
|
||||
# File is closed here by context manager, small delay to ensure OS releases handle
|
||||
time.sleep(0.1)
|
||||
|
||||
# Use absolute path for list file in 7z command
|
||||
list_file_abs = list_file_path.resolve()
|
||||
# Use -aoa to overwrite all files, -bb0 to suppress progress output
|
||||
cmd = [
|
||||
SEVEN_Z_EXE,
|
||||
"a",
|
||||
"-y",
|
||||
"-aoa", # Overwrite all existing files
|
||||
"-bb0", # Suppress progress output
|
||||
f"-mx={COMPRESSION_LEVEL}",
|
||||
"-tzip",
|
||||
str(zip_path),
|
||||
f"@{list_file_path}",
|
||||
f"@{list_file_abs}",
|
||||
]
|
||||
result = subprocess.run(
|
||||
cmd,
|
||||
@@ -226,9 +250,24 @@ def zip_sequence(seq_dir: Path, zip_path: Path) -> None:
|
||||
text=True,
|
||||
)
|
||||
if result.returncode != 0:
|
||||
raise RuntimeError(f"7z compression failed: {result.stderr}")
|
||||
error_msg = result.stderr.strip() if result.stderr else "Unknown error"
|
||||
if result.stdout:
|
||||
error_msg += f"\nstdout: {result.stdout.strip()}"
|
||||
raise RuntimeError(f"7z compression failed: {error_msg}")
|
||||
finally:
|
||||
list_file_path.unlink(missing_ok=True)
|
||||
# Clean up list file, with retry in case 7z still has it open
|
||||
if list_file_path and list_file_path.exists():
|
||||
for attempt in range(3):
|
||||
try:
|
||||
list_file_path.unlink(missing_ok=True)
|
||||
break
|
||||
except PermissionError:
|
||||
if attempt < 2:
|
||||
time.sleep(0.1) # Wait 100ms before retry
|
||||
else:
|
||||
# Last attempt failed, just log and continue
|
||||
# The temp file will be cleaned up by the OS eventually
|
||||
pass
|
||||
return
|
||||
|
||||
# Use zipfile (ZIPPER_TYPE == "zip" or fallback)
|
||||
|
||||
Reference in New Issue
Block a user