mirror of
https://git.yoctoproject.org/poky
synced 2026-09-15 06:49:33 +02:00
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 <alexandru.damian@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
committed by
Richard Purdie
parent
21924451c1
commit
49ac18dd0f
@@ -599,24 +599,41 @@ class LayerIndexLayerSource(LayerSource):
|
|||||||
assert self.apiurl is not None
|
assert self.apiurl is not None
|
||||||
from django.db import IntegrityError
|
from django.db import IntegrityError
|
||||||
|
|
||||||
def _get_json_response(apiurl = self.apiurl):
|
import httplib, urlparse, json
|
||||||
import httplib, urlparse, json
|
import os
|
||||||
parsedurl = urlparse.urlparse(apiurl)
|
proxy_settings = os.environ.get("http_proxy", None)
|
||||||
try:
|
|
||||||
(host, port) = parsedurl.netloc.split(":")
|
|
||||||
except ValueError:
|
|
||||||
host = parsedurl.netloc
|
|
||||||
port = None
|
|
||||||
|
|
||||||
if port is None:
|
def _get_json_response(apiurl = self.apiurl):
|
||||||
port = 80
|
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 proxy_settings is None:
|
||||||
|
host, port = parse_url(apiurl)
|
||||||
|
conn = httplib.HTTPConnection(host, port)
|
||||||
|
conn.request("GET", path + "?" + query)
|
||||||
else:
|
else:
|
||||||
port = int(port)
|
host, port = parse_url(proxy_settings)
|
||||||
conn = httplib.HTTPConnection(host, port)
|
conn = httplib.HTTPConnection(host, port)
|
||||||
conn.request("GET", parsedurl.path + "?" + parsedurl.query)
|
conn.request("GET", apiurl)
|
||||||
|
|
||||||
r = conn.getresponse()
|
r = conn.getresponse()
|
||||||
if r.status != 200:
|
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())
|
return json.loads(r.read())
|
||||||
|
|
||||||
# verify we can get the basic api
|
# verify we can get the basic api
|
||||||
@@ -624,6 +641,8 @@ class LayerIndexLayerSource(LayerSource):
|
|||||||
apilinks = _get_json_response()
|
apilinks = _get_json_response()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
import traceback
|
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))
|
print "EE: could not connect to %s, skipping update: %s\n%s" % (self.apiurl, e, traceback.format_exc(e))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user