-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathprepare_release.py
More file actions
61 lines (44 loc) · 1.95 KB
/
Copy pathprepare_release.py
File metadata and controls
61 lines (44 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""Prepare flat GitHub release assets from collected VVP results."""
import shutil
from pathlib import Path
# ======================================================================================
# Paths
# ======================================================================================
REPO_DIR = Path(__file__).resolve().parent
RESULTS_DIR = REPO_DIR / "results"
RELEASE_DIR = REPO_DIR / "release"
# ======================================================================================
# Discover result figures
# ======================================================================================
if not RESULTS_DIR.is_dir():
raise FileNotFoundError(f"Results directory not found: {RESULTS_DIR}")
figures = sorted(
path
for path in RESULTS_DIR.rglob("*")
if path.is_file() and path.suffix.lower() in {".png", ".gif"}
)
if not figures:
raise FileNotFoundError(f"No PNG or GIF results found in {RESULTS_DIR}")
# ======================================================================================
# Prepare flat release assets
# ======================================================================================
if RELEASE_DIR.is_dir():
shutil.rmtree(RELEASE_DIR)
RELEASE_DIR.mkdir()
total_size = 0
for source in figures:
relative_path = source.relative_to(RESULTS_DIR)
asset_name = "--".join(relative_path.parts)
destination = RELEASE_DIR / asset_name
if destination.exists():
raise FileExistsError(f"Flattened asset name is not unique: {destination.name}")
shutil.copy2(source, destination)
total_size += destination.stat().st_size
print(f"{relative_path} -> {destination.name}")
# ======================================================================================
# Summary
# ======================================================================================
print()
print(f"Assets: {len(figures)}")
print(f"Size : {total_size / 1024**2:.1f} MiB")
print(f"Release directory: {RELEASE_DIR}")