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

Unified Diff: utils.py

Issue 759163003: Add infrastructure to download golang and build AppRTC collider. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/webrtc/webrtc.DEPS/
Patch Set: Created 6 years 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
« download_golang.py ('K') | « mercurial-src.tar.gz.sha1 ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils.py
===================================================================
--- utils.py (revision 0)
+++ utils.py (working copy)
@@ -0,0 +1,73 @@
+#!/usr/bin/python
+# Copyright 201t The Chromium Authors. All rights reserved.
kjellander_chromium 2014/12/08 13:58:08 201t -> 2014.
phoglund_chromium 2014/12/08 14:26:16 Done.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Utilities for all our deps-management stuff."""
+
+import hashlib
+import os
+import shutil
+import sys
+import tarfile
+import zipfile
+
+
+def ComputeSHA1(path):
+ if not os.path.exists(path):
kjellander_chromium 2014/12/08 13:58:08 Returning 0 for non-existing files would be unexpe
phoglund_chromium 2014/12/08 14:26:16 That would introduce a lot of cruft in the calling
kjellander_chromium 2014/12/08 14:52:25 Fair enough.
+ return 0
+
+ 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.
kjellander_chromium 2014/12/08 13:58:08 "This is" is referencing what? I think this should
phoglund_chromium 2014/12/08 14:26:16 Deleted the comment.
phoglund_chromium 2014/12/08 14:26:16 Done.
+def DeleteDirNextToGclient(directory):
+ # Sanity check to avoid nuking the wrong dirs.
+ if not os.path.exists('.gclient'):
+ raise Exception('Invoked from wrong dir; invoke from dir with .gclient')
+ print 'Deleting %s in %s...' % (directory, os.getcwd())
+ shutil.rmtree(directory, ignore_errors=True)
+
+
+def UnpackToWorkingDir(archive_path):
+ extension = os.path.splitext(archive_path)[1]
+ if extension == '.zip':
+ _Unzip(archive_path)
+ else:
+ _Untar(archive_path)
+
+
+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 _Untar(path):
+ print 'Untarring %s in %s...' % (path, os.getcwd())
+ tar_file = tarfile.open(path, 'r:gz')
+ try:
+ tar_file.extractall()
+ finally:
+ tar_file.close()
+
+
+def GetPlatform():
+ if sys.platform.startswith('win'):
+ return 'win'
+ if sys.platform.startswith('linux'):
+ return 'linux'
+ if sys.platform.startswith('darwin'):
+ return 'mac'
+ raise Exception("Can't run on platform %s." % sys.platform)
kjellander_chromium 2014/12/08 13:58:08 Single-quote string and escape it like Can\'t inst
phoglund_chromium 2014/12/08 14:26:16 I watched a python readability review and this was
kjellander_chromium 2014/12/08 14:52:25 Acknowledged.
+
Property changes on: utils.py
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+LF
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
« download_golang.py ('K') | « mercurial-src.tar.gz.sha1 ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698