|
1 # Copyright (c) 2010 Google Inc. All rights reserved. |
|
2 # Copyright (c) 2009 Apple Inc. All rights reserved. |
|
3 # |
|
4 # Redistribution and use in source and binary forms, with or without |
|
5 # modification, are permitted provided that the following conditions are |
|
6 # met: |
|
7 # |
|
8 # * Redistributions of source code must retain the above copyright |
|
9 # notice, this list of conditions and the following disclaimer. |
|
10 # * Redistributions in binary form must reproduce the above |
|
11 # copyright notice, this list of conditions and the following disclaimer |
|
12 # in the documentation and/or other materials provided with the |
|
13 # distribution. |
|
14 # * Neither the name of Google Inc. nor the names of its |
|
15 # contributors may be used to endorse or promote products derived from |
|
16 # this software without specific prior written permission. |
|
17 # |
|
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
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. |
|
29 # |
|
30 # A tool for automating dealing with bugzilla, posting patches, committing patches, etc. |
|
31 |
|
32 import os |
|
33 import threading |
|
34 |
|
35 from webkitpy.common.checkout.api import Checkout |
|
36 from webkitpy.common.checkout.scm import detect_scm_system |
|
37 from webkitpy.common.net.bugzilla import Bugzilla |
|
38 from webkitpy.common.net.buildbot import BuildBot |
|
39 from webkitpy.common.net.rietveld import Rietveld |
|
40 from webkitpy.common.net.irc.ircproxy import IRCProxy |
|
41 from webkitpy.common.system.executive import Executive |
|
42 from webkitpy.common.system.user import User |
|
43 import webkitpy.tool.commands as commands |
|
44 # FIXME: Remove these imports once all the commands are in the root of the |
|
45 # command package. |
|
46 from webkitpy.tool.commands.download import * |
|
47 from webkitpy.tool.commands.earlywarningsystem import * |
|
48 from webkitpy.tool.commands.openbugs import OpenBugs |
|
49 from webkitpy.tool.commands.queries import * |
|
50 from webkitpy.tool.commands.queues import * |
|
51 from webkitpy.tool.commands.sheriffbot import * |
|
52 from webkitpy.tool.commands.upload import * |
|
53 from webkitpy.tool.multicommandtool import MultiCommandTool |
|
54 from webkitpy.common.system.deprecated_logging import log |
|
55 |
|
56 |
|
57 class WebKitPatch(MultiCommandTool): |
|
58 global_options = [ |
|
59 make_option("-v", "--verbose", action="store_true", dest="verbose", default=False, help="enable all logging"), |
|
60 make_option("--dry-run", action="store_true", dest="dry_run", default=False, help="do not touch remote servers"), |
|
61 make_option("--status-host", action="store", dest="status_host", type="string", nargs=1, help="Hostname (e.g. localhost or commit.webkit.org) where status updates should be posted."), |
|
62 make_option("--irc-password", action="store", dest="irc_password", type="string", nargs=1, help="Password to use when communicating via IRC."), |
|
63 ] |
|
64 |
|
65 def __init__(self, path): |
|
66 MultiCommandTool.__init__(self) |
|
67 |
|
68 self._path = path |
|
69 self.wakeup_event = threading.Event() |
|
70 self.bugs = Bugzilla() |
|
71 self.buildbot = BuildBot() |
|
72 self.executive = Executive() |
|
73 self._irc = None |
|
74 self.user = User() |
|
75 self._scm = None |
|
76 self._checkout = None |
|
77 self.status_server = StatusServer() |
|
78 self.codereview = Rietveld(self.executive) |
|
79 |
|
80 def scm(self): |
|
81 # Lazily initialize SCM to not error-out before command line parsing (or when running non-scm commands). |
|
82 original_cwd = os.path.abspath(".") |
|
83 if not self._scm: |
|
84 self._scm = detect_scm_system(original_cwd) |
|
85 |
|
86 if not self._scm: |
|
87 script_directory = os.path.abspath(sys.path[0]) |
|
88 self._scm = detect_scm_system(script_directory) |
|
89 if self._scm: |
|
90 log("The current directory (%s) is not a WebKit checkout, using %s" % (original_cwd, self._scm.checkout_root)) |
|
91 else: |
|
92 error("FATAL: Failed to determine the SCM system for either %s or %s" % (original_cwd, script_directory)) |
|
93 |
|
94 return self._scm |
|
95 |
|
96 def checkout(self): |
|
97 if not self._checkout: |
|
98 self._checkout = Checkout(self.scm()) |
|
99 return self._checkout |
|
100 |
|
101 def ensure_irc_connected(self, irc_delegate): |
|
102 if not self._irc: |
|
103 self._irc = IRCProxy(irc_delegate) |
|
104 |
|
105 def irc(self): |
|
106 # We don't automatically construct IRCProxy here because constructing |
|
107 # IRCProxy actually connects to IRC. We want clients to explicitly |
|
108 # connect to IRC. |
|
109 return self._irc |
|
110 |
|
111 def path(self): |
|
112 return self._path |
|
113 |
|
114 def command_completed(self): |
|
115 if self._irc: |
|
116 self._irc.disconnect() |
|
117 |
|
118 def should_show_in_main_help(self, command): |
|
119 if not command.show_in_main_help: |
|
120 return False |
|
121 if command.requires_local_commits: |
|
122 return self.scm().supports_local_commits() |
|
123 return True |
|
124 |
|
125 # FIXME: This may be unnecessary since we pass global options to all commands during execute() as well. |
|
126 def handle_global_options(self, options): |
|
127 self._options = options |
|
128 if options.dry_run: |
|
129 self.scm().dryrun = True |
|
130 self.bugs.dryrun = True |
|
131 self.codereview.dryrun = True |
|
132 if options.status_host: |
|
133 self.status_server.set_host(options.status_host) |
|
134 if options.irc_password: |
|
135 self.irc_password = options.irc_password |
|
136 |
|
137 def should_execute_command(self, command): |
|
138 if command.requires_local_commits and not self.scm().supports_local_commits(): |
|
139 failure_reason = "%s requires local commits using %s in %s." % (command.name, self.scm().display_name(), self.scm().checkout_root) |
|
140 return (False, failure_reason) |
|
141 return (True, None) |