Commit 776a2c3f authored by hinoka@google.com's avatar hinoka@google.com

Python fallback for git cache bootstrap

This is because the version of unzip on osx doesn't support zip64, so it can't
unzip large repositories like blink.

BUG=261741

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@266151 0039d316-1c4b-4281-b951-d872f2087c98
parent 2f64f78a
......@@ -15,6 +15,7 @@ import time
import subprocess
import sys
import urlparse
import zipfile
from download_from_google_storage import Gsutil
import gclient_utils
......@@ -222,26 +223,16 @@ class Mirror(object):
self.RunGit(['config', '--add', 'remote.origin.fetch', refspec], cwd=cwd)
def bootstrap_repo(self, directory):
"""Bootstrap the repo from Google Stroage if possible.
"""Bootstrap the repo from Google Stroage if possible."""
Requires 7z on Windows and Unzip on Linux/Mac.
"""
if sys.platform.startswith('win'):
if not self.FindExecutable('7z'):
self.print('''
Cannot find 7z in the path. If you want git cache to be able to bootstrap from
Google Storage, please install 7z from:
http://www.7-zip.org/download.html
''')
return False
else:
if not self.FindExecutable('unzip'):
self.print('''
Cannot find unzip in the path. If you want git cache to be able to bootstrap
from Google Storage, please ensure unzip is present on your system.
''')
return False
python_fallback = False
if sys.platform.startswith('win') and not self.FindExecutable('7z'):
python_fallback = True
elif sys.platform.startswith('darwin'):
# The OSX version of unzip doesn't support zip64.
python_fallback = True
elif not self.FindExecutable('unzip'):
python_fallback = True
gs_folder = 'gs://%s/%s' % (self.bootstrap_bucket, self.basedir)
gsutil = Gsutil(
......@@ -264,12 +255,23 @@ from Google Storage, please ensure unzip is present on your system.
return False
filename = os.path.join(tempdir, latest_checkout.split('/')[-1])
# Unpack the file with 7z on Windows, or unzip everywhere else.
if sys.platform.startswith('win'):
cmd = ['7z', 'x', '-o%s' % directory, '-tzip', filename]
# Unpack the file with 7z on Windows, unzip on linux, or fallback.
if not python_fallback:
if sys.platform.startswith('win'):
cmd = ['7z', 'x', '-o%s' % directory, '-tzip', filename]
else:
cmd = ['unzip', filename, '-d', directory]
retcode = subprocess.call(cmd)
else:
cmd = ['unzip', filename, '-d', directory]
retcode = subprocess.call(cmd)
try:
with zipfile.ZipFile(filename, 'r') as f:
f.printdir()
f.extractall(directory)
except Exception as e:
self.print('Encountered error: %s' % str(e), file=sys.stderr)
retcode = 1
else:
retcode = 0
finally:
# Clean up the downloaded zipfile.
gclient_utils.rmtree(tempdir)
......
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