aboutsummaryrefslogtreecommitdiffstats
path: root/host/utils
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2018-11-05 14:53:07 -0800
committerBrent Stapleton <bstapleton@g.hmc.edu>2018-11-16 14:04:13 -0800
commitc3680008cf46d3693bdd43ff2621492254c28849 (patch)
tree890c2f409d7c17b66f1b2eb32601ef870b158ce3 /host/utils
parent1be93abaef6b9c64fb6bd04ab639166fec5af550 (diff)
downloaduhd-c3680008cf46d3693bdd43ff2621492254c28849.tar.gz
uhd-c3680008cf46d3693bdd43ff2621492254c28849.tar.bz2
uhd-c3680008cf46d3693bdd43ff2621492254c28849.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.
Diffstat (limited to 'host/utils')
-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))