diff options
Diffstat (limited to 'fetch.py')
| -rw-r--r-- | fetch.py | 10 |
1 files changed, 7 insertions, 3 deletions
| @@ -18,7 +18,7 @@ import subprocess | |||
| 18 | import sys | 18 | import sys |
| 19 | from urllib.parse import urlparse | 19 | from urllib.parse import urlparse |
| 20 | 20 | ||
| 21 | def fetch_file(url): | 21 | def fetch_file(url, verbose=False): |
| 22 | """Fetch a file from the specified source using the appropriate protocol. | 22 | """Fetch a file from the specified source using the appropriate protocol. |
| 23 | 23 | ||
| 24 | Returns: | 24 | Returns: |
| @@ -29,10 +29,14 @@ def fetch_file(url): | |||
| 29 | cmd = ['gsutil', 'cat', url] | 29 | cmd = ['gsutil', 'cat', url] |
| 30 | try: | 30 | try: |
| 31 | result = subprocess.run( | 31 | result = subprocess.run( |
| 32 | cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | 32 | cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, |
| 33 | check=True) | ||
| 34 | if result.stderr and verbose: | ||
| 35 | print('warning: non-fatal error running "gsutil": %s' % result.stderr, | ||
| 36 | file=sys.stderr) | ||
| 33 | return result.stdout | 37 | return result.stdout |
| 34 | except subprocess.CalledProcessError as e: | 38 | except subprocess.CalledProcessError as e: |
| 35 | print('fatal: error running "gsutil": %s' % e.output, | 39 | print('fatal: error running "gsutil": %s' % e.stderr, |
| 36 | file=sys.stderr) | 40 | file=sys.stderr) |
| 37 | sys.exit(1) | 41 | sys.exit(1) |
| 38 | if scheme == 'file': | 42 | if scheme == 'file': |
