Commit 199bc5f9 authored by hinoka@chromium.org's avatar hinoka@chromium.org

Use gsutil.py for download_from_google_storage instead of the builtin one

This pins gsutil to a vanilla 4.7 instead of the weird custom 3.4 we have in depot_tools

BUG=
R=pgervais@chromium.org

Review URL: https://codereview.chromium.org/797663003

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@293413 0039d316-1c4b-4281-b951-d872f2087c98
parent 4fa73b8c
...@@ -20,8 +20,7 @@ import subprocess2 ...@@ -20,8 +20,7 @@ import subprocess2
GSUTIL_DEFAULT_PATH = os.path.join( GSUTIL_DEFAULT_PATH = os.path.join(
os.path.dirname(os.path.abspath(__file__)), os.path.dirname(os.path.abspath(__file__)), 'gsutil.py')
'third_party', 'gsutil', 'gsutil')
# Maps sys.platform to what we actually want to call them. # Maps sys.platform to what we actually want to call them.
PLATFORM_MAPPING = { PLATFORM_MAPPING = {
'cygwin': 'win', 'cygwin': 'win',
...@@ -55,13 +54,13 @@ def GetNormalizedPlatform(): ...@@ -55,13 +54,13 @@ def GetNormalizedPlatform():
class Gsutil(object): class Gsutil(object):
"""Call gsutil with some predefined settings. This is a convenience object, """Call gsutil with some predefined settings. This is a convenience object,
and is also immutable.""" and is also immutable."""
def __init__(self, path, boto_path, timeout=None, bypass_prodaccess=False): def __init__(self, path, boto_path, timeout=None, version='4.7'):
if not os.path.exists(path): if not os.path.exists(path):
raise FileNotFoundError('GSUtil not found in %s' % path) raise FileNotFoundError('GSUtil not found in %s' % path)
self.path = path self.path = path
self.timeout = timeout self.timeout = timeout
self.boto_path = boto_path self.boto_path = boto_path
self.bypass_prodaccess = bypass_prodaccess self.version = version
def get_sub_env(self): def get_sub_env(self):
env = os.environ.copy() env = os.environ.copy()
...@@ -80,16 +79,12 @@ class Gsutil(object): ...@@ -80,16 +79,12 @@ class Gsutil(object):
return env return env
def call(self, *args): def call(self, *args):
cmd = [sys.executable, self.path] cmd = [sys.executable, self.path, '--force-version', self.version]
if self.bypass_prodaccess:
cmd.append('--bypass_prodaccess')
cmd.extend(args) cmd.extend(args)
return subprocess2.call(cmd, env=self.get_sub_env(), timeout=self.timeout) return subprocess2.call(cmd, env=self.get_sub_env(), timeout=self.timeout)
def check_call(self, *args): def check_call(self, *args):
cmd = [sys.executable, self.path] cmd = [sys.executable, self.path, '--force-version', self.version]
if self.bypass_prodaccess:
cmd.append('--bypass_prodaccess')
cmd.extend(args) cmd.extend(args)
((out, err), code) = subprocess2.communicate( ((out, err), code) = subprocess2.communicate(
cmd, cmd,
...@@ -237,7 +232,7 @@ def _downloader_worker_thread(thread_num, q, force, base_url, ...@@ -237,7 +232,7 @@ def _downloader_worker_thread(thread_num, q, force, base_url,
if os.path.exists(output_filename): if os.path.exists(output_filename):
out_q.put('%d> Warning: deleting %s failed.' % ( out_q.put('%d> Warning: deleting %s failed.' % (
thread_num, output_filename)) thread_num, output_filename))
code, _, err = gsutil.check_call('cp', '-q', file_url, output_filename) code, _, err = gsutil.check_call('cp', file_url, output_filename)
if code != 0: if code != 0:
out_q.put('%d> %s' % (thread_num, err)) out_q.put('%d> %s' % (thread_num, err))
ret_codes.put((code, err)) ret_codes.put((code, err))
...@@ -398,8 +393,7 @@ def main(args): ...@@ -398,8 +393,7 @@ def main(args):
# Make sure gsutil exists where we expect it to. # Make sure gsutil exists where we expect it to.
if os.path.exists(GSUTIL_DEFAULT_PATH): if os.path.exists(GSUTIL_DEFAULT_PATH):
gsutil = Gsutil(GSUTIL_DEFAULT_PATH, gsutil = Gsutil(GSUTIL_DEFAULT_PATH,
boto_path=options.boto, boto_path=options.boto)
bypass_prodaccess=options.no_auth)
else: else:
parser.error('gsutil not found in %s, bad depot_tools checkout?' % parser.error('gsutil not found in %s, bad depot_tools checkout?' %
GSUTIL_DEFAULT_PATH) GSUTIL_DEFAULT_PATH)
......
...@@ -276,7 +276,7 @@ class Mirror(object): ...@@ -276,7 +276,7 @@ class Mirror(object):
python_fallback = True python_fallback = True
gs_folder = 'gs://%s/%s' % (self.bootstrap_bucket, self.basedir) gs_folder = 'gs://%s/%s' % (self.bootstrap_bucket, self.basedir)
gsutil = Gsutil(self.gsutil_exe, boto_path=None, bypass_prodaccess=True) gsutil = Gsutil(self.gsutil_exe, boto_path=None)
# Get the most recent version of the zipfile. # Get the most recent version of the zipfile.
_, ls_out, _ = gsutil.check_call('ls', gs_folder) _, ls_out, _ = gsutil.check_call('ls', gs_folder)
ls_out_sorted = sorted(ls_out.splitlines()) ls_out_sorted = sorted(ls_out.splitlines())
......
...@@ -19,10 +19,7 @@ from download_from_google_storage import check_bucket_permissions ...@@ -19,10 +19,7 @@ from download_from_google_storage import check_bucket_permissions
from download_from_google_storage import get_sha1 from download_from_google_storage import get_sha1
from download_from_google_storage import Gsutil from download_from_google_storage import Gsutil
from download_from_google_storage import printer_worker from download_from_google_storage import printer_worker
from download_from_google_storage import GSUTIL_DEFAULT_PATH
GSUTIL_DEFAULT_PATH = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
'third_party', 'gsutil', 'gsutil')
USAGE_STRING = """%prog [options] target [target2 ...]. USAGE_STRING = """%prog [options] target [target2 ...].
Target is the file intended to be uploaded to Google Storage. Target is the file intended to be uploaded to Google Storage.
...@@ -96,7 +93,7 @@ def _upload_worker( ...@@ -96,7 +93,7 @@ def _upload_worker(
continue continue
stdout_queue.put('%d> Uploading %s...' % ( stdout_queue.put('%d> Uploading %s...' % (
thread_num, filename)) thread_num, filename))
code, _, err = gsutil.check_call('cp', '-q', filename, file_url) code, _, err = gsutil.check_call('cp', filename, file_url)
if code != 0: if code != 0:
ret_codes.put( ret_codes.put(
(code, (code,
...@@ -234,8 +231,7 @@ def main(args): ...@@ -234,8 +231,7 @@ def main(args):
# Make sure we can find a working instance of gsutil. # Make sure we can find a working instance of gsutil.
if os.path.exists(GSUTIL_DEFAULT_PATH): if os.path.exists(GSUTIL_DEFAULT_PATH):
gsutil = Gsutil(GSUTIL_DEFAULT_PATH, boto_path=options.boto, gsutil = Gsutil(GSUTIL_DEFAULT_PATH, boto_path=options.boto)
bypass_prodaccess=True)
else: else:
gsutil = None gsutil = None
for path in os.environ["PATH"].split(os.pathsep): for path in os.environ["PATH"].split(os.pathsep):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment