Changeset 56658 in webkit


Ignore:
Timestamp:
Mar 26, 2010 10:44:59 PM (14 years ago)
Author:
abarth@webkit.org
Message:

2010-03-26 Adam Barth <abarth@webkit.org>

Reviewed by Eric Seidel.

Add some basic IRC commands to sheriffbot
https://bugs.webkit.org/show_bug.cgi?id=36684

Adds support for sheriffbot to respond to a "hi" command and a
"last-green-revision" command. It's lame that we're rebuilding
MultiCommandTool, but as discussed in person we'll intergrate the two
once we see what the requirements are.

  • Scripts/webkitpy/tool/bot/irc_command.py: Added.
  • Scripts/webkitpy/tool/bot/queueengine.py:
  • Scripts/webkitpy/tool/bot/queueengine_unittest.py:
  • Scripts/webkitpy/tool/bot/sheriffircbot.py:
  • Scripts/webkitpy/tool/bot/sheriffircbot_unittest.py: Added.
  • Scripts/webkitpy/tool/commands/queues.py:
  • Scripts/webkitpy/tool/commands/queuestest.py:
  • Scripts/webkitpy/tool/commands/sheriffbot.py:
  • Scripts/webkitpy/tool/main.py:
  • Scripts/webkitpy/tool/mocktool.py:
  • Scripts/webkitpy/tool/unittests.py:
Location:
trunk/WebKitTools
Files:
10 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/WebKitTools/ChangeLog

    r56657 r56658  
     12010-03-26  Adam Barth  <abarth@webkit.org>
     2
     3        Reviewed by Eric Seidel.
     4
     5        Add some basic IRC commands to sheriffbot
     6        https://bugs.webkit.org/show_bug.cgi?id=36684
     7
     8        Adds support for sheriffbot to respond to a "hi" command and a
     9        "last-green-revision" command.  It's lame that we're rebuilding
     10        MultiCommandTool, but as discussed in person we'll intergrate the two
     11        once we see what the requirements are.
     12
     13        * Scripts/webkitpy/tool/bot/irc_command.py: Added.
     14        * Scripts/webkitpy/tool/bot/queueengine.py:
     15        * Scripts/webkitpy/tool/bot/queueengine_unittest.py:
     16        * Scripts/webkitpy/tool/bot/sheriffircbot.py:
     17        * Scripts/webkitpy/tool/bot/sheriffircbot_unittest.py: Added.
     18        * Scripts/webkitpy/tool/commands/queues.py:
     19        * Scripts/webkitpy/tool/commands/queuestest.py:
     20        * Scripts/webkitpy/tool/commands/sheriffbot.py:
     21        * Scripts/webkitpy/tool/main.py:
     22        * Scripts/webkitpy/tool/mocktool.py:
     23        * Scripts/webkitpy/tool/unittests.py:
     24
    1252010-03-26  Adam Barth  <abarth@webkit.org>
    226
  • trunk/WebKitTools/Scripts/webkitpy/tool/bot/irc_command.py

    r56657 r56658  
    2727# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2828
    29 from webkitpy.common.net.irc.ircbot import IRCBotDelegate
     29# FIXME: Merge with Command?
     30class IRCCommand(object):
     31    def execute(self, args, tool):
     32        raise NotImplementedError, "subclasses must implement"
    3033
    31 class SheriffIRCBot(IRCBotDelegate):
    32     def __init__(self, password):
    33         self._password = password
    3434
    35     # IRCBotDelegate methods
     35class LastGreenRevision(IRCCommand):
     36    def execute(self, args, tool):
     37        return tool.buildbot.last_green_revision()
    3638
    37     def irc_message_received(self, message):
     39
     40class Hi(IRCCommand):
     41    def execute(self, args, tool):
    3842        return '"Only you can prevent forest fires." -- Smokey the Bear'
    39 
    40     def irc_nickname(self):
    41         return "sheriffbot"
    42 
    43     def irc_password(self):
    44         return self._password
  • trunk/WebKitTools/Scripts/webkitpy/tool/bot/queueengine.py

    r56654 r56658  
    6666
    6767class QueueEngine:
    68     def __init__(self, name, delegate, message_queue=None):
     68    def __init__(self, name, delegate, wakeup_event):
    6969        self._name = name
    7070        self._delegate = delegate
    71         self._message_queue = message_queue
     71        self._wakeup_event = wakeup_event
    7272        self._output_tee = OutputTee()
    7373
     
    140140    def _sleep(self, message):
    141141        log(self._sleep_message(message))
    142         if self._message_queue:
    143             self._message_queue.wait(self.seconds_to_sleep)
    144         else:
    145             time.sleep(self.seconds_to_sleep)
     142        if self._wakeup_event.wait(self.seconds_to_sleep):
     143            self._wakeup_event.clear()
  • trunk/WebKitTools/Scripts/webkitpy/tool/bot/queueengine_unittest.py

    r56586 r56658  
    3030import shutil
    3131import tempfile
     32import threading
    3233import unittest
    3334
     
    111112class FastQueueEngine(QueueEngine):
    112113    def __init__(self, delegate):
    113         QueueEngine.__init__(self, "fast-queue", delegate)
     114        QueueEngine.__init__(self, "fast-queue", delegate, threading.Event())
    114115
    115116    # No sleep for the wicked.
     
    123124    def test_trivial(self):
    124125        delegate = LoggingDelegate(self)
    125         work_queue = QueueEngine("trivial-queue", delegate)
     126        work_queue = QueueEngine("trivial-queue", delegate, threading.Event())
    126127        work_queue.run()
    127128        self.assertEquals(delegate._callbacks, LoggingDelegate.expected_callbacks)
     
    131132    def test_unexpected_error(self):
    132133        delegate = ThrowErrorDelegate(self, 3)
    133         work_queue = QueueEngine("error-queue", delegate)
     134        work_queue = QueueEngine("error-queue", delegate, threading.Event())
    134135        work_queue.run()
    135136        expected_callbacks = LoggingDelegate.expected_callbacks[:]
     
    142143    def test_handled_error(self):
    143144        delegate = ThrowErrorDelegate(self, QueueEngine.handled_error_code)
    144         work_queue = QueueEngine("handled-error-queue", delegate)
     145        work_queue = QueueEngine("handled-error-queue", delegate, threading.Event())
    145146        work_queue.run()
    146147        self.assertEquals(delegate._callbacks, LoggingDelegate.expected_callbacks)
  • trunk/WebKitTools/Scripts/webkitpy/tool/bot/sheriffircbot.py

    r56642 r56658  
    2727# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2828
     29import webkitpy.tool.bot.irc_command as irc_command
     30
    2931from webkitpy.common.net.irc.ircbot import IRCBotDelegate
     32from webkitpy.common.thread.threadedmessagequeue import ThreadedMessageQueue
    3033
    31 class SheriffIRCBot(IRCBotDelegate):
    32     def __init__(self, password):
     34
     35class _IRCThreadTearoff(object):
     36    def __init__(self, password, message_queue, wakeup_event):
    3337        self._password = password
     38        self._message_queue = message_queue
     39        self._wakeup_event = wakeup_event
    3440
    3541    # IRCBotDelegate methods
    3642
    3743    def irc_message_received(self, message):
    38         return '"Only you can prevent forest fires." -- Smokey the Bear'
     44        self._message_queue.post(message)
     45        self._wakeup_event.set()
    3946
    4047    def irc_nickname(self):
     
    4350    def irc_password(self):
    4451        return self._password
     52
     53
     54class SheriffIRCBot(IRCBotDelegate):
     55    # FIXME: Lame.  We should have an auto-registering CommandCenter.
     56    commands = {
     57        "last-green-revision": irc_command.LastGreenRevision,
     58        "hi": irc_command.Hi,
     59    }
     60
     61    def __init__(self, tool):
     62        self._tool = tool
     63        self._message_queue = ThreadedMessageQueue()
     64
     65    def irc_delegate(self):
     66        return _IRCThreadTearoff(self._tool.irc_password, self._message_queue, self._tool.wakeup_event)
     67
     68    def process_message(self, message):
     69        tokenized_message = message.strip().split(" ")
     70        if not tokenized_message:
     71            return
     72        command = self.commands.get(tokenized_message[0])
     73        if not command:
     74            self._tool.irc().post("Available commands: %s" % ", ".join(self.commands.keys()))
     75            return
     76        response = command().execute(tokenized_message[1:], self._tool)
     77        if response:
     78            self._tool.irc().post(response)
     79
     80    def process_pending_messages(self):
     81        (messages, is_running) = self._message_queue.take_all()
     82        for message in messages:
     83            self.process_message(message)
  • trunk/WebKitTools/Scripts/webkitpy/tool/bot/sheriffircbot_unittest.py

    r56657 r56658  
    44# modification, are permitted provided that the following conditions are
    55# met:
    6 #
     6# 
    77#     * Redistributions of source code must retain the above copyright
    88# notice, this list of conditions and the following disclaimer.
     
    1414# contributors may be used to endorse or promote products derived from
    1515# this software without specific prior written permission.
    16 #
     16# 
    1717# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    1818# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     
    2727# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2828
    29 from webkitpy.common.net.irc.ircbot import IRCBotDelegate
     29import unittest
    3030
    31 class SheriffIRCBot(IRCBotDelegate):
    32     def __init__(self, password):
    33         self._password = password
     31from webkitpy.common.system.outputcapture import OutputCapture
     32from webkitpy.tool.bot.sheriffircbot import SheriffIRCBot
     33from webkitpy.tool.mocktool import MockTool
    3434
    35     # IRCBotDelegate methods
     35def run(message):
     36    tool = MockTool()
     37    tool.ensure_irc_connected(None)
     38    bot = SheriffIRCBot(tool)
     39    bot._message_queue.post(message)
     40    bot.process_pending_messages()
    3641
    37     def irc_message_received(self, message):
    38         return '"Only you can prevent forest fires." -- Smokey the Bear'
    3942
    40     def irc_nickname(self):
    41         return "sheriffbot"
     43class SheriffIRCBotTest(unittest.TestCase):
     44    def test_hi(self):
     45        expected_stderr = 'MOCK: irc.post: "Only you can prevent forest fires." -- Smokey the Bear\n'
     46        OutputCapture().assert_outputs(self, run, args=["hi"], expected_stderr=expected_stderr)
    4247
    43     def irc_password(self):
    44         return self._password
     48    def test_bogus(self):
     49        expected_stderr = "MOCK: irc.post: Available commands: hi, last-green-revision\n"
     50        OutputCapture().assert_outputs(self, run, args=["bogus"], expected_stderr=expected_stderr)
     51
     52    def test_lgr(self):
     53        expected_stderr = "MOCK: irc.post: 9479\n"
     54        OutputCapture().assert_outputs(self, run, args=["last-green-revision"], expected_stderr=expected_stderr)
  • trunk/WebKitTools/Scripts/webkitpy/tool/commands/queues.py

    r56586 r56658  
    113113        self.options = options
    114114        self.tool = tool
    115         return engine(self.name, self).run()
     115        return engine(self.name, self, self.tool.wakeup_event).run()
    116116
    117117    @classmethod
  • trunk/WebKitTools/Scripts/webkitpy/tool/commands/queuestest.py

    r56519 r56658  
    3636
    3737class MockQueueEngine(object):
    38     def __init__(self, name, queue):
     38    def __init__(self, name, queue, wakeup_event):
    3939        pass
    4040
  • trunk/WebKitTools/Scripts/webkitpy/tool/commands/sheriffbot.py

    r56642 r56658  
    4444    def begin_work_queue(self):
    4545        AbstractQueue.begin_work_queue(self)
    46         self._irc_delegate = SheriffIRCBot(self.tool.irc_password)
    47         self.tool.ensure_irc_connected(self._irc_delegate)
     46        self._irc_bot = SheriffIRCBot(self.tool)
     47        self.tool.ensure_irc_connected(self._irc_bot.irc_delegate())
    4848
    4949    def work_item_log_path(self, failure_info):
  • trunk/WebKitTools/Scripts/webkitpy/tool/main.py

    r56642 r56658  
    3131
    3232import os
     33import threading
    3334
    3435from webkitpy.common.checkout.api import Checkout
     
    6162
    6263        self._path = path
     64        self.wakeup_event = threading.Event()
    6365        self.bugs = Bugzilla()
    6466        self.buildbot = BuildBot()
  • trunk/WebKitTools/Scripts/webkitpy/tool/mocktool.py

    r56642 r56658  
    2828
    2929import os
     30import threading
    3031
    3132from webkitpy.common.config.committers import CommitterList, Reviewer
     
    311312        return []
    312313
     314    def last_green_revision(self):
     315        return 9479
     316
    313317    def light_tree_on_fire(self):
    314318        self._tree_is_on_fire = True
     
    318322            "29837": [mock_builder]
    319323        }
     324
    320325
    321326class MockSCM(Mock):
     
    438443
    439444    def __init__(self):
     445        self.wakeup_event = threading.Event()
    440446        self.bugs = MockBugzilla()
    441447        self.buildbot = MockBuildBot()
  • trunk/WebKitTools/Scripts/webkitpy/tool/unittests.py

    r56522 r56658  
    2727from webkitpy.tool.bot.patchcollection_unittest import *
    2828from webkitpy.tool.bot.queueengine_unittest import *
     29from webkitpy.tool.bot.sheriffircbot_unittest import *
    2930from webkitpy.tool.commands.download_unittest import *
    3031from webkitpy.tool.commands.earlywarningsystem_unittest import *
Note: See TracChangeset for help on using the changeset viewer.