You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
882 B
31 lines
882 B
# Copyright (c) 2022 Nordic Semiconductor ASA |
|
# |
|
# SPDX-License-Identifier: Apache-2.0 |
|
|
|
import os |
|
import requests |
|
import sys |
|
|
|
from west import log |
|
|
|
from fetchers.core import ZephyrBlobFetcher |
|
|
|
class HTTPFetcher(ZephyrBlobFetcher): |
|
|
|
@classmethod |
|
def schemes(cls): |
|
return ['http', 'https'] |
|
|
|
def fetch(self, url, path): |
|
log.dbg(f'HTTPFetcher fetching {url} to {path}') |
|
try: |
|
resp = requests.get(url) |
|
resp.raise_for_status() # Raises an HTTPError for bad status codes (4xx or 5xx) |
|
except requests.exceptions.HTTPError as e: |
|
log.err(f'HTTP error occurred: {e}') |
|
sys.exit(os.EX_NOHOST) |
|
except requests.exceptions.RequestException as e: |
|
log.err(f'An error occurred: {e}') |
|
sys.exit(os.EX_DATAERR) |
|
with open(path, "wb") as f: |
|
f.write(resp.content)
|
|
|