From 014d0609899dba70a1af0b32de377ca08c54aded Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sun, 11 Sep 2011 12:57:15 -0700 Subject: Honor http_proxy variable globally If the http_proxy environment variable was set, honor it during the entire repo session for any Python created HTTP connections. Change-Id: Ib4ae833cb2cdd47ab0126949f6b399d2c142887d Signed-off-by: Shawn O. Pearce --- main.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'main.py') diff --git a/main.py b/main.py index f068fd47..48edc1cc 100755 --- a/main.py +++ b/main.py @@ -26,6 +26,7 @@ import optparse import os import re import sys +import urllib2 from trace import SetTrace from git_config import init_ssh, close_ssh @@ -199,6 +200,12 @@ def _PruneOptions(argv, opt): continue i += 1 +def init_http(): + if 'http_proxy' in os.environ: + url = os.environ['http_proxy'] + proxy_support = urllib2.ProxyHandler({'http': url, 'https': url}) + urllib2.install_opener(urllib2.build_opener(proxy_support)) + def _Main(argv): opt = optparse.OptionParser(usage="repo wrapperinfo -- ...") opt.add_option("--repo-dir", dest="repodir", @@ -217,6 +224,7 @@ def _Main(argv): try: try: init_ssh() + init_http() repo._Run(argv) finally: close_ssh() -- cgit v1.2.3-54-g00ecf