OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/python |
| 2 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. |
| 5 |
| 6 """Downloads the appengine SDK from WebRTC storage and unpacks it. |
| 7 |
| 8 Requires that depot_tools is installed and in the PATH. This script expects |
| 9 to run with Chrome's base dir as the working directory, e.g. where the .gclient |
| 10 file is. This is what should happen if this script is invoked as a hook action. |
| 11 """ |
| 12 |
| 13 import hashlib |
| 14 import os |
| 15 import shutil |
| 16 import sys |
| 17 import subprocess |
| 18 import zipfile |
| 19 |
| 20 |
| 21 def _DownloadAppEngineZipFile(webrtc_deps_path): |
| 22 print 'Downloading files in %s...' % webrtc_deps_path |
| 23 |
| 24 extension = 'bat' if 'win32' in sys.platform else 'py' |
| 25 cmd = ['download_from_google_storage.%s' % extension, |
| 26 '--bucket=chromium-webrtc-resources', |
| 27 '--directory', webrtc_deps_path] |
| 28 subprocess.check_call(cmd) |
| 29 |
| 30 |
| 31 def _ComputeSHA1(path): |
| 32 if not os.path.exists(path): |
| 33 return 0 |
| 34 |
| 35 sha1 = hashlib.sha1() |
| 36 file_to_hash = open(path, 'rb') |
| 37 try: |
| 38 sha1.update(file_to_hash.read()) |
| 39 finally: |
| 40 file_to_hash.close() |
| 41 |
| 42 return sha1.hexdigest() |
| 43 |
| 44 |
| 45 # This is necessary since Windows won't allow us to unzip onto an existing dir. |
| 46 def _DeleteOldAppEngineDir(): |
| 47 app_engine_dir = 'google_appengine' |
| 48 print 'Deleting %s in %s...' % (app_engine_dir, os.getcwd()) |
| 49 shutil.rmtree(app_engine_dir, ignore_errors=True) |
| 50 |
| 51 |
| 52 def _Unzip(path): |
| 53 print 'Unzipping %s in %s...' % (path, os.getcwd()) |
| 54 zip_file = zipfile.ZipFile(path) |
| 55 try: |
| 56 zip_file.extractall() |
| 57 finally: |
| 58 zip_file.close() |
| 59 |
| 60 |
| 61 def main(argv): |
| 62 if len(argv) == 1: |
| 63 return 'Usage: %s <path to webrtc.DEPS>' % argv[0] |
| 64 |
| 65 webrtc_deps_path = argv[1] |
| 66 zip_path = os.path.join(webrtc_deps_path, 'google-appengine.zip') |
| 67 old_zip_sha1 = _ComputeSHA1(zip_path) |
| 68 |
| 69 _DownloadAppEngineZipFile(webrtc_deps_path) |
| 70 |
| 71 if old_zip_sha1 != _ComputeSHA1(zip_path): |
| 72 _DeleteOldAppEngineDir() |
| 73 _Unzip(zip_path) |
| 74 |
| 75 |
| 76 if __name__ == '__main__': |
| 77 sys.exit(main(sys.argv)) |
OLD | NEW |