diff options
Diffstat (limited to 'fetch.py')
| -rw-r--r-- | fetch.py | 9 |
1 files changed, 8 insertions, 1 deletions
| @@ -18,6 +18,11 @@ import subprocess | |||
| 18 | import sys | 18 | import sys |
| 19 | from urllib.parse import urlparse | 19 | from urllib.parse import urlparse |
| 20 | from urllib.request import urlopen | 20 | from urllib.request import urlopen |
| 21 | from error import RepoExitError | ||
| 22 | |||
| 23 | |||
| 24 | class FetchFileError(RepoExitError): | ||
| 25 | """Exit error when fetch_file fails.""" | ||
| 21 | 26 | ||
| 22 | 27 | ||
| 23 | def fetch_file(url, verbose=False): | 28 | def 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() |
