Repository navigation
Expand file tree
/
Copy pathupdate_excel_template.py
More file actions
63 lines (51 loc) · 2.37 KB
/
Copy pathupdate_excel_template.py
File metadata and controls
63 lines (51 loc) · 2.37 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
62
63
"""Vendor the official ODCS Excel template and its conformance pair into the CLI.
Downloads from the Open Data Contract Standard Excel Template repository:
- one template per supported ODCS version into datacontract/templates/excel/, which
`datacontract export excel` picks from so that no network access is needed at runtime
(committed and shipped with the package)
- the examples/*.xlsx and examples/*.yaml conformance pairs into tests/fixtures/excel/, the
workbooks + expected YAML the Excel tests assert against
Usage:
python update_excel_template.py [base-url]
python update_excel_template.py --check # exit 1 when the vendored files differ from the repository
If no base URL is given, the main branch is used.
"""
import sys
from pathlib import Path
import requests
ODCS_EXCEL_TEMPLATE_BASE_URL = (
"https://github.com/datacontract/open-data-contract-standard-excel-template/raw/refs/heads/main"
)
ROOT = Path(__file__).parent
TEMPLATES = ROOT / "datacontract" / "templates" / "excel"
FILES = {
"odcs-template-v3.0.xlsx": TEMPLATES / "odcs-template-v3.0.xlsx",
"odcs-template-v3.1.xlsx": TEMPLATES / "odcs-template-v3.1.xlsx",
"odcs-template-v3.2.xlsx": TEMPLATES / "odcs-template-v3.2.xlsx",
"examples/full-odcs-3.2.xlsx": ROOT / "tests" / "fixtures" / "excel" / "full-odcs-3.2.xlsx",
"examples/full-odcs-3.2.yaml": ROOT / "tests" / "fixtures" / "excel" / "full-odcs-3.2.yaml",
}
def main() -> int:
args = [arg for arg in sys.argv[1:] if arg != "--check"]
check = "--check" in sys.argv
base_url = (args[0] if args else ODCS_EXCEL_TEMPLATE_BASE_URL).rstrip("/")
stale = []
for name, target in FILES.items():
url = f"{base_url}/{name}"
print(f"Downloading {url}")
response = requests.get(url, timeout=60)
response.raise_for_status()
if check:
if not target.exists() or target.read_bytes() != response.content:
stale.append(str(target.relative_to(ROOT)))
continue
target.parent.mkdir(parents=True, exist_ok=True)
target.write_bytes(response.content)
print(f"Vendored {len(response.content)} bytes into {target}")
if stale:
print("Vendored copies differ from the template repository: " + ", ".join(stale))
print("Run: python update_excel_template.py")
return 1
return 0
if __name__ == "__main__":
sys.exit(main())