Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2010 Google Inc. All rights reserved. | 1 # Copyright (c) 2010 Google Inc. All rights reserved. |
| 2 # Copyright (c) 2009 Apple Inc. All rights reserved. | 2 # Copyright (c) 2009 Apple Inc. All rights reserved. |
| 3 # | 3 # |
| 4 # Redistribution and use in source and binary forms, with or without | 4 # Redistribution and use in source and binary forms, with or without |
| 5 # modification, are permitted provided that the following conditions are | 5 # modification, are permitted provided that the following conditions are |
| 6 # met: | 6 # met: |
| 7 # | 7 # |
| 8 # * Redistributions of source code must retain the above copyright | 8 # * Redistributions of source code must retain the above copyright |
| 9 # notice, this list of conditions and the following disclaimer. | 9 # notice, this list of conditions and the following disclaimer. |
| 10 # * Redistributions in binary form must reproduce the above | 10 # * Redistributions in binary form must reproduce the above |
| 11 # copyright notice, this list of conditions and the following disclaimer | 11 # copyright notice, this list of conditions and the following disclaimer |
| 12 # in the documentation and/or other materials provided with the | 12 # in the documentation and/or other materials provided with the |
| 13 # distribution. | 13 # distribution. |
| 14 # * Neither the name of Google Inc. nor the names of its | 14 # * Neither the name of Google Inc. nor the names of its |
| 15 # contributors may be used to endorse or promote products derived from | 15 # contributors may be used to endorse or promote products derived from |
| 16 # this software without specific prior written permission. | 16 # this software without specific prior written permission. |
| 17 # | 17 # |
| 18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 # | |
| 30 # A tool for automating dealing with bugzilla, posting patches, committing patch es, etc. | |
| 31 | 29 |
| 30 """Webkit-patch is a tool with multiple sub-commands with different purposes. | |
| 31 | |
| 32 Historically, it had commands related to dealing with bugzilla, and posting | |
| 33 and comitting patches to WebKit. More recently, it has commands for printing | |
| 34 expectations, fetching new test baselines, starting a commit-announcer IRC bot, | |
| 35 etc. These commands don't necessarily have anything to do with each other. | |
| 36 """ | |
| 37 | |
| 38 import logging | |
| 39 import sys | |
| 32 from optparse import make_option | 40 from optparse import make_option |
| 33 | 41 |
| 34 from webkitpy.common.host import Host | 42 from webkitpy.common.host import Host |
| 35 from webkitpy.tool.multi_command_tool import MultiCommandTool | |
| 36 | 43 |
| 37 from webkitpy.tool.commands.analyze_baselines import AnalyzeBaselines | 44 from webkitpy.tool.commands.analyze_baselines import AnalyzeBaselines |
| 38 from webkitpy.tool.commands.commit_announcer import CommitAnnouncerCommand | 45 from webkitpy.tool.commands.commit_announcer import CommitAnnouncerCommand |
| 39 from webkitpy.tool.commands.flaky_tests import FlakyTests | 46 from webkitpy.tool.commands.flaky_tests import FlakyTests |
| 40 from webkitpy.tool.commands.layout_tests_server import LayoutTestsServer | 47 from webkitpy.tool.commands.layout_tests_server import LayoutTestsServer |
| 41 from webkitpy.tool.commands.pretty_diff import PrettyDiff | 48 from webkitpy.tool.commands.pretty_diff import PrettyDiff |
| 42 from webkitpy.tool.commands.queries import CrashLog | 49 from webkitpy.tool.commands.queries import CrashLog |
| 43 from webkitpy.tool.commands.queries import PrintBaselines | 50 from webkitpy.tool.commands.queries import PrintBaselines |
| 44 from webkitpy.tool.commands.queries import PrintExpectations | 51 from webkitpy.tool.commands.queries import PrintExpectations |
| 45 from webkitpy.tool.commands.rebaseline import AutoRebaseline | 52 from webkitpy.tool.commands.rebaseline import AutoRebaseline |
| 46 from webkitpy.tool.commands.rebaseline import CopyExistingBaselinesInternal | 53 from webkitpy.tool.commands.rebaseline import CopyExistingBaselinesInternal |
| 47 from webkitpy.tool.commands.rebaseline import OptimizeBaselines | 54 from webkitpy.tool.commands.rebaseline import OptimizeBaselines |
| 48 from webkitpy.tool.commands.rebaseline import Rebaseline | 55 from webkitpy.tool.commands.rebaseline import Rebaseline |
| 49 from webkitpy.tool.commands.rebaseline import RebaselineExpectations | 56 from webkitpy.tool.commands.rebaseline import RebaselineExpectations |
| 50 from webkitpy.tool.commands.rebaseline import RebaselineJson | 57 from webkitpy.tool.commands.rebaseline import RebaselineJson |
| 51 from webkitpy.tool.commands.rebaseline import RebaselineTest | 58 from webkitpy.tool.commands.rebaseline import RebaselineTest |
| 52 from webkitpy.tool.commands.rebaseline_server import RebaselineServer | 59 from webkitpy.tool.commands.rebaseline_server import RebaselineServer |
| 53 from webkitpy.tool.commands.rebaseline_from_try_jobs import RebaselineFromTryJob s | 60 from webkitpy.tool.commands.rebaseline_from_try_jobs import RebaselineFromTryJob s |
| 54 | 61 |
| 62 import optparse | |
| 55 | 63 |
| 56 class WebKitPatch(MultiCommandTool, Host): | 64 import sys |
| 65 | |
| 66 from webkitpy.tool.commands.command import HelpPrintingOptionParser | |
| 67 from webkitpy.tool.commands.help_command import HelpCommand | |
| 68 | |
| 69 | |
| 70 _log = logging.getLogger(__name__) | |
| 71 | |
| 72 | |
| 73 class WebKitPatch(Host): | |
| 57 global_options = [ | 74 global_options = [ |
| 58 make_option("-v", "--verbose", action="store_true", dest="verbose", defa ult=False, help="enable all logging"), | 75 make_option("-v", "--verbose", action="store_true", dest="verbose", defa ult=False, help="enable all logging"), |
| 59 make_option("-d", "--directory", action="append", dest="patch_directorie s", | 76 make_option("-d", "--directory", action="append", dest="patch_directorie s", |
| 60 default=[], help="Directory to look at for changed files"), | 77 default=[], help="Directory to look at for changed files"), |
| 61 ] | 78 ] |
| 62 | 79 |
| 63 def __init__(self, path): | 80 def __init__(self): |
| 64 MultiCommandTool.__init__(self, commands=[ | 81 Host.__init__(self) |
|
Dirk Pranke
2016/07/01 22:55:42
I'd probably use super() here to be consistent w/
qyearsley
2016/07/02 17:26:29
Done
| |
| 82 self.commands = [ | |
| 65 AnalyzeBaselines(), | 83 AnalyzeBaselines(), |
| 66 AutoRebaseline(), | 84 AutoRebaseline(), |
| 67 CommitAnnouncerCommand(), | 85 CommitAnnouncerCommand(), |
| 68 CopyExistingBaselinesInternal(), | 86 CopyExistingBaselinesInternal(), |
| 69 CrashLog(), | 87 CrashLog(), |
| 70 FlakyTests(), | 88 FlakyTests(), |
| 71 LayoutTestsServer(), | 89 LayoutTestsServer(), |
| 72 OptimizeBaselines(), | 90 OptimizeBaselines(), |
| 73 PrettyDiff(), | 91 PrettyDiff(), |
| 74 PrintBaselines(), | 92 PrintBaselines(), |
| 75 PrintExpectations(), | 93 PrintExpectations(), |
| 76 Rebaseline(), | 94 Rebaseline(), |
| 77 RebaselineExpectations(), | 95 RebaselineExpectations(), |
| 78 RebaselineFromTryJobs(), | 96 RebaselineFromTryJobs(), |
| 79 RebaselineJson(), | 97 RebaselineJson(), |
| 80 RebaselineServer(), | 98 RebaselineServer(), |
| 81 RebaselineTest(), | 99 RebaselineTest(), |
| 82 ]) | 100 ] |
| 83 Host.__init__(self) | 101 self.help_command = HelpCommand() |
| 84 self._path = path | 102 self.commands.append(self.help_command) |
| 103 # FIXME: Since tool is passed to Command.execute, it may not be necessar y to set a tool attribute on the | |
| 104 # command objects here - maybe this should be done inside of Command.exe cute for commands that use self._tool. | |
| 105 for command in self.commands: | |
| 106 command.bind_to_tool(self) | |
| 85 | 107 |
| 86 def path(self): | 108 def main(self, argv=None): |
| 87 return self._path | 109 argv = argv or sys.argv |
| 110 (command_name, args) = self._split_command_name_from_args(argv[1:]) | |
| 111 | |
| 112 option_parser = self._create_option_parser() | |
| 113 self._add_global_options(option_parser) | |
| 114 | |
| 115 command = self.command_by_name(command_name) or self.help_command | |
| 116 if not command: | |
| 117 option_parser.error("%s is not a recognized command" % command_name) | |
| 118 | |
| 119 command.set_option_parser(option_parser) | |
| 120 (options, args) = command.parse_args(args) | |
| 121 self._handle_global_options(options) | |
| 122 | |
| 123 (should_execute, failure_reason) = self._should_execute_command(command) | |
| 124 if not should_execute: | |
| 125 _log.error(failure_reason) | |
| 126 return 0 # FIXME: Should this really be 0? | |
| 127 | |
| 128 result = command.check_arguments_and_execute(options, args, self) | |
| 129 return result | |
| 130 | |
| 131 @staticmethod | |
| 132 def _split_command_name_from_args(args): | |
| 133 # Assume the first argument which doesn't start with "-" is the command name. | |
| 134 command_index = 0 | |
| 135 for arg in args: | |
| 136 if arg[0] != "-": | |
| 137 break | |
| 138 command_index += 1 | |
| 139 else: | |
| 140 return (None, args[:]) | |
| 141 | |
| 142 command = args[command_index] | |
| 143 return (command, args[:command_index] + args[command_index + 1:]) | |
| 144 | |
| 145 def _create_option_parser(self): | |
| 146 usage = "Usage: %prog [options] COMMAND [ARGS]" | |
| 147 name = optparse.OptionParser().get_prog_name() | |
| 148 return HelpPrintingOptionParser(epilog_method=self.help_command._help_ep ilog, prog=name, usage=usage) | |
| 149 | |
| 150 def _add_global_options(self, option_parser): | |
| 151 global_options = self.global_options or [] | |
| 152 for option in global_options: | |
| 153 option_parser.add_option(option) | |
| 154 | |
| 155 # FIXME: This may be unnecessary since we pass global options to all command s during execute() as well. | |
| 156 def _handle_global_options(self, options): | |
| 157 self.initialize_scm(options.patch_directories) | |
| 158 | |
| 159 def _should_execute_command(self, command): | |
| 160 if command.requires_local_commits and not self.scm().supports_local_comm its(): | |
| 161 failure_reason = "%s requires local commits using %s in %s." % ( | |
| 162 command.name, self.scm().display_name(), self.scm().checkout_roo t) | |
| 163 return (False, failure_reason) | |
| 164 return (True, None) | |
| 88 | 165 |
| 89 def should_show_in_main_help(self, command): | 166 def should_show_in_main_help(self, command): |
| 90 if not command.show_in_main_help: | 167 if not command.show_in_main_help: |
| 91 return False | 168 return False |
| 92 if command.requires_local_commits: | 169 if command.requires_local_commits: |
| 93 return self.scm().supports_local_commits() | 170 return self.scm().supports_local_commits() |
| 94 return True | 171 return True |
| 95 | 172 |
| 96 # FIXME: This may be unnecessary since we pass global options to all command s during execute() as well. | 173 def command_by_name(self, command_name): |
| 97 def handle_global_options(self, options): | 174 for command in self.commands: |
| 98 self.initialize_scm(options.patch_directories) | 175 if command_name == command.name: |
| 99 | 176 return command |
| 100 def should_execute_command(self, command): | 177 return None |
| 101 if command.requires_local_commits and not self.scm().supports_local_comm its(): | |
| 102 failure_reason = "%s requires local commits using %s in %s." % ( | |
| 103 command.name, self.scm().display_name(), self.scm().checkout_roo t) | |
| 104 return (False, failure_reason) | |
| 105 return (True, None) | |
| OLD | NEW |