|
| 1 | +import os |
| 2 | +from datetime import datetime |
| 3 | + |
| 4 | +import requests |
| 5 | +from tidy3d import web |
| 6 | +from tidy3d.web.environment import Env |
| 7 | + |
| 8 | +s3_small_file_url = "https://s3.us-gov-west-1.amazonaws.com/www.simulation.cloud/test.txt" |
| 9 | +s3_big_file_url = "https://s3.us-gov-west-1.amazonaws.com/www.simulation.cloud/50M.dat" |
| 10 | +time_url = "http://worldtimeapi.org/api/timezone/Etc/UTC" |
| 11 | +proxy_check_url = "https://httpbin.org/ip" |
| 12 | +flexcompute_robots_url = "https://www.flexcompute.com/robots.txt" |
| 13 | +simcloud_robots_url = "https://tidy3d.simulation.cloud/robots.txt" |
| 14 | + |
| 15 | + |
| 16 | +def download_s3_file_with_boto3(object_key): |
| 17 | + try: |
| 18 | + import boto3 |
| 19 | + from botocore import UNSIGNED |
| 20 | + from botocore.client import Config |
| 21 | + |
| 22 | + region_name = "us-gov-west-1" |
| 23 | + s3 = boto3.client("s3", config=Config(signature_version=UNSIGNED), region_name=region_name) |
| 24 | + s3.download_file("www.simulation.cloud", object_key, f"/tmp/{object_key}") |
| 25 | + print(f"download {object_key} with boto3 successfully") |
| 26 | + except Exception as e: |
| 27 | + print(f"download {object_key} with boto3 fails: {e}") |
| 28 | + |
| 29 | + |
| 30 | +def download_file(url): |
| 31 | + try: |
| 32 | + response = requests.get(url) |
| 33 | + if response.status_code == 200: |
| 34 | + with open("downloaded_file", "wb") as f: |
| 35 | + f.write(response.content) |
| 36 | + print(f"download {url} with request successfully") |
| 37 | + else: |
| 38 | + print(f"download {url} with request fails, status_code: {response.status_code}") |
| 39 | + except Exception as e: |
| 40 | + print(f"download {url} with request error: {e}") |
| 41 | + |
| 42 | + |
| 43 | +def get_file_content(url): |
| 44 | + try: |
| 45 | + response = requests.get(url) |
| 46 | + content = response.text |
| 47 | + return content |
| 48 | + except Exception as e: |
| 49 | + print(f"get_file_content {url} error: {e}") |
| 50 | + |
| 51 | + |
| 52 | +def get_urllib_version(): |
| 53 | + try: |
| 54 | + import urllib3 |
| 55 | + |
| 56 | + return urllib3.__version__ |
| 57 | + except Exception as e: |
| 58 | + print(f"get_urllib_version, error: {e}") |
| 59 | + |
| 60 | + |
| 61 | +def get_boto_version(): |
| 62 | + try: |
| 63 | + import importlib.metadata |
| 64 | + |
| 65 | + return importlib.metadata.version("boto3") |
| 66 | + except Exception as e: |
| 67 | + print(f"get_boto_version, error: {e}") |
| 68 | + |
| 69 | + |
| 70 | +def list_ssl_info(): |
| 71 | + try: |
| 72 | + import ssl |
| 73 | + |
| 74 | + context = ssl.create_default_context() |
| 75 | + ciphers = context.get_ciphers() |
| 76 | + for cipher in ciphers: |
| 77 | + print( |
| 78 | + f"Cipher: {cipher['name']}, Protocol: {cipher['protocol']}, Strength: {cipher['strength_bits']} bits" |
| 79 | + ) |
| 80 | + except Exception as e: |
| 81 | + print(f"list_supported_algorithms,error: {e}") |
| 82 | + |
| 83 | + |
| 84 | +def get_ssl_version(): |
| 85 | + try: |
| 86 | + import ssl |
| 87 | + |
| 88 | + openssl_version = ssl.OPENSSL_VERSION |
| 89 | + print(f"OpenSSL Version: {openssl_version}") |
| 90 | + |
| 91 | + openssl_version_number = ssl.OPENSSL_VERSION_NUMBER |
| 92 | + print(f"OpenSSL Version Number: {openssl_version_number}") |
| 93 | + |
| 94 | + print(f"OpenSSL TLS 1.1: {ssl.HAS_TLSv1_1}") |
| 95 | + print(f"OpenSSL TLS 1.2: {ssl.HAS_TLSv1_2}") |
| 96 | + print(f"OpenSSL TLS 1.3: {ssl.HAS_TLSv1_3}") |
| 97 | + except Exception as e: |
| 98 | + print(f"get_ssl_version,error: {e}") |
| 99 | + |
| 100 | + |
| 101 | +def detect_proxy_with_requests(): |
| 102 | + proxies = {"http": os.getenv("HTTP_PROXY"), "https": os.getenv("HTTPS_PROXY")} |
| 103 | + try: |
| 104 | + response = requests.get(proxy_check_url, proxies=proxies, timeout=5) |
| 105 | + data = response.json() |
| 106 | + return data |
| 107 | + except Exception as e: |
| 108 | + print("detect_proxy_with_requests: error", e) |
| 109 | + |
| 110 | + |
| 111 | +def get_network_time(): |
| 112 | + try: |
| 113 | + response = requests.get(time_url, timeout=10) |
| 114 | + response.raise_for_status() # Raises HTTPError for bad responses |
| 115 | + data = response.json() |
| 116 | + datetime_str = data.get("datetime") |
| 117 | + if datetime_str: |
| 118 | + return datetime_str |
| 119 | + except Exception as e: |
| 120 | + print("get_network_time error:{e}") |
| 121 | + |
| 122 | + |
| 123 | +def get_basic_os_info(): |
| 124 | + info = {} |
| 125 | + info["os_name"] = os.name # 'posix', 'nt', etc. |
| 126 | + info["os_version"] = os.environ # 'posix', 'nt', etc. |
| 127 | + info["env_variables"] = dict(os.environ) # Environment variables |
| 128 | + info["current_directory"] = os.getcwd() # Current working directory |
| 129 | + info["process_id"] = os.getpid() # Current process ID |
| 130 | + try: |
| 131 | + info["user"] = os.getlogin() |
| 132 | + except Exception as e: |
| 133 | + info["user"] = str(e) # Fallback for environments where getlogin() may fail |
| 134 | + return info |
| 135 | + |
| 136 | + |
| 137 | +if __name__ == "__main__": |
| 138 | + print("---------Attention: Please install tidy3d first.----------\n") |
| 139 | + print("---------web.test information begin----------") |
| 140 | + response = requests.get(Env.current.web_api_endpoint) |
| 141 | + print(f"call endpoint response:{response.text}") |
| 142 | + print("---------web.test information end----------\n") |
| 143 | + |
| 144 | + print("---------web.test information begin----------") |
| 145 | + web.test() |
| 146 | + print("---------web.test information end----------\n") |
| 147 | + |
| 148 | + print("---------sdk information begin----------") |
| 149 | + version = web.__version__ |
| 150 | + ssl_version = Env.current.ssl_version |
| 151 | + ssl_verify = Env.current.ssl_verify |
| 152 | + boto_version = get_boto_version() |
| 153 | + urllib_version = get_urllib_version() |
| 154 | + print( |
| 155 | + f"Tidy3d version: {version}, ssl_version: {ssl_version}, ssl_verify: {ssl_verify}, boto_version:{boto_version}, urllib_version:{urllib_version}" |
| 156 | + ) |
| 157 | + print("---------sdk information end----------\n") |
| 158 | + |
| 159 | + print("---------ssl information begin----------") |
| 160 | + get_ssl_version() |
| 161 | + list_ssl_info() |
| 162 | + print("---------ssl information end----------\n") |
| 163 | + |
| 164 | + print("---------os information begin----------") |
| 165 | + os_info = get_basic_os_info() |
| 166 | + for key, value in os_info.items(): |
| 167 | + print(f"{key}: {value}") |
| 168 | + print("---------os information end----------\n") |
| 169 | + |
| 170 | + print("---------get s3 public file information end----------") |
| 171 | + file_content = get_file_content(s3_small_file_url) |
| 172 | + print(f"get test.text file content: {file_content}") |
| 173 | + print(f"start to download {s3_small_file_url} with request...") |
| 174 | + download_file(s3_small_file_url) |
| 175 | + print(f"start to download {s3_small_file_url} with boto3...") |
| 176 | + download_s3_file_with_boto3("test.txt") |
| 177 | + print(f"start to download {s3_big_file_url} with request...") |
| 178 | + download_file(s3_big_file_url) |
| 179 | + print(f"start to download {s3_big_file_url} with boto3...") |
| 180 | + download_s3_file_with_boto3("50M.dat") |
| 181 | + print("---------get s3 public information end----------\n") |
| 182 | + |
| 183 | + print("---------time information begin----------") |
| 184 | + network_time = get_network_time() |
| 185 | + local_time = datetime.utcnow() |
| 186 | + print(f"local_time: {local_time}, network_time: {network_time}") |
| 187 | + print("---------time information end----------\n") |
| 188 | + |
| 189 | + print("---------network proxy information begin----------") |
| 190 | + proxy = detect_proxy_with_requests() |
| 191 | + print(f"proxy info: {proxy}") |
| 192 | + print("---------network proxy information end----------\n") |
| 193 | + |
| 194 | + print("---------download robots information begin----------") |
| 195 | + print(f"start download {flexcompute_robots_url}") |
| 196 | + download_file(flexcompute_robots_url) |
| 197 | + print(f"start download {simcloud_robots_url}") |
| 198 | + download_file(simcloud_robots_url) |
| 199 | + print("---------download robots information end----------\n") |
0 commit comments