Chromium Code Reviews| Index: git_cache.py |
| diff --git a/git_cache.py b/git_cache.py |
| index 5c1f85a46eeaa454d280dfe89c1550f012894683..50e9388678f9e5e5720a5e5e80ec8572b208f795 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,17 @@ 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. |
| - """ |
| + python_fallback = False |
| if sys.platform.startswith('win'): |
|
agable
2014/04/25 05:41:39
sys.platform.... and not self.FindExec...
Ryan Tseng
2014/04/25 08:49:47
Done.
|
| 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 = 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 +256,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 python_fallback: |
|
agable
2014/04/25 05:41:39
Flop these. Start with "if not python_fallback:"..
Ryan Tseng
2014/04/25 08:49:47
Done.
|
| + try: |
| + with zipfile.ZipFile(filename, 'r') as f: |
| + f.printdir() |
|
agable
2014/04/25 05:41:39
Is this necessary or is it debugging?
Ryan Tseng
2014/04/25 08:49:47
Its not, but its there to match the behavior of 7z
|
| + f.extractall(directory) |
| + except Exception as e: |
| + self.print('Encountered error: %s' % str(e), file=sys.stderr) |
| + retcode = 1 |
| + else: |
| + retcode = 0 |
| else: |
| - cmd = ['unzip', filename, '-d', directory] |
| - retcode = subprocess.call(cmd) |
| + if sys.platform.startswith('win'): |
| + cmd = ['7z', 'x', '-o%s' % directory, '-tzip', filename] |
| + else: |
| + cmd = ['unzip', filename, '-d', directory] |
| + retcode = subprocess.call(cmd) |
| finally: |
| # Clean up the downloaded zipfile. |
| gclient_utils.rmtree(tempdir) |