summaryrefslogtreecommitdiffstats
path: root/fetch.py
diff options
context:
space:
mode:
Diffstat (limited to 'fetch.py')
-rw-r--r--fetch.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/fetch.py b/fetch.py
index 31f8152f..cf8d1d7d 100644
--- a/fetch.py
+++ b/fetch.py
@@ -18,6 +18,11 @@ import subprocess
18import sys 18import sys
19from urllib.parse import urlparse 19from urllib.parse import urlparse
20from urllib.request import urlopen 20from urllib.request import urlopen
21from error import RepoExitError
22
23
24class FetchFileError(RepoExitError):
25 """Exit error when fetch_file fails."""
21 26
22 27
23def fetch_file(url, verbose=False): 28def fetch_file(url, verbose=False):
@@ -29,6 +34,7 @@ def fetch_file(url, verbose=False):
29 scheme = urlparse(url).scheme 34 scheme = urlparse(url).scheme
30 if scheme == "gs": 35 if scheme == "gs":
31 cmd = ["gsutil", "cat", url] 36 cmd = ["gsutil", "cat", url]
37 errors = []
32 try: 38 try:
33 result = subprocess.run( 39 result = subprocess.run(
34 cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True 40 cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True
@@ -41,9 +47,10 @@ def fetch_file(url, verbose=False):
41 ) 47 )
42 return result.stdout 48 return result.stdout
43 except subprocess.CalledProcessError as e: 49 except subprocess.CalledProcessError as e:
50 errors.append(e)
44 print( 51 print(
45 'fatal: error running "gsutil": %s' % e.stderr, file=sys.stderr 52 'fatal: error running "gsutil": %s' % e.stderr, file=sys.stderr
46 ) 53 )
47 sys.exit(1) 54 raise FetchFileError(aggregate_errors=errors)
48 with urlopen(url) as f: 55 with urlopen(url) as f:
49 return f.read() 56 return f.read()