diff options
author | Alexandru DAMIAN <alexandru.damian@intel.com> | 2014-11-21 13:58:51 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2014-11-28 14:02:57 +0000 |
commit | 49ac18dd0fedbcb63e9b18d1b0df62431ed37eb0 (patch) | |
tree | cc753ee05a35c1a806e4ac9d626f014160b1638a | |
parent | 21924451c10e058473c50c697c23d7149297856a (diff) | |
download | poky-49ac18dd0fedbcb63e9b18d1b0df62431ed37eb0.tar.gz |
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>
-rw-r--r-- | bitbake/lib/toaster/orm/models.py | 45 |
1 files changed, 32 insertions, 13 deletions
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): | |||
599 | assert self.apiurl is not None | 599 | assert self.apiurl is not None |
600 | from django.db import IntegrityError | 600 | from django.db import IntegrityError |
601 | 601 | ||
602 | import httplib, urlparse, json | ||
603 | import os | ||
604 | proxy_settings = os.environ.get("http_proxy", None) | ||
605 | |||
602 | def _get_json_response(apiurl = self.apiurl): | 606 | def _get_json_response(apiurl = self.apiurl): |
603 | import httplib, urlparse, json | 607 | conn = None |
604 | parsedurl = urlparse.urlparse(apiurl) | 608 | _parsedurl = urlparse.urlparse(apiurl) |
605 | try: | 609 | path = _parsedurl.path |
606 | (host, port) = parsedurl.netloc.split(":") | 610 | query = _parsedurl.query |
607 | except ValueError: | 611 | def parse_url(url): |
608 | host = parsedurl.netloc | 612 | parsedurl = urlparse.urlparse(url) |
609 | port = None | 613 | try: |
614 | (host, port) = parsedurl.netloc.split(":") | ||
615 | except ValueError: | ||
616 | host = parsedurl.netloc | ||
617 | port = None | ||
618 | |||
619 | if port is None: | ||
620 | port = 80 | ||
621 | else: | ||
622 | port = int(port) | ||
623 | return (host, port) | ||
610 | 624 | ||
611 | if port is None: | 625 | if proxy_settings is None: |
612 | port = 80 | 626 | host, port = parse_url(apiurl) |
627 | conn = httplib.HTTPConnection(host, port) | ||
628 | conn.request("GET", path + "?" + query) | ||
613 | else: | 629 | else: |
614 | port = int(port) | 630 | host, port = parse_url(proxy_settings) |
615 | conn = httplib.HTTPConnection(host, port) | 631 | conn = httplib.HTTPConnection(host, port) |
616 | conn.request("GET", parsedurl.path + "?" + parsedurl.query) | 632 | conn.request("GET", apiurl) |
633 | |||
617 | r = conn.getresponse() | 634 | r = conn.getresponse() |
618 | if r.status != 200: | 635 | if r.status != 200: |
619 | raise Exception("Failed to read " + parsedurl.path + ": %d %s" % (r.status, r.reason)) | 636 | raise Exception("Failed to read " + path + ": %d %s" % (r.status, r.reason)) |
620 | return json.loads(r.read()) | 637 | return json.loads(r.read()) |
621 | 638 | ||
622 | # verify we can get the basic api | 639 | # verify we can get the basic api |
@@ -624,6 +641,8 @@ class LayerIndexLayerSource(LayerSource): | |||
624 | apilinks = _get_json_response() | 641 | apilinks = _get_json_response() |
625 | except Exception as e: | 642 | except Exception as e: |
626 | import traceback | 643 | import traceback |
644 | if proxy_settings is not None: | ||
645 | print "EE: Using proxy ", proxy_settings | ||
627 | print "EE: could not connect to %s, skipping update: %s\n%s" % (self.apiurl, e, traceback.format_exc(e)) | 646 | print "EE: could not connect to %s, skipping update: %s\n%s" % (self.apiurl, e, traceback.format_exc(e)) |
628 | return | 647 | return |
629 | 648 | ||