[Session restore] Rename group name Enabled to Restore.
[chromium-blink-merge.git] / tools / perf / PRESUBMIT.py
blob70aadd7a160aa9352d758ff2820c2fbca308e03e
1 # Copyright 2012 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.
5 """Presubmit script for changes affecting tools/perf/.
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
8 for more details about the presubmit API built into depot_tools.
9 """
11 import os
12 import sys
14 PYLINT_BLACKLIST = []
15 PYLINT_DISABLED_WARNINGS = [
16 'R0923', # Interface not implemented
17 'R0201', # Method could be a function
18 'E1101', # Non-existent member is accessed.
22 def _CommonChecks(input_api, output_api):
23 """Performs common checks, which includes running pylint."""
24 results = []
25 old_sys_path = sys.path
26 try:
27 # Modules in tools/perf depend on telemetry.
28 sys.path = [os.path.join(os.pardir, 'telemetry')] + sys.path
29 results.extend(input_api.canned_checks.RunPylint(
30 input_api, output_api,
31 black_list=PYLINT_BLACKLIST,
32 disabled_warnings=PYLINT_DISABLED_WARNINGS))
33 results.extend(_CheckJson(input_api, output_api))
34 results.extend(_CheckWprShaFiles(input_api, output_api))
35 finally:
36 sys.path = old_sys_path
37 return results
40 def _CheckWprShaFiles(input_api, output_api):
41 """Check whether the wpr sha files have matching URLs."""
42 from telemetry.util import cloud_storage
43 results = []
44 for affected_file in input_api.AffectedFiles(include_deletes=False):
45 filename = affected_file.AbsoluteLocalPath()
46 if not filename.endswith('wpr.sha1'):
47 continue
48 expected_hash = cloud_storage.ReadHash(filename)
49 is_wpr_file_uploaded = any(
50 cloud_storage.Exists(bucket, expected_hash)
51 for bucket in cloud_storage.BUCKET_ALIASES.itervalues())
52 if not is_wpr_file_uploaded:
53 wpr_filename = filename[:-5]
54 results.append(output_api.PresubmitError(
55 'There is no URLs matched for wpr sha file %s.\n'
56 'You can upload your new wpr archive file with the command:\n'
57 'depot_tools/upload_to_google_storage.py --bucket '
58 '<Your pageset\'s bucket> %s.\nFor more info: see '
59 'http://www.chromium.org/developers/telemetry/'
60 'record_a_page_set#TOC-Upload-the-recording-to-Cloud-Storage' %
61 (filename, wpr_filename)))
62 return results
65 def _CheckJson(input_api, output_api):
66 """Checks whether JSON files in this change can be parsed."""
67 for affected_file in input_api.AffectedFiles(include_deletes=False):
68 filename = affected_file.AbsoluteLocalPath()
69 if os.path.splitext(filename)[1] != '.json':
70 continue
71 try:
72 input_api.json.load(open(filename))
73 except ValueError:
74 return [output_api.PresubmitError('Error parsing JSON in %s!' % filename)]
75 return []
78 def CheckChangeOnUpload(input_api, output_api):
79 report = []
80 report.extend(_CommonChecks(input_api, output_api))
81 return report
84 def CheckChangeOnCommit(input_api, output_api):
85 report = []
86 report.extend(_CommonChecks(input_api, output_api))
87 return report