Skip to content

Commit e2c271f

Browse files
committed
added zip capability for all CMS types, refactored around repo chgs
1 parent 791c9f0 commit e2c271f

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# chmod +x zip_ssd_deployment_individual_files.py
2+
#!/usr/bin/env python3
3+
4+
# cd /workspaces/ssd-data-model/admin/tools-ssd_workflow/admin/
5+
# python zip_ssd_deployment_individual_files.py
6+
7+
8+
import zipfile
9+
from pathlib import Path
10+
from datetime import date
11+
12+
13+
def find_deployment_extracts_root() -> Path:
14+
"""
15+
Walk up from this script until finding 'deployment_extracts' folder
16+
"""
17+
script_path = Path(__file__).resolve()
18+
19+
for parent in script_path.parents:
20+
candidate = parent / "deployment_extracts"
21+
if candidate.is_dir():
22+
return candidate
23+
24+
raise SystemExit(
25+
"Couldn't find 'deployment_extracts' folder by walking up from script location"
26+
)
27+
28+
29+
def build_vendor_bundle(vendor_dir: Path, today_str: str) -> None:
30+
"""
31+
Build zip bundle for each single vendor folder, e..g:
32+
deployment_extracts/mosaic/live
33+
deployment_extracts/eclipse/live
34+
35+
Assumptions:
36+
- SQL files to zip in:
37+
deployment_extracts/<vendor>/live/ssd_deployment_individual_files/*.sql
38+
fallback to:
39+
deployment_extracts/<vendor>/live/*.sql
40+
"""
41+
vendor_name = vendor_dir.name # mosaic, eclipse, etc.
42+
live_dir = vendor_dir / "live"
43+
44+
if not live_dir.is_dir():
45+
print(f"Skipping {vendor_name} (no live directory at {live_dir})")
46+
return
47+
48+
# Init input root is ssd_deployment_individual_files
49+
input_root = live_dir / "ssd_deployment_individual_files"
50+
if not input_root.is_dir():
51+
input_root = live_dir
52+
53+
# All CMS type folders: only zip *.sql files
54+
candidates = list(input_root.rglob("*.sql"))
55+
56+
files_to_zip = []
57+
for path in candidates:
58+
# Avoid including current or previous deployment bundles
59+
if path.name.endswith(f"ssd_{vendor_name}_deployment_download.zip"):
60+
continue
61+
files_to_zip.append(path)
62+
63+
if not files_to_zip:
64+
print(f"Skipping {vendor_name} (no .sql files to zip in {input_root})")
65+
return
66+
67+
# Eg: 2025-11-25-ssd_mosaic_deployment_download.zip
68+
zip_name = f"{today_str}-ssd_{vendor_name}_deployment_download.zip"
69+
zip_path = live_dir / zip_name
70+
71+
with zipfile.ZipFile(zip_path, mode="w", compression=zipfile.ZIP_DEFLATED) as zf:
72+
for file_path in files_to_zip:
73+
# Store paths relative to live directory
74+
arcname = file_path.relative_to(live_dir)
75+
zf.write(file_path, arcname)
76+
77+
print(f"Created zip for {vendor_name}: {zip_path}")
78+
79+
80+
def main() -> None:
81+
deployment_extracts_root = find_deployment_extracts_root()
82+
today_str = date.today().strftime("%Y-%m-%d")
83+
84+
any_built = False
85+
86+
# Iterate CMS folders, mosaic, eclipse
87+
for vendor_dir in sorted(deployment_extracts_root.iterdir()):
88+
if not vendor_dir.is_dir():
89+
continue
90+
build_vendor_bundle(vendor_dir, today_str)
91+
any_built = True
92+
93+
if not any_built:
94+
raise SystemExit("No deployment bundles created. Check folders and contents")
95+
96+
97+
if __name__ == "__main__":
98+
main()

0 commit comments

Comments
 (0)