Chromium Code Reviews| Index: gsutil.py |
| diff --git a/gsutil.py b/gsutil.py |
| index 6578d7844171202eb787bf1414c4a371e15a75a0..8b338df680c7ae3ddb8bd1d05459b7f501eeea1c 100755 |
| --- a/gsutil.py |
| +++ b/gsutil.py |
| @@ -15,6 +15,7 @@ import shutil |
| import subprocess |
| import sys |
| import urllib2 |
| +import urlparse |
| import zipfile |
| @@ -121,12 +122,42 @@ def ensure_gsutil(version, target): |
| return gsutil_bin |
| +def get_boto_proxy_options_from_environment(): |
| + """Derive proxy options for gsutil from the environment. |
| + |
| + Parses the contents of the 'http_proxy' (and variations) environment variable |
| + and converts it to the corresponding Boto options that gsutil accepts. |
| + """ |
| + proxy_variable = None |
| + for env_var in ('http_proxy', 'HTTP_PROXY', 'https_proxy', 'HTTPS_PROXY'): |
|
agable
2015/01/08 20:39:01
Shouldn't we prioritize an https proxy over an htt
Raphael Kubo da Costa (rakuco)
2015/01/08 22:29:02
I don't have a strong opinion here, as the whole t
|
| + if env_var in os.environ: |
| + proxy_variable = env_var |
| + break |
| + if proxy_variable is None: |
| + return [] |
| + |
| + proxy_url = urlparse.urlsplit(os.environ[proxy_variable]) |
| + if proxy_url.hostname is None or proxy_url.port is None: |
| + raise EnvironmentError( |
| + 'The "%s" environment is set, but has an invalid format. Its ' |
| + 'format must be "http://[user[:password]]host:port".' % proxy_variable) |
|
agable
2015/01/08 20:39:01
[user[:password]@]host:port
|
| + boto_options = ['-o', 'Boto:proxy=%s' % proxy_url.hostname, |
| + '-o', 'Boto:proxy_port=%d' % proxy_url.port] |
| + if proxy_url.username: |
| + boto_options.extend(['-o', 'Boto:proxy_user=%s' % proxy_url.username]) |
| + if proxy_url.password: |
| + boto_options.extend(['-o', 'Boto:proxy_pass=%s' % proxy_url.password]) |
| + return boto_options |
| + |
| + |
| def run_gsutil(force_version, fallback, target, args): |
| if force_version: |
| gsutil_bin = ensure_gsutil(force_version, target) |
| + proxy_options = get_boto_proxy_options_from_environment() |
| else: |
| gsutil_bin = fallback |
| - cmd = [sys.executable, gsutil_bin] + args |
| + proxy_options = [] # Not available in the fallback gsutil. |
| + cmd = [sys.executable, gsutil_bin] + proxy_options + args |
| try: |
| call(cmd) |
| except SubprocessError as e: |