| Index: download_appengine_and_mercurial.py
|
| ===================================================================
|
| --- download_appengine_and_mercurial.py (revision 293261)
|
| +++ download_appengine_and_mercurial.py (working copy)
|
| @@ -10,15 +10,14 @@
|
| file is. This is what should happen if this script is invoked as a hook action.
|
| """
|
|
|
| -import hashlib
|
| +import glob
|
| import os
|
| -import shutil
|
| import sys
|
| import subprocess
|
| -import zipfile
|
|
|
| +import utils
|
|
|
| -def _DownloadAppEngineZipFile(webrtc_deps_path):
|
| +def _DownloadResources(webrtc_deps_path):
|
| print 'Downloading files in %s...' % webrtc_deps_path
|
|
|
| extension = 'bat' if 'win32' in sys.platform else 'py'
|
| @@ -28,50 +27,33 @@
|
| subprocess.check_call(cmd)
|
|
|
|
|
| -def _ComputeSHA1(path):
|
| - if not os.path.exists(path):
|
| - return 0
|
| +def _StripVersionNumberFromMercurialFolder():
|
| + unpacked_name = glob.glob('mercurial*')
|
| + assert len(unpacked_name) == 1, 'Should have precisely one mercurial!'
|
| + os.rename(unpacked_name[0], 'mercurial')
|
|
|
| - sha1 = hashlib.sha1()
|
| - file_to_hash = open(path, 'rb')
|
| - try:
|
| - sha1.update(file_to_hash.read())
|
| - finally:
|
| - file_to_hash.close()
|
|
|
| - return sha1.hexdigest()
|
| -
|
| -
|
| -# This is necessary since Windows won't allow us to unzip onto an existing dir.
|
| -def _DeleteOldAppEngineDir():
|
| - app_engine_dir = 'google_appengine'
|
| - print 'Deleting %s in %s...' % (app_engine_dir, os.getcwd())
|
| - shutil.rmtree(app_engine_dir, ignore_errors=True)
|
| -
|
| -
|
| -def _Unzip(path):
|
| - print 'Unzipping %s in %s...' % (path, os.getcwd())
|
| - zip_file = zipfile.ZipFile(path)
|
| - try:
|
| - zip_file.extractall()
|
| - finally:
|
| - zip_file.close()
|
| -
|
| -
|
| def main(argv):
|
| if len(argv) == 1:
|
| return 'Usage: %s <path to webrtc.DEPS>' % argv[0]
|
|
|
| webrtc_deps_path = argv[1]
|
| - zip_path = os.path.join(webrtc_deps_path, 'google-appengine.zip')
|
| - old_zip_sha1 = _ComputeSHA1(zip_path)
|
| + appengine_zip_path = os.path.join(webrtc_deps_path, 'google-appengine.zip')
|
| + old_appengine_sha1 = utils.ComputeSHA1(appengine_zip_path)
|
|
|
| - _DownloadAppEngineZipFile(webrtc_deps_path)
|
| + mercurial_tar_path = os.path.join(webrtc_deps_path, 'mercurial-src.tar.gz')
|
| + old_mercurial_sha1 = utils.ComputeSHA1(mercurial_tar_path)
|
|
|
| - if old_zip_sha1 != _ComputeSHA1(zip_path):
|
| - _DeleteOldAppEngineDir()
|
| - _Unzip(zip_path)
|
| + _DownloadResources(webrtc_deps_path)
|
|
|
| + if old_appengine_sha1 != utils.ComputeSHA1(appengine_zip_path):
|
| + utils.DeleteDirNextToGclient('google_appengine')
|
| + utils.UnpackToWorkingDir(appengine_zip_path)
|
|
|
| + if old_mercurial_sha1 != utils.ComputeSHA1(mercurial_tar_path):
|
| + utils.DeleteDirNextToGclient('mercurial')
|
| + utils.UnpackToWorkingDir(mercurial_tar_path)
|
| + _StripVersionNumberFromMercurialFolder()
|
| +
|
| if __name__ == '__main__':
|
| sys.exit(main(sys.argv))
|
|
|