Debian Codegraph @

infra/bots/recipe_modules/gold_upload/resources/get_uninteresting_hashes.py

raw
1 # Copyright 2024 Google LLC
2 #
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 import contextlib
7 import math
8 import socket
9 import sys
10 import time
11
12 from urllib.request import urlopen
13
14 HASHES_URL = sys.argv[1]
15 RETRIES = 5
16 TIMEOUT = 60
17 WAIT_BASE = 15
18
19 socket.setdefaulttimeout(TIMEOUT)
20 for retry in range(RETRIES):
21 try:
22 with contextlib.closing(
23 urlopen(HASHES_URL, timeout=TIMEOUT)) as w:
24 hashes = w.read().decode('utf-8')
25 with open(sys.argv[2], 'w') as f:
26 f.write(hashes)
27 break
28 except Exception as e:
29 print('Failed to get uninteresting hashes from %s:' % HASHES_URL)
30 print(e)
31 if retry == RETRIES:
32 raise
33 waittime = WAIT_BASE * math.pow(2, retry)
34 print('Retry in %d seconds.' % waittime)
35 time.sleep(waittime)