aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2018-11-05 14:53:07 -0800
committermichael-west <michael.west@ettus.com>2018-12-17 13:38:01 -0800
commit1d72679e30b112baa87a0d16f9603e3242f8b589 (patch)
treed17f28d752c694c26069c59fdf48c264bd096317
parentmpmd: Improve error message for compat number mismatches (diff)
downloaduhd-1d72679e30b112baa87a0d16f9603e3242f8b589.tar.xz
uhd-1d72679e30b112baa87a0d16f9603e3242f8b589.zip
utils: uhd_images_downloader: Add --http-proxy option
This lets the user specify a HTTP proxy. The environment variable HTTP_PROXY is still usable, but --http-proxy will override it. Example: $ uhd_images_downloader \ --http-proxy http://user:pass@10.20.30.40:3128 \ -t x310 Here, the tool will download all the images matching 'x310' using a proxy at 10.20.30.40.
-rw-r--r--host/utils/uhd_images_downloader.py.in13
1 files changed, 11 insertions, 2 deletions
diff --git a/host/utils/uhd_images_downloader.py.in b/host/utils/uhd_images_downloader.py.in
index ef0bdd4ee..fc1d3f979 100644
--- a/host/utils/uhd_images_downloader.py.in
+++ b/host/utils/uhd_images_downloader.py.in
@@ -70,6 +70,7 @@ _LOG_LEVELS = {"TRACE": 1,
"ERROR": 5}
_LOG_LEVEL = _LOG_LEVELS["INFO"]
_YES = False
+_PROXIES = {}
def log(level, message):
@@ -106,6 +107,11 @@ def parse_args():
help="Set threshold for download limits. Any download "
"larger than this will require approval, either "
"interactively, or by providing --yes.")
+ parser.add_argument("--http-proxy", type=str,
+ help="Specify HTTP proxy in the format "
+ "http://user:pass@1.2.3.4:port\n"
+ "If this this option is not given, the environment "
+ "variable HTTP_PROXY can also be used to specify a proxy.")
parser.add_argument("-b", "--base-url", type=str, default=_DEFAULT_BASE_URL,
help="Set base URL for images download location")
parser.add_argument("-k", "--keep", action="store_true", default=False,
@@ -130,6 +136,9 @@ def parse_args():
if args.yes:
global _YES
_YES = True
+ if args.http_proxy:
+ global _PROXIES
+ _PROXIES['http'] = args.http_proxy
# Set the verbosity
global _LOG_LEVEL
log("TRACE", "Default log level: {}".format(_LOG_LEVEL))
@@ -322,12 +331,12 @@ def download(
download_limit = download_limit or _DEFAULT_DOWNLOAD_LIMIT
log("TRACE", "Downloading {} to {}".format(images_url, filename))
try:
- resp = requests.get(images_url, stream=True,
+ resp = requests.get(images_url, stream=True, proxies=_PROXIES,
headers={'User-Agent': 'UHD Images Downloader'})
except TypeError:
# requests library versions pre-4c3b9df6091b65d8c72763222bd5fdefb7231149
# (Dec.'12) workaround
- resp = requests.get(images_url, prefetch=False,
+ resp = requests.get(images_url, prefetch=False, proxies=_PROXIES,
headers={'User-Agent': 'UHD Images Downloader'})
if resp.status_code != 200:
raise RuntimeError("URL does not exist: {}".format(images_url))