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

Unified Diff: tools/perf/page_sets/PRESUBMIT.py

Issue 21684002: [telemetry] Automatic hash file creation and upload to Cloud Storage. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add to unit tests. Created 7 years, 5 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 | « tools/perf/page_sets/.gitignore ('k') | tools/telemetry/telemetry/page/cloud_storage.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/perf/page_sets/PRESUBMIT.py
diff --git a/tools/perf/page_sets/PRESUBMIT.py b/tools/perf/page_sets/PRESUBMIT.py
new file mode 100644
index 0000000000000000000000000000000000000000..f9eeac219371d654063e8272410fd280ba41b427
--- /dev/null
+++ b/tools/perf/page_sets/PRESUBMIT.py
@@ -0,0 +1,66 @@
+# Copyright (c) 2013 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.
+import os
+import re
+import sys
+
+
+DEFAULT_BUCKET = 'chromium-wpr'
+
+
+def _SyncFilesToCloud(input_api, output_api):
+ """Searches for .sha1 files and uploads them to Cloud Storage.
+
+ It validates all the hashes and skips upload if not necessary.
+ """
+ # Because this script will be called from a magic PRESUBMIT demon,
+ # avoid angering it; don't pollute its sys.path.
+ old_sys_path = sys.path
+ try:
+ sys.path = [os.path.join(os.pardir, os.pardir, 'telemetry')] + sys.path
+ from telemetry.page import cloud_storage
+ finally:
+ sys.path = old_sys_path
+
+ hashes_in_cloud_storage = cloud_storage.List(DEFAULT_BUCKET)
+
+ results = []
+ for hash_path in input_api.AbsoluteLocalPaths():
+ file_path, extension = os.path.splitext(hash_path)
+ if extension != '.sha1':
+ continue
+
+ with open(hash_path, 'rb') as f:
+ file_hash = f.read(1024).rstrip()
+ if file_hash in hashes_in_cloud_storage:
+ results.append(output_api.PresubmitNotifyResult(
+ 'File already in Cloud Storage, skipping upload: %s' % hash_path))
+ continue
+
+ if not re.match('^([A-Za-z0-9]{40})$', file_hash):
+ results.append(output_api.PresubmitError(
+ 'Hash file does not contain a valid SHA-1 hash: %s' % hash_path))
+ continue
+ if not os.path.exists(file_path):
+ results.append(output_api.PresubmitError(
+ 'Hash file exists, but file not found: %s' % hash_path))
+ continue
+ if cloud_storage.GetHash(file_path) != file_hash:
+ results.append(output_api.PresubmitError(
+ 'Hash file does not match file\'s actual hash: %s' % hash_path))
+ continue
+
+ try:
+ cloud_storage.Insert(DEFAULT_BUCKET, file_hash, file_path)
+ except cloud_storage.CloudStorageError:
+ results.append(output_api.PresubmitError(
+ 'Unable to upload to Cloud Storage: %s' % hash_path))
+
+ return results
+
+
+def CheckChangeOnCommit(input_api, output_api):
+ results = []
+ results += _SyncFilesToCloud(input_api, output_api)
+ return results
« no previous file with comments | « tools/perf/page_sets/.gitignore ('k') | tools/telemetry/telemetry/page/cloud_storage.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698