OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/python2.4 |
| 2 # Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. |
| 5 |
| 6 '''Base class and interface for tools. |
| 7 ''' |
| 8 |
| 9 import sys |
| 10 |
| 11 class Tool(object): |
| 12 '''Base class for all tools. Tools should use their docstring (i.e. the |
| 13 class-level docstring) for the help they want to have printed when they |
| 14 are invoked.''' |
| 15 |
| 16 # |
| 17 # Interface (abstract methods) |
| 18 # |
| 19 |
| 20 def ShortDescription(self): |
| 21 '''Returns a short description of the functionality of the tool.''' |
| 22 raise NotImplementedError() |
| 23 |
| 24 def Run(self, global_options, my_arguments): |
| 25 '''Runs the tool. |
| 26 |
| 27 Args: |
| 28 global_options: object grit_runner.Options |
| 29 my_arguments: [arg1 arg2 ...] |
| 30 |
| 31 Return: |
| 32 0 for success, non-0 for error |
| 33 ''' |
| 34 raise NotImplementedError() |
| 35 |
| 36 # |
| 37 # Base class implementation |
| 38 # |
| 39 |
| 40 def __init__(self): |
| 41 self.o = None |
| 42 |
| 43 def SetOptions(self, opts): |
| 44 self.o = opts |
| 45 |
| 46 def Out(self, text): |
| 47 '''Always writes out 'text'.''' |
| 48 self.o.output_stream.write(text) |
| 49 |
| 50 def VerboseOut(self, text): |
| 51 '''Writes out 'text' if the verbose option is on.''' |
| 52 if self.o.verbose: |
| 53 self.o.output_stream.write(text) |
| 54 |
| 55 def ExtraVerboseOut(self, text): |
| 56 '''Writes out 'text' if the extra-verbose option is on. |
| 57 ''' |
| 58 if self.o.extra_verbose: |
| 59 self.o.output_stream.write(text) |
OLD | NEW |