#!/usr/bin/env python3 from __future__ import annotations import argparse from pathlib import Path import shutil import subprocess from urllib.parse import urlparse def download_s3_source(source_uri: str, destination: Path) -> None: aws_path = shutil.which("aws") if aws_path: subprocess.run( [ aws_path, "s3", "cp", source_uri, str(destination), "--only-show-errors", ], check=True, ) return parsed = urlparse(source_uri) if parsed.scheme != "s3" or not parsed.netloc or not parsed.path.lstrip("/"): raise SystemExit(f"invalid S3 source URI: {source_uri}") import boto3 boto3.client("s3").download_file( parsed.netloc, parsed.path.lstrip("/"), str(destination), ) def main() -> None: parser = argparse.ArgumentParser( description="Download a frozen Salesforce migration source from S3." ) parser.add_argument("source_uri") parser.add_argument("destination", type=Path) args = parser.parse_args() download_s3_source(args.source_uri, args.destination) if __name__ == "__main__": main()