From 49ac18dd0fedbcb63e9b18d1b0df62431ed37eb0 Mon Sep 17 00:00:00 2001 From: Alexandru DAMIAN Date: Fri, 21 Nov 2014 13:58:51 +0000 Subject: bitbake: toaster: use http proxies to fetch data Under some network configurations http proxies are used for Internet access. This patch makes Toaster obey the http_proxy environment variable when fetching information from layer indexes. (Bitbake rev: 9f3cf52b3a96768e5b9764dde02833b078fe61e4) Signed-off-by: Alexandru DAMIAN Signed-off-by: Richard Purdie --- bitbake/lib/toaster/orm/models.py | 45 ++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 13 deletions(-) (limited to 'bitbake') diff --git a/bitbake/lib/toaster/orm/models.py b/bitbake/lib/toaster/orm/models.py index c90e047caf..99cc695012 100644 --- a/bitbake/lib/toaster/orm/models.py +++ b/bitbake/lib/toaster/orm/models.py @@ -599,24 +599,41 @@ class LayerIndexLayerSource(LayerSource): assert self.apiurl is not None from django.db import IntegrityError + import httplib, urlparse, json + import os + proxy_settings = os.environ.get("http_proxy", None) + def _get_json_response(apiurl = self.apiurl): - import httplib, urlparse, json - parsedurl = urlparse.urlparse(apiurl) - try: - (host, port) = parsedurl.netloc.split(":") - except ValueError: - host = parsedurl.netloc - port = None + conn = None + _parsedurl = urlparse.urlparse(apiurl) + path = _parsedurl.path + query = _parsedurl.query + def parse_url(url): + parsedurl = urlparse.urlparse(url) + try: + (host, port) = parsedurl.netloc.split(":") + except ValueError: + host = parsedurl.netloc + port = None + + if port is None: + port = 80 + else: + port = int(port) + return (host, port) - if port is None: - port = 80 + if proxy_settings is None: + host, port = parse_url(apiurl) + conn = httplib.HTTPConnection(host, port) + conn.request("GET", path + "?" + query) else: - port = int(port) - conn = httplib.HTTPConnection(host, port) - conn.request("GET", parsedurl.path + "?" + parsedurl.query) + host, port = parse_url(proxy_settings) + conn = httplib.HTTPConnection(host, port) + conn.request("GET", apiurl) + r = conn.getresponse() if r.status != 200: - raise Exception("Failed to read " + parsedurl.path + ": %d %s" % (r.status, r.reason)) + raise Exception("Failed to read " + path + ": %d %s" % (r.status, r.reason)) return json.loads(r.read()) # verify we can get the basic api @@ -624,6 +641,8 @@ class LayerIndexLayerSource(LayerSource): apilinks = _get_json_response() except Exception as e: import traceback + if proxy_settings is not None: + print "EE: Using proxy ", proxy_settings print "EE: could not connect to %s, skipping update: %s\n%s" % (self.apiurl, e, traceback.format_exc(e)) return -- cgit v1.2.3-54-g00ecf