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

Unified Diff: git_cache.py

Issue 251413002: Python fallback for git cache bootstrap (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Nit fix Created 6 years, 8 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: git_cache.py
diff --git a/git_cache.py b/git_cache.py
index 5c1f85a46eeaa454d280dfe89c1550f012894683..52e42c59274781f580491428b67afa4d6bf66280 100755
--- a/git_cache.py
+++ b/git_cache.py
@@ -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)
« 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