OLD | NEW |
(Empty) | |
| 1 # Copyright 2016 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 """Presubmit script for Chromium browser resources. |
| 6 |
| 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
| 8 for more details about the presubmit API built into depot_tools, and see |
| 9 http://www.chromium.org/developers/web-development-style-guide for the rules |
| 10 we're checking against here. |
| 11 """ |
| 12 |
| 13 import os |
| 14 import sys |
| 15 |
| 16 class IcoFiles(object): |
| 17 """Verifier of ICO files for Chromium resources. |
| 18 """ |
| 19 |
| 20 def __init__(self, input_api, output_api): |
| 21 """ Initializes IcoFiles with path.""" |
| 22 self.input_api = input_api |
| 23 self.output_api = output_api |
| 24 |
| 25 tool_path = input_api.os_path.join(input_api.PresubmitLocalPath(), |
| 26 '../../../tools/resources') |
| 27 sys.path.insert(0, tool_path) |
| 28 |
| 29 def RunChecks(self): |
| 30 """Verifies the correctness of the ICO files. |
| 31 |
| 32 Returns: |
| 33 An array of presubmit errors if any ICO files were broken in some way. |
| 34 """ |
| 35 results = [] |
| 36 affected_files = self.input_api.AffectedFiles(include_deletes=False) |
| 37 for f in affected_files: |
| 38 path = f.LocalPath() |
| 39 if os.path.splitext(path)[1].lower() != '.ico': |
| 40 continue |
| 41 |
| 42 # Import this module from here (to avoid importing it in the highly common |
| 43 # case where there are no ICO files being changed). |
| 44 import ico_tools |
| 45 |
| 46 repository_path = self.input_api.change.RepositoryRoot() |
| 47 |
| 48 with open(os.path.join(repository_path, path), 'rb') as ico_file: |
| 49 errors = list(ico_tools.LintIcoFile(ico_file)) |
| 50 if errors: |
| 51 error_string = '\n'.join(' * ' + e for e in errors) |
| 52 results.append(self.output_api.PresubmitError( |
| 53 '%s: This file does not meet the standards for Chromium ICO ' |
| 54 'files.\n%s\n Please run ' |
| 55 'tools/resources/optimize-ico-files.py on this file. See ' |
| 56 'chrome/app/theme/README for details.' % (path, error_string))) |
| 57 return results |
OLD | NEW |