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

Side by Side 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: Created 7 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4 import os
5 import re
6 import sys
7
8
9 DEFAULT_BUCKET = 'chromium-wpr'
10
11
12 def _SyncFilesToCloud(input_api, output_api):
13 """Searches for .sha1 files and uploads them to Cloud Storage.
14
15 It validates all the hashes and skips upload if not necessary.
16 """
17 # Because this script will be called from a magic PRESUBMIT demon,
18 # avoid angering it; don't pollute its sys.path.
19 old_sys_path = sys.path
20 try:
21 sys.path = [os.path.join(os.pardir, os.pardir, 'telemetry')] + sys.path
22 from telemetry.page import cloud_storage
23 finally:
24 sys.path = old_sys_path
25
26 hashes_in_cloud_storage = cloud_storage.List(DEFAULT_BUCKET)
27
28 results = []
29 for hash_path in input_api.AbsoluteLocalPaths():
30 file_path, extension = os.path.splitext(hash_path)
31 if extension != '.sha1':
32 continue
33
34 with open(hash_path, 'rb') as f:
35 file_hash = f.read(1024).rstrip()
36 if file_hash in hashes_in_cloud_storage:
37 results.append(output_api.PresubmitNotifyResult(
38 'File already in Cloud Storage, skipping upload: %s' % hash_path))
39 continue
40
41 if not re.match('^([A-Za-z0-9]{40})$', file_hash):
42 results.append(output_api.PresubmitError(
43 'Hash file does not contain a valid SHA-1 hash: %s' % hash_path))
44 continue
45 if not os.path.exists(file_path):
46 results.append(output_api.PresubmitError(
47 'Hash file exists, but file not found: %s' % hash_path))
48 continue
49 if cloud_storage.GetHash(file_path) != file_hash:
50 results.append(output_api.PresubmitError(
51 'Hash file does not match file\'s actual hash: %s' % hash_path))
52 continue
53
54 try:
55 cloud_storage.Insert(DEFAULT_BUCKET, file_hash, file_path)
56 except cloud_storage.CloudStorageError:
57 results.append(output_api.PresubmitError(
58 'Unable to upload to Cloud Storage: %s' % hash_path))
59
60 return results
61
62
63 def CheckChangeOnCommit(input_api, output_api):
64 results = []
65 results += _SyncFilesToCloud(input_api, output_api)
66 return results
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698