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

Side by Side Diff: third_party/WebKit/Tools/Scripts/webkitpy/tool/multi_command_tool.py

Issue 2073893004: Reland of Use an explicit list of webkit-patch commands instead of using auto-discovery. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added a FIXME note about a possible refactoring. Created 4 years, 6 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
OLDNEW
1 # Copyright (c) 2009 Google Inc. All rights reserved. 1 # Copyright (c) 2009 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
(...skipping 17 matching lines...) Expand all
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 # 29 #
30 # MultiCommandTool provides a framework for writing svn-like/git-like tools 30 # MultiCommandTool provides a framework for writing svn-like/git-like tools
31 # which are called with the following format: 31 # which are called with the following format:
32 # tool-name [global options] command-name [command options] 32 # tool-name [global options] command-name [command options]
33 33
34 import optparse 34 import optparse
35 import logging 35 import logging
36 import sys 36 import sys
37 37
38 from webkitpy.tool.commands.command import Command
39 from webkitpy.tool.commands.command import HelpPrintingOptionParser 38 from webkitpy.tool.commands.command import HelpPrintingOptionParser
40 from webkitpy.tool.commands.help_command import HelpCommand 39 from webkitpy.tool.commands.help_command import HelpCommand
41 40
42 _log = logging.getLogger(__name__) 41 _log = logging.getLogger(__name__)
43 42
44 43
45 class MultiCommandTool(object): 44 class MultiCommandTool(object):
46 45
47 global_options = None 46 global_options = None
48 47
49 def __init__(self, name=None, commands=None): 48 def __init__(self, name=None, commands=None):
50 self._name = name or optparse.OptionParser(prog=name).get_prog_name() # OptionParser has nice logic for fetching the name. 49 self._name = name or optparse.OptionParser(prog=name).get_prog_name() # OptionParser has nice logic for fetching the name.
51 # Allow the unit tests to disable command auto-discovery. 50 self.commands = commands or []
Dirk Pranke 2016/06/17 19:09:25 can we make name and commands mandatory parameters
qyearsley 2016/06/17 20:10:06 That makes sense; now done.
52 self.commands = commands or [cls() for cls in self._find_all_commands() if cls.name]
53 self.help_command = self.command_by_name(HelpCommand.name) 51 self.help_command = self.command_by_name(HelpCommand.name)
54 # Require a help command, even if the manual test list doesn't include o ne. 52 # Require the help command, even if the manual test list doesn't include one.
55 if not self.help_command: 53 if not self.help_command:
56 self.help_command = HelpCommand() 54 self.help_command = HelpCommand()
57 self.commands.append(self.help_command) 55 self.commands.append(self.help_command)
56 # FIXME: Since tool is passed to Command.execute, it may not be necessar y to set a tool attribute on the
57 # command objects here - maybe this should be done inside of Command.exe cute for commands that use self._tool.
58 for command in self.commands: 58 for command in self.commands:
59 command.bind_to_tool(self) 59 command.bind_to_tool(self)
60 60
61 @classmethod
62 def _add_all_subclasses(cls, class_to_crawl, seen_classes):
63 for subclass in class_to_crawl.__subclasses__():
64 if subclass not in seen_classes:
65 seen_classes.add(subclass)
66 cls._add_all_subclasses(subclass, seen_classes)
67
68 @classmethod
69 def _find_all_commands(cls):
70 commands = set()
71 cls._add_all_subclasses(Command, commands)
72 return sorted(commands)
73
74 def name(self): 61 def name(self):
75 return self._name 62 return self._name
76 63
77 def _create_option_parser(self): 64 def _create_option_parser(self):
78 usage = "Usage: %prog [options] COMMAND [ARGS]" 65 usage = "Usage: %prog [options] COMMAND [ARGS]"
79 return HelpPrintingOptionParser(epilog_method=self.help_command._help_ep ilog, prog=self.name(), usage=usage) 66 return HelpPrintingOptionParser(epilog_method=self.help_command._help_ep ilog, prog=self.name(), usage=usage)
80 67
81 @staticmethod 68 @staticmethod
82 def _split_command_name_from_args(args): 69 def _split_command_name_from_args(args):
83 # Assume the first argument which doesn't start with "-" is the command name. 70 # Assume the first argument which doesn't start with "-" is the command name.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 122
136 (should_execute, failure_reason) = self.should_execute_command(command) 123 (should_execute, failure_reason) = self.should_execute_command(command)
137 if not should_execute: 124 if not should_execute:
138 _log.error(failure_reason) 125 _log.error(failure_reason)
139 return 0 # FIXME: Should this really be 0? 126 return 0 # FIXME: Should this really be 0?
140 127
141 result = command.check_arguments_and_execute(options, args, self) 128 result = command.check_arguments_and_execute(options, args, self)
142 129
143 self.command_completed() 130 self.command_completed()
144 return result 131 return result
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698