OLD | NEW |
(Empty) | |
| 1 # Copyright (c) 2011 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 |
| 5 # If this presubmit check fails or misbehaves, please complain to |
| 6 # gfeher@chromium.org or jkummerow@chromium.org. |
| 7 |
| 8 import sys |
| 9 |
| 10 |
| 11 def _CommonChecks(input_api, output_api): |
| 12 filepath = input_api.os_path.join(input_api.PresubmitLocalPath(), |
| 13 'policy_templates.json') |
| 14 if any(f.AbsoluteLocalPath() == filepath |
| 15 for f in input_api.AffectedFiles()): |
| 16 old_sys_path = sys.path |
| 17 try: |
| 18 sys.path = [input_api.PresubmitLocalPath()] + sys.path |
| 19 # Optimization: only load this when it's needed. |
| 20 import syntax_check_policy_template_json |
| 21 checker = syntax_check_policy_template_json.PolicyTemplateChecker() |
| 22 if checker.Run([], filepath) > 0: |
| 23 return [output_api.PresubmitError('Syntax error(s) in file:', |
| 24 [filepath])] |
| 25 finally: |
| 26 sys.path = old_sys_path |
| 27 return [] |
| 28 |
| 29 |
| 30 def CheckChangeOnUpload(input_api, output_api): |
| 31 return _CommonChecks(input_api, output_api) |
| 32 |
| 33 |
| 34 def CheckChangeOnCommit(input_api, output_api): |
| 35 return _CommonChecks(input_api, output_api) |
OLD | NEW |