|
82 | 82 |
|
83 | 83 |
|
84 | 84 | _CMD_TIMEOUT = 900 |
| 85 | +_MAX_ATTEMPTS = 3 |
85 | 86 |
|
86 | 87 | _DEFALUT = "Default" |
87 | 88 | _ANDROID = "Android" |
@@ -172,7 +173,6 @@ def main(argv): |
172 | 173 | raise app.UsageError("Too many command-line arguments.") |
173 | 174 |
|
174 | 175 | if FLAGS.install: |
175 | | - uninstall_unity(FLAGS.version) |
176 | 176 | install_unity(FLAGS.version, FLAGS.platforms) |
177 | 177 |
|
178 | 178 | if FLAGS.activate_license: |
@@ -209,9 +209,24 @@ def install_unity(unity_version, platforms): |
209 | 209 | u3d = find_u3d() |
210 | 210 | run([u3d, "available", "-u", unity_version], check=False) |
211 | 211 | run([u3d, "available", "-u", unity_full_version, "-p"], check=False) |
212 | | - run([u3d, "install", "--trace", |
| 212 | + attempt_num = 1 |
| 213 | + while attempt_num <= _MAX_ATTEMPTS: |
| 214 | + uninstall_unity(unity_version) |
| 215 | + args = [u3d, "install", "--trace", |
213 | 216 | "--verbose", unity_full_version, |
214 | | - "-p", package_csv]) |
| 217 | + "-p", package_csv] |
| 218 | + logging.info("run_with_retry: %s (attempt %s of %s)", args, attempt_num, _MAX_ATTEMPTS) |
| 219 | + try: |
| 220 | + run(args) |
| 221 | + except subprocess.SubprocessError: |
| 222 | + logging.exception("run_with_retry: %s (attempt %s of %s) FAILED", args, attempt_num, _MAX_ATTEMPTS) |
| 223 | + # If retries have been exhausted, just raise the exception |
| 224 | + if attempt_num >= _MAX_ATTEMPTS: |
| 225 | + raise |
| 226 | + else: |
| 227 | + break |
| 228 | + attempt_num += 1 |
| 229 | + |
215 | 230 | logging.info("Finished installing Unity.") |
216 | 231 |
|
217 | 232 | unity_path = get_unity_path(unity_version) |
@@ -324,8 +339,8 @@ def run(args, check=True, timeout=_CMD_TIMEOUT): |
324 | 339 | """Runs args in a subprocess, throwing an error on non-zero return code.""" |
325 | 340 | logging.info("run cmd: %s", " ".join(args)) |
326 | 341 | result = subprocess.run(args=args, check=check, timeout=timeout, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) |
327 | | - logging.info(result.stdout) |
328 | | - logging.info(result.stderr) |
| 342 | + logging.info("cmd result.stdout: %s", result.stdout) |
| 343 | + logging.info("cmd result.stderr: %s", result.stderr) |
329 | 344 |
|
330 | 345 |
|
331 | 346 | if __name__ == "__main__": |
|
0 commit comments