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

Unified Diff: sdk_build/data/common/download_file_from_google_storage.py

Issue 1720433003: SDK stuff: Add a script to download the mojom parser binary. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 10 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 | « sdk_build/build_sdk.py ('k') | sdk_build/data/common/download_mojom_parser.sh » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk_build/data/common/download_file_from_google_storage.py
diff --git a/sdk_build/data/common/download_file_from_google_storage.py b/sdk_build/data/common/download_file_from_google_storage.py
new file mode 100755
index 0000000000000000000000000000000000000000..28feb4d3db4d479e21aa9af637f5adaed03fee94
--- /dev/null
+++ b/sdk_build/data/common/download_file_from_google_storage.py
@@ -0,0 +1,68 @@
+#!/usr/bin/env python
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+#FIXME
+
+import argparse
+import hashlib
+import httplib
+import os
+import sys
+
+
+def _FatalError(message):
+ print >> sys.stderr, "%s: fatal error: %s" % (os.path.basename(sys.argv[0]),
+ message)
+
+
+def _DownloadFile(source):
+ """FIXME"""
+
+ try:
+ conn = httplib.HTTPSConnection("storage.googleapis.com")
+ conn.request("GET", "/" + source)
+ resp = conn.getresponse()
+ if resp.status != httplib.OK:
+ _FatalError("HTTP status: %s" % resp.reason)
+ data = resp.read()
+ conn.close()
+ return data
+ except httplib.HTTPException as e:
+ _FatalError("HTTP exception: %s" % str(e))
+
+
+def main():
+ parser = argparse.ArgumentParser(
+ description="Downloads a file from Google Cloud Storage.")
+ parser.add_argument("--sha1-hash", dest="sha1_hash",
+ help="SHA-1 hash for the downloaded file")
+ parser.add_argument("--executable", action="store_true",
+ help="make the downloaded file executable")
+ parser.add_argument("source", help="source path, including bucket name")
+ parser.add_argument("destination", help="destination path")
+ args = parser.parse_args()
+
+ bits = _DownloadFile(args.source)
+ if args.sha1_hash:
+ got_sha1_hash = hashlib.sha1(bits).hexdigest().lower()
+ expected_sha1_hash = args.sha1_hash.lower()
+ if got_sha1_hash != expected_sha1_hash:
+ _FatalError("SHA-1 hash did not match: got %s, expected %s" %
+ (got_sha1_hash, expected_sha1_hash))
+
+ with open(args.destination, "wb") as f:
+ f.write(bits)
+
+ if args.executable:
+ curr_mode = os.stat(args.destination).st_mode
+ # Set the x bits (0111) where the r bits (0444) are set.
+ new_mode = curr_mode | ((curr_mode & 0444) >> 2)
+ os.chmod(args.destination, new_mode)
+
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(main())
« no previous file with comments | « sdk_build/build_sdk.py ('k') | sdk_build/data/common/download_mojom_parser.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698