Changeset 56658 in webkit
- Timestamp:
- Mar 26, 2010 10:44:59 PM (14 years ago)
- Location:
- trunk/WebKitTools
- Files:
-
- 10 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebKitTools/ChangeLog
r56657 r56658 1 2010-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 1 25 2010-03-26 Adam Barth <abarth@webkit.org> 2 26 -
trunk/WebKitTools/Scripts/webkitpy/tool/bot/irc_command.py
r56657 r56658 27 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 28 29 from webkitpy.common.net.irc.ircbot import IRCBotDelegate 29 # FIXME: Merge with Command? 30 class IRCCommand(object): 31 def execute(self, args, tool): 32 raise NotImplementedError, "subclasses must implement" 30 33 31 class SheriffIRCBot(IRCBotDelegate):32 def __init__(self, password):33 self._password = password34 34 35 # IRCBotDelegate methods 35 class LastGreenRevision(IRCCommand): 36 def execute(self, args, tool): 37 return tool.buildbot.last_green_revision() 36 38 37 def irc_message_received(self, message): 39 40 class Hi(IRCCommand): 41 def execute(self, args, tool): 38 42 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 66 66 67 67 class QueueEngine: 68 def __init__(self, name, delegate, message_queue=None):68 def __init__(self, name, delegate, wakeup_event): 69 69 self._name = name 70 70 self._delegate = delegate 71 self._ message_queue = message_queue71 self._wakeup_event = wakeup_event 72 72 self._output_tee = OutputTee() 73 73 … … 140 140 def _sleep(self, message): 141 141 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 30 30 import shutil 31 31 import tempfile 32 import threading 32 33 import unittest 33 34 … … 111 112 class FastQueueEngine(QueueEngine): 112 113 def __init__(self, delegate): 113 QueueEngine.__init__(self, "fast-queue", delegate )114 QueueEngine.__init__(self, "fast-queue", delegate, threading.Event()) 114 115 115 116 # No sleep for the wicked. … … 123 124 def test_trivial(self): 124 125 delegate = LoggingDelegate(self) 125 work_queue = QueueEngine("trivial-queue", delegate )126 work_queue = QueueEngine("trivial-queue", delegate, threading.Event()) 126 127 work_queue.run() 127 128 self.assertEquals(delegate._callbacks, LoggingDelegate.expected_callbacks) … … 131 132 def test_unexpected_error(self): 132 133 delegate = ThrowErrorDelegate(self, 3) 133 work_queue = QueueEngine("error-queue", delegate )134 work_queue = QueueEngine("error-queue", delegate, threading.Event()) 134 135 work_queue.run() 135 136 expected_callbacks = LoggingDelegate.expected_callbacks[:] … … 142 143 def test_handled_error(self): 143 144 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()) 145 146 work_queue.run() 146 147 self.assertEquals(delegate._callbacks, LoggingDelegate.expected_callbacks) -
trunk/WebKitTools/Scripts/webkitpy/tool/bot/sheriffircbot.py
r56642 r56658 27 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 28 29 import webkitpy.tool.bot.irc_command as irc_command 30 29 31 from webkitpy.common.net.irc.ircbot import IRCBotDelegate 32 from webkitpy.common.thread.threadedmessagequeue import ThreadedMessageQueue 30 33 31 class SheriffIRCBot(IRCBotDelegate): 32 def __init__(self, password): 34 35 class _IRCThreadTearoff(object): 36 def __init__(self, password, message_queue, wakeup_event): 33 37 self._password = password 38 self._message_queue = message_queue 39 self._wakeup_event = wakeup_event 34 40 35 41 # IRCBotDelegate methods 36 42 37 43 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() 39 46 40 47 def irc_nickname(self): … … 43 50 def irc_password(self): 44 51 return self._password 52 53 54 class 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 4 4 # modification, are permitted provided that the following conditions are 5 5 # met: 6 # 6 # 7 7 # * Redistributions of source code must retain the above copyright 8 8 # notice, this list of conditions and the following disclaimer. … … 14 14 # contributors may be used to endorse or promote products derived from 15 15 # this software without specific prior written permission. 16 # 16 # 17 17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT … … 27 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 28 29 from webkitpy.common.net.irc.ircbot import IRCBotDelegate 29 import unittest 30 30 31 class SheriffIRCBot(IRCBotDelegate): 32 def __init__(self, password): 33 self._password = password 31 from webkitpy.common.system.outputcapture import OutputCapture 32 from webkitpy.tool.bot.sheriffircbot import SheriffIRCBot 33 from webkitpy.tool.mocktool import MockTool 34 34 35 # IRCBotDelegate methods 35 def 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() 36 41 37 def irc_message_received(self, message):38 return '"Only you can prevent forest fires." -- Smokey the Bear'39 42 40 def irc_nickname(self): 41 return "sheriffbot" 43 class 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) 42 47 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 113 113 self.options = options 114 114 self.tool = tool 115 return engine(self.name, self ).run()115 return engine(self.name, self, self.tool.wakeup_event).run() 116 116 117 117 @classmethod -
trunk/WebKitTools/Scripts/webkitpy/tool/commands/queuestest.py
r56519 r56658 36 36 37 37 class MockQueueEngine(object): 38 def __init__(self, name, queue ):38 def __init__(self, name, queue, wakeup_event): 39 39 pass 40 40 -
trunk/WebKitTools/Scripts/webkitpy/tool/commands/sheriffbot.py
r56642 r56658 44 44 def begin_work_queue(self): 45 45 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()) 48 48 49 49 def work_item_log_path(self, failure_info): -
trunk/WebKitTools/Scripts/webkitpy/tool/main.py
r56642 r56658 31 31 32 32 import os 33 import threading 33 34 34 35 from webkitpy.common.checkout.api import Checkout … … 61 62 62 63 self._path = path 64 self.wakeup_event = threading.Event() 63 65 self.bugs = Bugzilla() 64 66 self.buildbot = BuildBot() -
trunk/WebKitTools/Scripts/webkitpy/tool/mocktool.py
r56642 r56658 28 28 29 29 import os 30 import threading 30 31 31 32 from webkitpy.common.config.committers import CommitterList, Reviewer … … 311 312 return [] 312 313 314 def last_green_revision(self): 315 return 9479 316 313 317 def light_tree_on_fire(self): 314 318 self._tree_is_on_fire = True … … 318 322 "29837": [mock_builder] 319 323 } 324 320 325 321 326 class MockSCM(Mock): … … 438 443 439 444 def __init__(self): 445 self.wakeup_event = threading.Event() 440 446 self.bugs = MockBugzilla() 441 447 self.buildbot = MockBuildBot() -
trunk/WebKitTools/Scripts/webkitpy/tool/unittests.py
r56522 r56658 27 27 from webkitpy.tool.bot.patchcollection_unittest import * 28 28 from webkitpy.tool.bot.queueengine_unittest import * 29 from webkitpy.tool.bot.sheriffircbot_unittest import * 29 30 from webkitpy.tool.commands.download_unittest import * 30 31 from webkitpy.tool.commands.earlywarningsystem_unittest import *
Note: See TracChangeset
for help on using the changeset viewer.