Spaces:
Running
Running
| """Sube los artefactos de EJES a Azure (report_artifacts root) para que el Space los consuma. | |
| Recorre data/analysis/next_goal/artifacts/ejes/<slug>/<season>/* del repo Racing y sube cada | |
| archivo a ``{azure_report_artifacts_root}/ejes/...``. Chicos (~11MB total). | |
| Uso: python scripts/upload_ejes_artifacts.py [--source ../data/analysis/next_goal/artifacts/ejes] [--overwrite] | |
| """ | |
| from __future__ import annotations | |
| import argparse | |
| import sys | |
| from pathlib import Path | |
| sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src")) | |
| from racing_reports.config import DEFAULT_SETTINGS | |
| from racing_reports.datastore import DataStore, _azure_credential # noqa: F401 | |
| from azure.storage.filedatalake import DataLakeServiceClient | |
| DEFAULT_SOURCE = Path(__file__).resolve().parents[2] / "data" / "analysis" / "next_goal" / "artifacts" / "ejes" | |
| def main() -> None: | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("--source", type=Path, default=DEFAULT_SOURCE) | |
| ap.add_argument("--overwrite", action="store_true") | |
| args = ap.parse_args() | |
| src: Path = args.source | |
| if not src.is_dir(): | |
| raise SystemExit(f"No existe {src}") | |
| fs = DataStore()._filesystem_client() | |
| root = DEFAULT_SETTINGS.azure_report_artifacts_root.strip("/") | |
| files = [p for p in src.rglob("*") if p.is_file() and not p.name.startswith("_")] | |
| print(f"{len(files)} archivos → {root}/ejes/") | |
| subidos = saltados = 0 | |
| for p in files: | |
| rel = p.relative_to(src).as_posix() | |
| remote = f"{root}/ejes/{rel}" | |
| fc = fs.get_file_client(remote) | |
| if not args.overwrite: | |
| try: | |
| fc.get_file_properties() | |
| saltados += 1 | |
| continue | |
| except Exception: | |
| pass | |
| fc.upload_data(p.read_bytes(), overwrite=True) | |
| subidos += 1 | |
| print(f"subidos: {subidos} | ya estaban: {saltados}") | |
| if __name__ == "__main__": | |
| main() | |