Esko+artios+cad+v120+torrentzip+new
#!/usr/bin/env python3
"""
Batch export Artios CAD files to PDF + deterministic ZIP.
Requires:
- artioscad-cli (v120) installed and added to PATH
- torrentzip (pip install torrentzip)
"""
import subprocess
import pathlib
import hashlib
import os
from torrentzip import TorrentZip
# ----------------------------------------------------------------------
# CONFIGURATION
# ----------------------------------------------------------------------
ARTIOSCAD_EXE = "artioscad-cli.exe" # or just "artioscad-cli" on macOS
SOURCE_DIR = pathlib.Path(r"C:\Designs\NewProject")
EXPORT_DIR = pathlib.Path(r"C:\Designs\NewProject\Exports")
ZIP_NAME = "NewProject_v1.0.zip"
FIXED_DATE = "2000-01-01T00:00:00Z" # ISO8601 timestamp for torrentzip
# ----------------------------------------------------------------------
def export_to_pdf(ard_file: pathlib.Path) -> pathlib.Path:
"""Export a single .ard file to PDF using the CLI."""
out_pdf = EXPORT_DIR / f"ard_file.stem.pdf"
cmd = [
ARTIOSCAD_EXE,
"--export-pdf",
str(ard_file),
str(out_pdf)
]
subprocess.run(cmd, check=True)
return out_pdf
def zip_deterministic(folder: pathlib.Path, zip_path: pathlib.Path):
"""Create a deterministic zip using torrentzip."""
tz = TorrentZip(
folder=folder,
output=zip_path,
timestamp=FIXED_DATE,
compression=9,
include_hidden=False,
)
tz.create()
print(f"✅ Deterministic zip created: zip_path")
def sha256(file_path: pathlib.Path) -> str:
h = hashlib.sha256()
with open(file_path, "rb") as f:
for chunk in iter(lambda: f.read(8192), b""):
h.update(chunk)
return h.hexdigest()
# ----------------------------------------------------------------------
if __name__ == "__main__":
EXPORT_DIR.mkdir(parents=True, exist_ok=True)
# 1️⃣ Export every .ard in the source folder
pdf_paths = []
for ard in SOURCE_DIR.glob("*.ard"):
pdf = export_to_pdf(ard)
pdf_paths.append(pdf)
# 2️⃣ Copy source ARD files + PDFs into a staging folder
STAGE = EXPORT_DIR / "stage"
STAGE.mkdir(parents=True, exist_ok=True)
for file in list(SOURCE_DIR.glob("*.ard")) + pdf_paths:
target = STAGE / file.name
target.write_bytes(file.read_bytes())
# 3️⃣ Create deterministic zip
zip_path = EXPORT_DIR / ZIP_NAME
zip_deterministic(STAGE, zip_path)
# 4️⃣ Print hash for audit / CI pipelines
print("🧾 SHA‑256:", sha256(zip_path))
What this script does
Published: April 2026
TorrentZip (TZ) is a command‑line utility that creates deterministic ZIP archives. Determinism means that given the same set of input files, TZ will always produce a byte‑identical ZIP file regardless of: esko+artios+cad+v120+torrentzip+new
| Variable | Standard ZIP Behavior | TorrentZip Behavior |
|---|---|---|
| File order | Depends on OS enumeration (often nondeterministic) | Sorted alphabetically, then by case‑insensitive path |
| Timestamps | Stored as local file modification time | Normalised to a fixed epoch (e.g., 2000‑01‑01 00:00:00 UTC) |
| Permissions & extra fields | Preserved verbatim (may differ by filesystem) | Stripped or standardised |
| Compression metadata | Varies with library version and thread count | Fixed compression level (-9) and dictionary | What this script does
Published: April 2026
Because the output is predictable, any change in the source files results in a different hash (SHA‑256, MD5, etc.). This property is essential for: TorrentZip (TZ) is a command‑line utility that creates