1 #!/usr/bin/env python 2 # Copyright (c) 2009, Google Inc. All rights reserved. 3 # Copyright (c) 2009 Apple Inc. All rights reserved. 4 # 5 # Redistribution and use in source and binary forms, with or without 6 # modification, are permitted provided that the following conditions are 7 # met: 8 # 9 # * Redistributions of source code must retain the above copyright 10 # notice, this list of conditions and the following disclaimer. 11 # * Redistributions in binary form must reproduce the above 12 # copyright notice, this list of conditions and the following disclaimer 13 # in the documentation and/or other materials provided with the 14 # distribution. 15 # * Neither the name of Google Inc. nor the names of its 16 # contributors may be used to endorse or promote products derived from 17 # this software without specific prior written permission. 18 # 19 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 # 31 # A tool for automating dealing with bugzilla, posting patches, committing patches, etc. 32 33 import os 34 35 from webkitpy.bugzilla import Bugzilla 36 from webkitpy.buildbot import BuildBot 37 from webkitpy.commands.download import * 38 from webkitpy.commands.early_warning_system import * 39 from webkitpy.commands.openbugs import OpenBugs 40 from webkitpy.commands.queries import * 41 from webkitpy.commands.queues import * 42 from webkitpy.commands.upload import * 43 from webkitpy.executive import Executive 44 from webkitpy.webkit_logging import log 45 from webkitpy.multicommandtool import MultiCommandTool 46 from webkitpy.scm import detect_scm_system 47 from webkitpy.user import User 48 49 50 class WebKitPatch(MultiCommandTool): 51 global_options = [ 52 make_option("--dry-run", action="store_true", dest="dry_run", default=False, help="do not touch remote servers"), 53 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."), 54 ] 55 56 def __init__(self): 57 MultiCommandTool.__init__(self) 58 59 self.bugs = Bugzilla() 60 self.buildbot = BuildBot() 61 self.executive = Executive() 62 self.user = User() 63 self._scm = None 64 self.status_server = StatusServer() 65 66 def scm(self): 67 # Lazily initialize SCM to not error-out before command line parsing (or when running non-scm commands). 68 original_cwd = os.path.abspath(".") 69 if not self._scm: 70 self._scm = detect_scm_system(original_cwd) 71 72 if not self._scm: 73 script_directory = os.path.abspath(sys.path[0]) 74 webkit_directory = os.path.abspath(os.path.join(script_directory, "../..")) 75 self._scm = detect_scm_system(webkit_directory) 76 if self._scm: 77 log("The current directory (%s) is not a WebKit checkout, using %s" % (original_cwd, webkit_directory)) 78 else: 79 error("FATAL: Failed to determine the SCM system for either %s or %s" % (original_cwd, webkit_directory)) 80 81 return self._scm 82 83 def path(self): 84 return __file__ 85 86 def should_show_in_main_help(self, command): 87 if not command.show_in_main_help: 88 return False 89 if command.requires_local_commits: 90 return self.scm().supports_local_commits() 91 return True 92 93 # FIXME: This may be unnecessary since we pass global options to all commands during execute() as well. 94 def handle_global_options(self, options): 95 if options.dry_run: 96 self.scm().dryrun = True 97 self.bugs.dryrun = True 98 if options.status_host: 99 self.status_server.set_host(options.status_host) 100 101 def should_execute_command(self, command): 102 if command.requires_local_commits and not self.scm().supports_local_commits(): 103 failure_reason = "%s requires local commits using %s in %s." % (command.name, self.scm().display_name(), self.scm().checkout_root) 104 return (False, failure_reason) 105 return (True, None) 106 107 108 if __name__ == "__main__": 109 WebKitPatch().main() 110