Home | History | Annotate | Download | only in webkitpy

Lines Matching full:self

45     def __init__(self, help_text, argument_names=None, options=None, long_help=None, requires_local_commits=False):
46 self.help_text = help_text
47 self.long_help = long_help
48 self.argument_names = argument_names
49 self.required_arguments = self._parse_required_arguments(argument_names)
50 self.options = options
51 self.requires_local_commits = requires_local_commits
52 self.tool = None
55 self.option_parser = HelpPrintingOptionParser(usage=SUPPRESS_USAGE, add_help_option=False, option_list=self.options)
60 def set_option_parser(self, option_parser):
61 self.option_parser = option_parser
62 self._add_options_to_parser()
64 def _add_options_to_parser(self):
65 options = self.options or []
67 self.option_parser.add_option(option)
70 def bind_to_tool(self, tool):
72 if self.tool and tool != self.tool:
74 self.tool = tool
92 def name_with_arguments(self):
93 usage_string = self.name
94 if self.options:
96 if self.argument_names:
97 usage_string += " " + self.argument_names
100 def parse_args(self, args):
101 return self.option_parser.parse_args(args)
103 def check_arguments_and_execute(self, options, args, tool=None):
104 if len(args) < len(self.required_arguments):
106 pluralize("argument", len(self.required_arguments)),
109 " ".join(self.required_arguments),
111 self.name))
113 return self.execute(options, args, tool) or 0
115 def standalone_help(self):
116 help_text = self.name_with_arguments().ljust(len(self.name_with_arguments()) + 3) + self.help_text + "\n\n"
117 if self.long_help:
118 help_text += "%s\n\n" % self.long_help
119 help_text += self.option_parser.format_option_help(IndentedHelpFormatter())
122 def execute(self, options, args, tool):
127 def main(self, args=sys.argv):
128 (options, args) = self.parse_args(args)
130 return self.check_arguments_and_execute(options, args)
138 def __init__(self, options=None, **kwargs):
139 Command.__init__(self, self.help_text, self.argument_names, options=options, long_help=self.long_help, **kwargs)
143 def __init__(self, epilog_method=None, *args, **kwargs):
144 self.epilog_method = epilog_method
145 OptionParser.__init__(self, *args, **kwargs)
147 def error(self, msg):
148 self.print_usage(sys.stderr)
149 error_message = "%s: error: %s\n" % (self.get_prog_name(), msg)
151 error_message += "\nType \"%s --help\" to see usage.\n" % self.get_prog_name()
152 self.exit(1, error_message)
156 def format_epilog(self, epilog):
157 if self.epilog_method:
158 return "\n%s\n" % self.epilog_method()
167 def __init__(self):
171 AbstractDeclarativeCommand.__init__(self, options)
172 self.show_all_commands = False # A hack used to pass --all-commands to _help_epilog even though it's called by the OptionParser.
174 def _help_epilog(self):
176 if self.show_all_commands:
178 relevant_commands = self.tool.commands[:]
181 relevant_commands = filter(self.tool.should_show_in_main_help, self.tool.commands)
188 return epilog.replace("%prog", self.tool.name()) # Use of %prog here mimics OptionParser.expand_prog_name().
191 def _remove_help_options(self):
192 for option in self.options:
193 self.option_parser.remove_option(option.get_opt_string())
195 def execute(self, options, args, tool):
197 command = self.tool.command_by_name(args[0])
202 self.show_all_commands = options.show_all_commands
203 self._remove_help_options()
204 self.option_parser.print_help()
211 def __init__(self, name=None, commands=None):
212 self._name = name or OptionParser(prog=name).get_prog_name() # OptionParser has nice logic for fetching the name.
214 self.commands = commands or [cls() for cls in self._find_all_commands() if cls.name]
215 self.help_command = self.command_by_name(HelpCommand.name)
217 if not self.help_command:
218 self.help_command = HelpCommand()
219 self.commands.append(self.help_command)
220 for command in self.commands:
221 command.bind_to_tool(self)
236 def name(self):
237 return self._name
239 def _create_option_parser(self):
241 return HelpPrintingOptionParser(epilog_method=self.help_command._help_epilog, prog=self.name(), usage=usage)
257 def command_by_name(self, command_name):
258 for command in self.commands:
263 def path(self):
266 def should_show_in_main_help(self, command):
269 def should_execute_command(self, command):
272 def _add_global_options(self, option_parser):
273 global_options = self.global_options or []
277 def handle_global_options(self, options):
280 def main(self, argv=sys.argv):
281 (command_name, args) = self._split_command_name_from_args(argv[1:])
283 option_parser = self._create_option_parser()
284 self._add_global_options(option_parser)
286 command = self.command_by_name(command_name) or self.help_command
292 self.handle_global_options(options)
294 (should_execute, failure_reason) = self.should_execute_command(command)
299 return command.check_arguments_and_execute(options, args, self)