OLD | NEW |
| (Empty) |
1 # Copyright (C) 2009 Google Inc. All rights reserved. | |
2 # | |
3 # Redistribution and use in source and binary forms, with or without | |
4 # modification, are permitted provided that the following conditions are | |
5 # met: | |
6 # | |
7 # * Redistributions of source code must retain the above copyright | |
8 # notice, this list of conditions and the following disclaimer. | |
9 # * Redistributions in binary form must reproduce the above | |
10 # copyright notice, this list of conditions and the following disclaimer | |
11 # in the documentation and/or other materials provided with the | |
12 # distribution. | |
13 # * Neither the name of Google Inc. nor the names of its | |
14 # contributors may be used to endorse or promote products derived from | |
15 # this software without specific prior written permission. | |
16 # | |
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
28 | |
29 import logging | |
30 import sys | |
31 | |
32 from webkitpy.tool import steps | |
33 | |
34 from webkitpy.common.system.executive import ScriptError | |
35 | |
36 _log = logging.getLogger(__name__) | |
37 | |
38 | |
39 class StepSequenceErrorHandler(): | |
40 @classmethod | |
41 def handle_script_error(cls, tool, patch, script_error): | |
42 raise NotImplementedError, "subclasses must implement" | |
43 | |
44 @classmethod | |
45 def handle_checkout_needs_update(cls, tool, state, options, error): | |
46 raise NotImplementedError, "subclasses must implement" | |
47 | |
48 | |
49 class StepSequence(object): | |
50 def __init__(self, steps): | |
51 self._steps = steps or [] | |
52 | |
53 def options(self): | |
54 collected_options = [ | |
55 steps.Options.parent_command, | |
56 steps.Options.quiet, | |
57 ] | |
58 for step in self._steps: | |
59 collected_options = collected_options + step.options() | |
60 # Remove duplicates. | |
61 collected_options = sorted(set(collected_options)) | |
62 return collected_options | |
63 | |
64 def _run(self, tool, options, state): | |
65 for step in self._steps: | |
66 step(tool, options).run(state) | |
67 | |
68 # Child processes exit with a special code to the parent queue process can d
etect the error was handled. | |
69 handled_error_code = 2 | |
70 | |
71 @classmethod | |
72 def exit_after_handled_error(cls, error): | |
73 _log.error(error) | |
74 sys.exit(cls.handled_error_code) | |
75 | |
76 def run_and_handle_errors(self, tool, options, state=None): | |
77 if not state: | |
78 state = {} | |
79 try: | |
80 self._run(tool, options, state) | |
81 except ScriptError, e: | |
82 if not options.quiet: | |
83 _log.error(e.message_with_output()) | |
84 if options.parent_command: | |
85 command = tool.command_by_name(options.parent_command) | |
86 command.handle_script_error(tool, state, e) | |
87 self.exit_after_handled_error(e) | |
OLD | NEW |