2 # Copyright (c) 2009, Google Inc. All rights reserved.
3 # Copyright (c) 2009 Apple Inc. All rights reserved.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
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
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.
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.
31 # A tool for automating dealing with bugzilla, posting patches, committing patches, etc.
35 from modules.commands.download import *
36 from modules.commands.queries import *
37 from modules.commands.queues import *
38 from modules.commands.upload import *
39 from modules.logging import log
41 class BugzillaTool(MultiCommandTool):
43 # HACK: Set self.cached_scm before calling MultiCommandTool.__init__ because
44 # MultiCommandTool._commands_usage() will call self.should_show_command_help which uses scm().
45 # This hack can be removed by overriding usage() printing in HelpPrintingOptionParser
46 # so that we don't need to create 'epilog' before constructing HelpPrintingOptionParser.
47 self.cached_scm = None
48 MultiCommandTool.__init__(self)
49 self.global_option_parser.add_option("--dry-run", action="callback", help="do not touch remote servers", callback=self.dry_run_callback)
51 self.bugs = Bugzilla()
52 self.buildbot = BuildBot()
54 def dry_run_callback(self, option, opt, value, parser):
55 self.scm().dryrun = True
56 self.bugs.dryrun = True
59 # Lazily initialize SCM to not error-out before command line parsing (or when running non-scm commands).
60 original_cwd = os.path.abspath(".")
61 if not self.cached_scm:
62 self.cached_scm = detect_scm_system(original_cwd)
64 if not self.cached_scm:
65 script_directory = os.path.abspath(sys.path[0])
66 webkit_directory = os.path.abspath(os.path.join(script_directory, "../.."))
67 self.cached_scm = detect_scm_system(webkit_directory)
69 log("The current directory (%s) is not a WebKit checkout, using %s" % (original_cwd, webkit_directory))
71 error("FATAL: Failed to determine the SCM system for either %s or %s" % (original_cwd, webkit_directory))
73 return self.cached_scm
75 def should_show_command_help(self, command):
76 if command.requires_local_commits:
77 return self.scm().supports_local_commits()
80 def should_execute_command(self, command):
81 if command.requires_local_commits and not self.scm().supports_local_commits():
82 failure_reason = "%s requires local commits using %s in %s." % (command.name, self.scm().display_name(), self.scm().checkout_root)
83 return (False, failure_reason)
87 if __name__ == "__main__":