Title: [124373] trunk/Tools
Revision
124373
Author
[email protected]
Date
2012-08-01 15:16:08 -0700 (Wed, 01 Aug 2012)

Log Message

Generalize SheriffIRCBot to prepare for PerfBot
https://bugs.webkit.org/show_bug.cgi?id=92912

Reviewed by Adam Barth.

Renamed SheriffIRCBot to IRCBot and generalized to support non-sheriffbot IRC bot in the future.
This will be useful when I add an experimental perf EWS IRC bot.

* Scripts/webkitpy/tool/bot/irc_command.py:
(Whois.execute):
* Scripts/webkitpy/tool/bot/irc_command_unittest.py:
(IRCCommandTest):
* Scripts/webkitpy/tool/bot/ircbot.py: Moved from Tools/Scripts/webkitpy/tool/bot/sheriffircbot.py.
(Eliza): Moved from irc_command.
(Eliza.__init__):
(Eliza.execute):
(IRCBot):
(IRCBot.__init__):
(IRCBot.irc_delegate):
(IRCBot._parse_command_and_args):
(IRCBot.process_message):
* Scripts/webkitpy/tool/bot/ircbot_unittest.py: Moved from Tools/Scripts/webkitpy/tool/bot/sheriffircbot_unittest.py.
(run):
(IRCBotTest):
(IRCBotTest.test_eliza): Moved from IRCCommandTest.
(IRCBotTest.test_parse_command_and_args):
(IRCBotTest.test_exception_during_command):
* Scripts/webkitpy/tool/bot/sheriffircbot.py: Removed.
* Scripts/webkitpy/tool/bot/sheriffircbot_unittest.py: Removed.
* Scripts/webkitpy/tool/commands/sheriffbot.py:
(SheriffBot.begin_work_queue):
* Scripts/webkitpy/webkitpy.pyproj:

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/Tools/ChangeLog (124372 => 124373)


--- trunk/Tools/ChangeLog	2012-08-01 22:12:23 UTC (rev 124372)
+++ trunk/Tools/ChangeLog	2012-08-01 22:16:08 UTC (rev 124373)
@@ -1,3 +1,38 @@
+2012-08-01  Ryosuke Niwa  <[email protected]>
+
+        Generalize SheriffIRCBot to prepare for PerfBot
+        https://bugs.webkit.org/show_bug.cgi?id=92912
+
+        Reviewed by Adam Barth.
+
+        Renamed SheriffIRCBot to IRCBot and generalized to support non-sheriffbot IRC bot in the future.
+        This will be useful when I add an experimental perf EWS IRC bot.
+
+        * Scripts/webkitpy/tool/bot/irc_command.py:
+        (Whois.execute):
+        * Scripts/webkitpy/tool/bot/irc_command_unittest.py:
+        (IRCCommandTest):
+        * Scripts/webkitpy/tool/bot/ircbot.py: Moved from Tools/Scripts/webkitpy/tool/bot/sheriffircbot.py.
+        (Eliza): Moved from irc_command.
+        (Eliza.__init__):
+        (Eliza.execute):
+        (IRCBot):
+        (IRCBot.__init__):
+        (IRCBot.irc_delegate):
+        (IRCBot._parse_command_and_args):
+        (IRCBot.process_message):
+        * Scripts/webkitpy/tool/bot/ircbot_unittest.py: Moved from Tools/Scripts/webkitpy/tool/bot/sheriffircbot_unittest.py.
+        (run):
+        (IRCBotTest):
+        (IRCBotTest.test_eliza): Moved from IRCCommandTest.
+        (IRCBotTest.test_parse_command_and_args):
+        (IRCBotTest.test_exception_during_command):
+        * Scripts/webkitpy/tool/bot/sheriffircbot.py: Removed.
+        * Scripts/webkitpy/tool/bot/sheriffircbot_unittest.py: Removed.
+        * Scripts/webkitpy/tool/commands/sheriffbot.py:
+        (SheriffBot.begin_work_queue):
+        * Scripts/webkitpy/webkitpy.pyproj:
+
 2012-08-01  Dirk Pranke  <[email protected]>
 
         nrwt: reenable the test for --verbose working in child processes

Modified: trunk/Tools/Scripts/webkitpy/tool/bot/irc_command.py (124372 => 124373)


--- trunk/Tools/Scripts/webkitpy/tool/bot/irc_command.py	2012-08-01 22:12:23 UTC (rev 124372)
+++ trunk/Tools/Scripts/webkitpy/tool/bot/irc_command.py	2012-08-01 22:16:08 UTC (rev 124373)
@@ -210,18 +210,6 @@
         return "%s: I'm not sure who you mean?  %s could be '%s'." % (nick, contributors_string, search_string)
 
 
-class Eliza(IRCCommand):
-    therapist = None
-
-    def __init__(self):
-        if not self.therapist:
-            import webkitpy.thirdparty.autoinstalled.eliza as eliza
-            Eliza.therapist = eliza.eliza()
-
-    def execute(self, nick, args, tool, sheriff):
-        return "%s: %s" % (nick, self.therapist.respond(" ".join(args)))
-
-
 class CreateBug(IRCCommand):
     def execute(self, nick, args, tool, sheriff):
         if not args:

Modified: trunk/Tools/Scripts/webkitpy/tool/bot/irc_command_unittest.py (124372 => 124373)


--- trunk/Tools/Scripts/webkitpy/tool/bot/irc_command_unittest.py	2012-08-01 22:12:23 UTC (rev 124372)
+++ trunk/Tools/Scripts/webkitpy/tool/bot/irc_command_unittest.py	2012-08-01 22:16:08 UTC (rev 124373)
@@ -35,11 +35,6 @@
 
 
 class IRCCommandTest(unittest.TestCase):
-    def test_eliza(self):
-        eliza = Eliza()
-        eliza.execute("tom", "hi", None, None)
-        eliza.execute("tom", "bye", None, None)
-
     def test_whois(self):
         whois = Whois()
         self.assertEquals("tom: Usage: whois SEARCH_STRING",

Copied: trunk/Tools/Scripts/webkitpy/tool/bot/ircbot.py (from rev 124338, trunk/Tools/Scripts/webkitpy/tool/bot/sheriffircbot.py) (0 => 124373)


--- trunk/Tools/Scripts/webkitpy/tool/bot/ircbot.py	                        (rev 0)
+++ trunk/Tools/Scripts/webkitpy/tool/bot/ircbot.py	2012-08-01 22:16:08 UTC (rev 124373)
@@ -0,0 +1,105 @@
+# Copyright (c) 2010 Google Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+#     * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#     * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+#     * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+from webkitpy.tool.bot.queueengine import TerminateQueue
+from webkitpy.tool.bot.irc_command import IRCCommand
+from webkitpy.common.net.irc.ircbot import IRCBotDelegate
+from webkitpy.common.thread.threadedmessagequeue import ThreadedMessageQueue
+
+
+class _IRCThreadTearoff(IRCBotDelegate):
+    def __init__(self, name, password, message_queue, wakeup_event):
+        self._name = name
+        self._password = password
+        self._message_queue = message_queue
+        self._wakeup_event = wakeup_event
+
+    # IRCBotDelegate methods
+
+    def irc_message_received(self, nick, message):
+        self._message_queue.post([nick, message])
+        self._wakeup_event.set()
+
+    def irc_nickname(self):
+        return self._name
+
+    def irc_password(self):
+        return self._password
+
+
+class Eliza(IRCCommand):
+    therapist = None
+
+    def __init__(self):
+        if not self.therapist:
+            import webkitpy.thirdparty.autoinstalled.eliza as eliza
+            Eliza.therapist = eliza.eliza()
+
+    def execute(self, nick, args, tool, sheriff):
+        return "%s: %s" % (nick, self.therapist.respond(" ".join(args)))
+
+
+class IRCBot(object):
+    def __init__(self, name, tool, agent, commands):
+        self._name = name
+        self._tool = tool
+        self._agent = agent
+        self._message_queue = ThreadedMessageQueue()
+        self._commands = commands
+
+    def irc_delegate(self):
+        return _IRCThreadTearoff(self._name, self._tool.irc_password,
+            self._message_queue, self._tool.wakeup_event)
+
+    def _parse_command_and_args(self, request):
+        tokenized_request = request.strip().split(" ")
+        command = self._commands.get(tokenized_request[0])
+        args = tokenized_request[1:]
+        if not command:
+            # Give the peoples someone to talk with.
+            command = Eliza
+            args = tokenized_request
+        return (command, args)
+
+    def process_message(self, requester_nick, request):
+        command, args = self._parse_command_and_args(request)
+        try:
+            response = command().execute(requester_nick, args, self._tool, self._agent)
+            if response:
+                self._tool.irc().post(response)
+        except TerminateQueue:
+            raise
+        # This will catch everything else. SystemExit and KeyboardInterrupt are not subclasses of Exception, so we won't catch those.
+        except Exception, e:
+            self._tool.irc().post("Exception executing command: %s" % e)
+
+    def process_pending_messages(self):
+        (messages, is_running) = self._message_queue.take_all()
+        for message in messages:
+            (nick, request) = message
+            self.process_message(nick, request)

Copied: trunk/Tools/Scripts/webkitpy/tool/bot/ircbot_unittest.py (from rev 124338, trunk/Tools/Scripts/webkitpy/tool/bot/sheriffircbot_unittest.py) (0 => 124373)


--- trunk/Tools/Scripts/webkitpy/tool/bot/ircbot_unittest.py	                        (rev 0)
+++ trunk/Tools/Scripts/webkitpy/tool/bot/ircbot_unittest.py	2012-08-01 22:16:08 UTC (rev 124373)
@@ -0,0 +1,163 @@
+# Copyright (c) 2010 Google Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+#     * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#     * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+#     * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+import unittest
+import random
+
+from webkitpy.common.system.outputcapture import OutputCapture
+from webkitpy.tool.bot import irc_command
+from webkitpy.tool.bot.queueengine import TerminateQueue
+from webkitpy.tool.bot.sheriff import Sheriff
+from webkitpy.tool.bot.ircbot import IRCBot
+from webkitpy.tool.bot.ircbot import Eliza
+from webkitpy.tool.bot.sheriff_unittest import MockSheriffBot
+from webkitpy.tool.mocktool import MockTool
+
+
+def run(message):
+    tool = MockTool()
+    tool.ensure_irc_connected(None)
+    bot = IRCBot("sheriffbot", tool, Sheriff(tool, MockSheriffBot()), irc_command.commands)
+    bot._message_queue.post(["mock_nick", message])
+    bot.process_pending_messages()
+
+
+class IRCBotTest(unittest.TestCase):
+    def test_eliza(self):
+        eliza = Eliza()
+        eliza.execute("tom", "hi", None, None)
+        eliza.execute("tom", "bye", None, None)
+
+    def test_parse_command_and_args(self):
+        tool = MockTool()
+        bot = IRCBot("sheriffbot", tool, Sheriff(tool, MockSheriffBot()), irc_command.commands)
+        self.assertEqual(bot._parse_command_and_args(""), (Eliza, [""]))
+        self.assertEqual(bot._parse_command_and_args("   "), (Eliza, [""]))
+        self.assertEqual(bot._parse_command_and_args(" hi "), (irc_command.Hi, []))
+        self.assertEqual(bot._parse_command_and_args(" hi there "), (irc_command.Hi, ["there"]))
+
+    def test_exception_during_command(self):
+        tool = MockTool()
+        tool.ensure_irc_connected(None)
+        bot = IRCBot("sheriffbot", tool, Sheriff(tool, MockSheriffBot()), irc_command.commands)
+
+        class CommandWithException(object):
+            def execute(self, nick, args, tool, sheriff):
+                raise Exception("mock_exception")
+
+        bot._parse_command_and_args = lambda request: (CommandWithException, [])
+        expected_stderr = 'MOCK: irc.post: Exception executing command: mock_exception\n'
+        OutputCapture().assert_outputs(self, bot.process_message, args=["mock_nick", "ignored message"], expected_stderr=expected_stderr)
+
+        class CommandWithException(object):
+            def execute(self, nick, args, tool, sheriff):
+                raise KeyboardInterrupt()
+
+        bot._parse_command_and_args = lambda request: (CommandWithException, [])
+        # KeyboardInterrupt and SystemExit are not subclasses of Exception and thus correctly will not be caught.
+        OutputCapture().assert_outputs(self, bot.process_message, args=["mock_nick", "ignored message"], expected_exception=KeyboardInterrupt)
+
+    def test_hi(self):
+        random.seed(23324)
+        expected_stderr = 'MOCK: irc.post: "Only you can prevent forest fires." -- Smokey the Bear\n'
+        OutputCapture().assert_outputs(self, run, args=["hi"], expected_stderr=expected_stderr)
+
+    def test_help(self):
+        expected_stderr = "MOCK: irc.post: mock_nick: Available commands: create-bug, help, hi, restart, roll-chromium-deps, rollout, whois\n"
+        OutputCapture().assert_outputs(self, run, args=["help"], expected_stderr=expected_stderr)
+
+    def test_restart(self):
+        expected_stderr = "MOCK: irc.post: Restarting...\n"
+        OutputCapture().assert_outputs(self, run, args=["restart"], expected_stderr=expected_stderr, expected_exception=TerminateQueue)
+
+    def test_rollout(self):
+        expected_stderr = "MOCK: irc.post: mock_nick: Preparing rollout for http://trac.webkit.org/changeset/21654 ...\nMOCK: irc.post: mock_nick, abarth, darin, eseidel: Created rollout: http://example.com/36936\n"
+        OutputCapture().assert_outputs(self, run, args=["rollout 21654 This patch broke the world"], expected_stderr=expected_stderr)
+
+    def test_revert(self):
+        expected_stderr = "MOCK: irc.post: mock_nick: Preparing rollout for http://trac.webkit.org/changeset/21654 ...\nMOCK: irc.post: mock_nick, abarth, darin, eseidel: Created rollout: http://example.com/36936\n"
+        OutputCapture().assert_outputs(self, run, args=["revert 21654 This patch broke the world"], expected_stderr=expected_stderr)
+
+    def test_roll_chromium_deps(self):
+        expected_stderr = "MOCK: irc.post: mock_nick: Rolling Chromium DEPS to r21654\nMOCK: irc.post: mock_nick: Created DEPS roll: http://example.com/36936\n"
+        OutputCapture().assert_outputs(self, run, args=["roll-chromium-deps 21654"], expected_stderr=expected_stderr)
+
+    def test_roll_chromium_deps_to_lkgr(self):
+        expected_stderr = "MOCK: irc.post: mock_nick: Rolling Chromium DEPS to last-known good revision\nMOCK: irc.post: mock_nick: Created DEPS roll: http://example.com/36936\n"
+        OutputCapture().assert_outputs(self, run, args=["roll-chromium-deps"], expected_stderr=expected_stderr)
+
+    def test_multi_rollout(self):
+        expected_stderr = "MOCK: irc.post: mock_nick: Preparing rollout for http://trac.webkit.org/changeset/21654, http://trac.webkit.org/changeset/21655, and http://trac.webkit.org/changeset/21656 ...\nMOCK: irc.post: mock_nick, abarth, darin, eseidel: Created rollout: http://example.com/36936\n"
+        OutputCapture().assert_outputs(self, run, args=["rollout 21654 21655 21656 This 21654 patch broke the world"], expected_stderr=expected_stderr)
+
+    def test_rollout_with_r_in_svn_revision(self):
+        expected_stderr = "MOCK: irc.post: mock_nick: Preparing rollout for http://trac.webkit.org/changeset/21654 ...\nMOCK: irc.post: mock_nick, abarth, darin, eseidel: Created rollout: http://example.com/36936\n"
+        OutputCapture().assert_outputs(self, run, args=["rollout r21654 This patch broke the world"], expected_stderr=expected_stderr)
+
+    def test_multi_rollout_with_r_in_svn_revision(self):
+        expected_stderr = "MOCK: irc.post: mock_nick: Preparing rollout for http://trac.webkit.org/changeset/21654, http://trac.webkit.org/changeset/21655, and http://trac.webkit.org/changeset/21656 ...\nMOCK: irc.post: mock_nick, abarth, darin, eseidel: Created rollout: http://example.com/36936\n"
+        OutputCapture().assert_outputs(self, run, args=["rollout r21654 21655 r21656 This r21654 patch broke the world"], expected_stderr=expected_stderr)
+
+    def test_rollout_bananas(self):
+        expected_stderr = "MOCK: irc.post: mock_nick: Usage: rollout SVN_REVISION [SVN_REVISIONS] REASON\n"
+        OutputCapture().assert_outputs(self, run, args=["rollout bananas"], expected_stderr=expected_stderr)
+
+    def test_rollout_invalidate_revision(self):
+        # When folks pass junk arguments, we should just spit the usage back at them.
+        expected_stderr = "MOCK: irc.post: mock_nick: Usage: rollout SVN_REVISION [SVN_REVISIONS] REASON\n"
+        OutputCapture().assert_outputs(self, run,
+                                       args=["rollout --component=Tools 21654"],
+                                       expected_stderr=expected_stderr)
+
+    def test_rollout_invalidate_reason(self):
+        # FIXME: I'm slightly confused as to why this doesn't return the USAGE message.
+        expected_stderr = """MOCK: irc.post: mock_nick: Preparing rollout for http://trac.webkit.org/changeset/21654 ...
+MOCK: irc.post: mock_nick, abarth, darin, eseidel: Failed to create rollout patch:
+MOCK: irc.post: The rollout reason may not begin with - (\"-bad (Requested by mock_nick on #webkit).\").
+"""
+        OutputCapture().assert_outputs(self, run,
+                                       args=["rollout 21654 -bad"],
+                                       expected_stderr=expected_stderr)
+
+    def test_multi_rollout_invalidate_reason(self):
+        expected_stderr = """MOCK: irc.post: mock_nick: Preparing rollout for http://trac.webkit.org/changeset/21654, http://trac.webkit.org/changeset/21655, and http://trac.webkit.org/changeset/21656 ...
+MOCK: irc.post: mock_nick, abarth, darin, eseidel: Failed to create rollout patch:
+MOCK: irc.post: The rollout reason may not begin with - (\"-bad (Requested by mock_nick on #webkit).\").
+"""
+        OutputCapture().assert_outputs(self, run,
+                                       args=["rollout "
+                                             "21654 21655 r21656 -bad"],
+                                       expected_stderr=expected_stderr)
+
+    def test_rollout_no_reason(self):
+        expected_stderr = "MOCK: irc.post: mock_nick: Usage: rollout SVN_REVISION [SVN_REVISIONS] REASON\n"
+        OutputCapture().assert_outputs(self, run, args=["rollout 21654"], expected_stderr=expected_stderr)
+
+    def test_multi_rollout_no_reason(self):
+        expected_stderr = "MOCK: irc.post: mock_nick: Usage: rollout SVN_REVISION [SVN_REVISIONS] REASON\n"
+        OutputCapture().assert_outputs(self, run, args=["rollout 21654 21655 r21656"], expected_stderr=expected_stderr)

Deleted: trunk/Tools/Scripts/webkitpy/tool/bot/sheriffircbot.py (124372 => 124373)


--- trunk/Tools/Scripts/webkitpy/tool/bot/sheriffircbot.py	2012-08-01 22:12:23 UTC (rev 124372)
+++ trunk/Tools/Scripts/webkitpy/tool/bot/sheriffircbot.py	2012-08-01 22:16:08 UTC (rev 124373)
@@ -1,91 +0,0 @@
-# Copyright (c) 2010 Google Inc. All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are
-# met:
-#
-#     * Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-#     * Redistributions in binary form must reproduce the above
-# copyright notice, this list of conditions and the following disclaimer
-# in the documentation and/or other materials provided with the
-# distribution.
-#     * Neither the name of Google Inc. nor the names of its
-# contributors may be used to endorse or promote products derived from
-# this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-from webkitpy.tool.bot import irc_command
-from webkitpy.tool.bot.queueengine import TerminateQueue
-from webkitpy.common.net.irc.ircbot import IRCBotDelegate
-from webkitpy.common.thread.threadedmessagequeue import ThreadedMessageQueue
-
-
-class _IRCThreadTearoff(IRCBotDelegate):
-    def __init__(self, password, message_queue, wakeup_event):
-        self._password = password
-        self._message_queue = message_queue
-        self._wakeup_event = wakeup_event
-
-    # IRCBotDelegate methods
-
-    def irc_message_received(self, nick, message):
-        self._message_queue.post([nick, message])
-        self._wakeup_event.set()
-
-    def irc_nickname(self):
-        return "sheriffbot"
-
-    def irc_password(self):
-        return self._password
-
-
-class SheriffIRCBot(object):
-    def __init__(self, tool, sheriff):
-        self._tool = tool
-        self._sheriff = sheriff
-        self._message_queue = ThreadedMessageQueue()
-
-    def irc_delegate(self):
-        return _IRCThreadTearoff(self._tool.irc_password,
-                                 self._message_queue,
-                                 self._tool.wakeup_event)
-
-    def _parse_command_and_args(self, request):
-        tokenized_request = request.strip().split(" ")
-        command = irc_command.commands.get(tokenized_request[0])
-        args = tokenized_request[1:]
-        if not command:
-            # Give the peoples someone to talk with.
-            command = irc_command.Eliza
-            args = tokenized_request
-        return (command, args)
-
-    def process_message(self, requester_nick, request):
-        command, args = self._parse_command_and_args(request)
-        try:
-            response = command().execute(requester_nick, args, self._tool, self._sheriff)
-            if response:
-                self._tool.irc().post(response)
-        except TerminateQueue:
-            raise
-        # This will catch everything else. SystemExit and KeyboardInterrupt are not subclasses of Exception, so we won't catch those.
-        except Exception, e:
-            self._tool.irc().post("Exception executing command: %s" % e)
-
-    def process_pending_messages(self):
-        (messages, is_running) = self._message_queue.take_all()
-        for message in messages:
-            (nick, request) = message
-            self.process_message(nick, request)

Deleted: trunk/Tools/Scripts/webkitpy/tool/bot/sheriffircbot_unittest.py (124372 => 124373)


--- trunk/Tools/Scripts/webkitpy/tool/bot/sheriffircbot_unittest.py	2012-08-01 22:12:23 UTC (rev 124372)
+++ trunk/Tools/Scripts/webkitpy/tool/bot/sheriffircbot_unittest.py	2012-08-01 22:16:08 UTC (rev 124373)
@@ -1,157 +0,0 @@
-# Copyright (c) 2010 Google Inc. All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are
-# met:
-# 
-#     * Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-#     * Redistributions in binary form must reproduce the above
-# copyright notice, this list of conditions and the following disclaimer
-# in the documentation and/or other materials provided with the
-# distribution.
-#     * Neither the name of Google Inc. nor the names of its
-# contributors may be used to endorse or promote products derived from
-# this software without specific prior written permission.
-# 
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-import unittest
-import random
-
-from webkitpy.common.system.outputcapture import OutputCapture
-from webkitpy.tool.bot import irc_command
-from webkitpy.tool.bot.queueengine import TerminateQueue
-from webkitpy.tool.bot.sheriff import Sheriff
-from webkitpy.tool.bot.sheriffircbot import SheriffIRCBot
-from webkitpy.tool.bot.sheriff_unittest import MockSheriffBot
-from webkitpy.tool.mocktool import MockTool
-
-
-def run(message):
-    tool = MockTool()
-    tool.ensure_irc_connected(None)
-    bot = SheriffIRCBot(tool, Sheriff(tool, MockSheriffBot()))
-    bot._message_queue.post(["mock_nick", message])
-    bot.process_pending_messages()
-
-
-class SheriffIRCBotTest(unittest.TestCase):
-    def test_parse_command_and_args(self):
-        tool = MockTool()
-        bot = SheriffIRCBot(tool, Sheriff(tool, MockSheriffBot()))
-        self.assertEqual(bot._parse_command_and_args(""), (irc_command.Eliza, [""]))
-        self.assertEqual(bot._parse_command_and_args("   "), (irc_command.Eliza, [""]))
-        self.assertEqual(bot._parse_command_and_args(" hi "), (irc_command.Hi, []))
-        self.assertEqual(bot._parse_command_and_args(" hi there "), (irc_command.Hi, ["there"]))
-
-    def test_exception_during_command(self):
-        tool = MockTool()
-        tool.ensure_irc_connected(None)
-        bot = SheriffIRCBot(tool, Sheriff(tool, MockSheriffBot()))
-
-        class CommandWithException(object):
-            def execute(self, nick, args, tool, sheriff):
-                raise Exception("mock_exception")
-
-        bot._parse_command_and_args = lambda request: (CommandWithException, [])
-        expected_stderr = 'MOCK: irc.post: Exception executing command: mock_exception\n'
-        OutputCapture().assert_outputs(self, bot.process_message, args=["mock_nick", "ignored message"], expected_stderr=expected_stderr)
-
-        class CommandWithException(object):
-            def execute(self, nick, args, tool, sheriff):
-                raise KeyboardInterrupt()
-
-        bot._parse_command_and_args = lambda request: (CommandWithException, [])
-        # KeyboardInterrupt and SystemExit are not subclasses of Exception and thus correctly will not be caught.
-        OutputCapture().assert_outputs(self, bot.process_message, args=["mock_nick", "ignored message"], expected_exception=KeyboardInterrupt)
-
-    def test_hi(self):
-        random.seed(23324)
-        expected_stderr = 'MOCK: irc.post: "Only you can prevent forest fires." -- Smokey the Bear\n'
-        OutputCapture().assert_outputs(self, run, args=["hi"], expected_stderr=expected_stderr)
-
-    def test_help(self):
-        expected_stderr = "MOCK: irc.post: mock_nick: Available commands: create-bug, help, hi, restart, roll-chromium-deps, rollout, whois\n"
-        OutputCapture().assert_outputs(self, run, args=["help"], expected_stderr=expected_stderr)
-
-    def test_restart(self):
-        expected_stderr = "MOCK: irc.post: Restarting...\n"
-        OutputCapture().assert_outputs(self, run, args=["restart"], expected_stderr=expected_stderr, expected_exception=TerminateQueue)
-
-    def test_rollout(self):
-        expected_stderr = "MOCK: irc.post: mock_nick: Preparing rollout for http://trac.webkit.org/changeset/21654 ...\nMOCK: irc.post: mock_nick, abarth, darin, eseidel: Created rollout: http://example.com/36936\n"
-        OutputCapture().assert_outputs(self, run, args=["rollout 21654 This patch broke the world"], expected_stderr=expected_stderr)
-
-    def test_revert(self):
-        expected_stderr = "MOCK: irc.post: mock_nick: Preparing rollout for http://trac.webkit.org/changeset/21654 ...\nMOCK: irc.post: mock_nick, abarth, darin, eseidel: Created rollout: http://example.com/36936\n"
-        OutputCapture().assert_outputs(self, run, args=["revert 21654 This patch broke the world"], expected_stderr=expected_stderr)
-
-    def test_roll_chromium_deps(self):
-        expected_stderr = "MOCK: irc.post: mock_nick: Rolling Chromium DEPS to r21654\nMOCK: irc.post: mock_nick: Created DEPS roll: http://example.com/36936\n"
-        OutputCapture().assert_outputs(self, run, args=["roll-chromium-deps 21654"], expected_stderr=expected_stderr)
-
-    def test_roll_chromium_deps_to_lkgr(self):
-        expected_stderr = "MOCK: irc.post: mock_nick: Rolling Chromium DEPS to last-known good revision\nMOCK: irc.post: mock_nick: Created DEPS roll: http://example.com/36936\n"
-        OutputCapture().assert_outputs(self, run, args=["roll-chromium-deps"], expected_stderr=expected_stderr)
-
-    def test_multi_rollout(self):
-        expected_stderr = "MOCK: irc.post: mock_nick: Preparing rollout for http://trac.webkit.org/changeset/21654, http://trac.webkit.org/changeset/21655, and http://trac.webkit.org/changeset/21656 ...\nMOCK: irc.post: mock_nick, abarth, darin, eseidel: Created rollout: http://example.com/36936\n"
-        OutputCapture().assert_outputs(self, run, args=["rollout 21654 21655 21656 This 21654 patch broke the world"], expected_stderr=expected_stderr)
-
-    def test_rollout_with_r_in_svn_revision(self):
-        expected_stderr = "MOCK: irc.post: mock_nick: Preparing rollout for http://trac.webkit.org/changeset/21654 ...\nMOCK: irc.post: mock_nick, abarth, darin, eseidel: Created rollout: http://example.com/36936\n"
-        OutputCapture().assert_outputs(self, run, args=["rollout r21654 This patch broke the world"], expected_stderr=expected_stderr)
-
-    def test_multi_rollout_with_r_in_svn_revision(self):
-        expected_stderr = "MOCK: irc.post: mock_nick: Preparing rollout for http://trac.webkit.org/changeset/21654, http://trac.webkit.org/changeset/21655, and http://trac.webkit.org/changeset/21656 ...\nMOCK: irc.post: mock_nick, abarth, darin, eseidel: Created rollout: http://example.com/36936\n"
-        OutputCapture().assert_outputs(self, run, args=["rollout r21654 21655 r21656 This r21654 patch broke the world"], expected_stderr=expected_stderr)
-
-    def test_rollout_bananas(self):
-        expected_stderr = "MOCK: irc.post: mock_nick: Usage: rollout SVN_REVISION [SVN_REVISIONS] REASON\n"
-        OutputCapture().assert_outputs(self, run, args=["rollout bananas"], expected_stderr=expected_stderr)
-
-    def test_rollout_invalidate_revision(self):
-        # When folks pass junk arguments, we should just spit the usage back at them.
-        expected_stderr = "MOCK: irc.post: mock_nick: Usage: rollout SVN_REVISION [SVN_REVISIONS] REASON\n"
-        OutputCapture().assert_outputs(self, run,
-                                       args=["rollout --component=Tools 21654"],
-                                       expected_stderr=expected_stderr)
-
-    def test_rollout_invalidate_reason(self):
-        # FIXME: I'm slightly confused as to why this doesn't return the USAGE message.
-        expected_stderr = """MOCK: irc.post: mock_nick: Preparing rollout for http://trac.webkit.org/changeset/21654 ...
-MOCK: irc.post: mock_nick, abarth, darin, eseidel: Failed to create rollout patch:
-MOCK: irc.post: The rollout reason may not begin with - (\"-bad (Requested by mock_nick on #webkit).\").
-"""
-        OutputCapture().assert_outputs(self, run,
-                                       args=["rollout 21654 -bad"],
-                                       expected_stderr=expected_stderr)
-
-    def test_multi_rollout_invalidate_reason(self):
-        expected_stderr = """MOCK: irc.post: mock_nick: Preparing rollout for http://trac.webkit.org/changeset/21654, http://trac.webkit.org/changeset/21655, and http://trac.webkit.org/changeset/21656 ...
-MOCK: irc.post: mock_nick, abarth, darin, eseidel: Failed to create rollout patch:
-MOCK: irc.post: The rollout reason may not begin with - (\"-bad (Requested by mock_nick on #webkit).\").
-"""
-        OutputCapture().assert_outputs(self, run,
-                                       args=["rollout "
-                                             "21654 21655 r21656 -bad"],
-                                       expected_stderr=expected_stderr)
-
-    def test_rollout_no_reason(self):
-        expected_stderr = "MOCK: irc.post: mock_nick: Usage: rollout SVN_REVISION [SVN_REVISIONS] REASON\n"
-        OutputCapture().assert_outputs(self, run, args=["rollout 21654"], expected_stderr=expected_stderr)
-
-    def test_multi_rollout_no_reason(self):
-        expected_stderr = "MOCK: irc.post: mock_nick: Usage: rollout SVN_REVISION [SVN_REVISIONS] REASON\n"
-        OutputCapture().assert_outputs(self, run, args=["rollout 21654 21655 r21656"], expected_stderr=expected_stderr)

Modified: trunk/Tools/Scripts/webkitpy/tool/commands/sheriffbot.py (124372 => 124373)


--- trunk/Tools/Scripts/webkitpy/tool/commands/sheriffbot.py	2012-08-01 22:12:23 UTC (rev 124372)
+++ trunk/Tools/Scripts/webkitpy/tool/commands/sheriffbot.py	2012-08-01 22:16:08 UTC (rev 124373)
@@ -28,7 +28,8 @@
 
 from webkitpy.common.system.deprecated_logging import log
 from webkitpy.tool.bot.sheriff import Sheriff
-from webkitpy.tool.bot.sheriffircbot import SheriffIRCBot
+from webkitpy.tool.bot.irc_command import commands as irc_commands
+from webkitpy.tool.bot.ircbot import IRCBot
 from webkitpy.tool.commands.queues import AbstractQueue
 from webkitpy.tool.commands.stepsequence import StepSequenceErrorHandler
 
@@ -45,7 +46,7 @@
     def begin_work_queue(self):
         AbstractQueue.begin_work_queue(self)
         self._sheriff = Sheriff(self._tool, self)
-        self._irc_bot = SheriffIRCBot(self._tool, self._sheriff)
+        self._irc_bot = IRCBot("sheriffbot", self._tool, self._sheriff, irc_commands)
         self._tool.ensure_irc_connected(self._irc_bot.irc_delegate())
 
     def work_item_log_path(self, failure_map):

Modified: trunk/Tools/Scripts/webkitpy/webkitpy.pyproj (124372 => 124373)


--- trunk/Tools/Scripts/webkitpy/webkitpy.pyproj	2012-08-01 22:12:23 UTC (rev 124372)
+++ trunk/Tools/Scripts/webkitpy/webkitpy.pyproj	2012-08-01 22:16:08 UTC (rev 124373)
@@ -378,14 +378,14 @@
     <Compile Include="tool\bot\flakytestreporter_unittest.py" />
     <Compile Include="tool\bot\irc_command.py" />
     <Compile Include="tool\bot\irc_command_unittest.py" />
+    <Compile Include="tool\bot\ircbot.py" />
+    <Compile Include="tool\bot\ircbot_unittest.py" />
     <Compile Include="tool\bot\layouttestresultsreader.py" />
     <Compile Include="tool\bot\layouttestresultsreader_unittest.py" />
     <Compile Include="tool\bot\patchanalysistask.py" />
     <Compile Include="tool\bot\queueengine.py" />
     <Compile Include="tool\bot\queueengine_unittest.py" />
     <Compile Include="tool\bot\sheriff.py" />
-    <Compile Include="tool\bot\sheriffircbot.py" />
-    <Compile Include="tool\bot\sheriffircbot_unittest.py" />
     <Compile Include="tool\bot\sheriff_unittest.py" />
     <Compile Include="tool\bot\stylequeuetask.py" />
     <Compile Include="tool\bot\__init__.py" />
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to