|
| 1 | +import argparse |
| 2 | +from pathlib import Path |
| 3 | +import requests |
| 4 | +from requests.auth import HTTPBasicAuth |
| 5 | + |
| 6 | + |
| 7 | +def main(): |
| 8 | + parser = argparse.ArgumentParser() |
| 9 | + parser.add_argument("version") |
| 10 | + args = parser.parse_args() |
| 11 | + |
| 12 | + download_jdbc(args.version) |
| 13 | + download_testng() |
| 14 | + create_user() |
| 15 | + |
| 16 | + |
| 17 | +def download_jdbc(version): |
| 18 | + |
| 19 | + files = [f"databend-jdbc-{version}.jar", f"databend-jdbc-{version}-tests.jar"] |
| 20 | + |
| 21 | + for filename in files: |
| 22 | + target = Path(f"cache/jdbc/{filename}") |
| 23 | + if target.exists(): |
| 24 | + print(f"{filename} exists") |
| 25 | + continue |
| 26 | + target.parent.mkdir(parents=True, exist_ok=True) |
| 27 | + |
| 28 | + print(f"start download {filename}") |
| 29 | + resp = requests.get( |
| 30 | + f"https://github.com/databendlabs/databend-jdbc/releases/download/v{version}/{filename}" |
| 31 | + ) |
| 32 | + resp.raise_for_status() |
| 33 | + target.write_bytes(resp.content) |
| 34 | + |
| 35 | + |
| 36 | +def create_user(): |
| 37 | + requests.post( |
| 38 | + "http://localhost:8000/v1/query/", |
| 39 | + auth=HTTPBasicAuth("root", ""), |
| 40 | + headers={"Content-Type": "application/json"}, |
| 41 | + json={"sql": "CREATE USER IF NOT EXISTS databend IDENTIFIED BY 'databend'"}, |
| 42 | + ).raise_for_status() |
| 43 | + requests.post( |
| 44 | + "http://localhost:8000/v1/query/", |
| 45 | + auth=HTTPBasicAuth("root", ""), |
| 46 | + headers={"Content-Type": "application/json"}, |
| 47 | + json={"sql": "GRANT ALL ON *.* TO databend"}, |
| 48 | + ).raise_for_status() |
| 49 | + |
| 50 | + |
| 51 | +def download_testng(): |
| 52 | + urls = [ |
| 53 | + "https://repo.maven.apache.org/maven2/org/testng/testng/7.11.0/testng-7.11.0.jar", |
| 54 | + "https://repo1.maven.org/maven2/com/vdurmont/semver4j/3.1.0/semver4j-3.1.0.jar", |
| 55 | + "https://repo1.maven.org/maven2/org/jcommander/jcommander/1.83/jcommander-1.83.jar", |
| 56 | + "https://repo1.maven.org/maven2/org/locationtech/jts/jts-core/1.19.0/jts-core-1.19.0.jar", |
| 57 | + "https://repo1.maven.org/maven2/org/slf4j/slf4j-api/2.0.16/slf4j-api-2.0.16.jar", |
| 58 | + "https://repo1.maven.org/maven2/org/slf4j/slf4j-simple/2.0.13/slf4j-simple-2.0.13.jar", |
| 59 | + "https://repo1.maven.org/maven2/org/junit/platform/junit-platform-console-standalone/1.11.3/junit-platform-console-standalone-1.11.3.jar", |
| 60 | + ] |
| 61 | + |
| 62 | + for url in urls: |
| 63 | + splited = url.rsplit("/", 1) |
| 64 | + filename = splited[1] |
| 65 | + target = Path(f"cache/lib/{filename}") |
| 66 | + if target.exists(): |
| 67 | + print(f"{filename} exists") |
| 68 | + continue |
| 69 | + target.parent.mkdir(parents=True, exist_ok=True) |
| 70 | + |
| 71 | + print(f"start download {filename}") |
| 72 | + resp = requests.get(url) |
| 73 | + resp.raise_for_status() |
| 74 | + target.write_bytes(resp.content) |
| 75 | + |
| 76 | + |
| 77 | +if __name__ == "__main__": |
| 78 | + main() |
0 commit comments