Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4213)

Unified Diff: gsutil.py

Issue 841823002: gsutil: Pass proxy information via Boto options. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gsutil.py
diff --git a/gsutil.py b/gsutil.py
index 6578d7844171202eb787bf1414c4a371e15a75a0..bdb9d53d7b3f939c8a943533dabba1025b2e6863 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,32 @@ def ensure_gsutil(version, target):
return gsutil_bin
+def get_boto_proxy_options_from_environment():
Ryan Tseng 2015/01/07 22:21:58 for completeness sake (since I've seen all these p
+ """Converts the contents of the 'http_proxy' environment variable into the
Ryan Tseng 2015/01/07 22:21:58 """One line More lines ... """ So rewrite this a
+ corresponding Boto options that gsutil accepts."""
+ if 'http_proxy' not in os.environ:
+ return []
+ proxy_url = urlparse.urlsplit(os.environ['http_proxy'])
+ if proxy_url.hostname is None or proxy_url.port is None:
+ raise EnvironmentError(
+ 'The "http_proxy" environment is set, but has an invalid format. Its '
Ryan Tseng 2015/01/07 22:21:58 2 indents
+ 'format must be "http://[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)
else:
gsutil_bin = fallback
- cmd = [sys.executable, gsutil_bin] + args
+ proxy_options = get_boto_proxy_options_from_environment()
+ cmd = [sys.executable, gsutil_bin] + proxy_options + args
try:
call(cmd)
except SubprocessError as e:
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698