Пример #1
0
 def test_basic(self):
     queue = ThreadedMessageQueue()
     delegate = TestDelegate()
     pump = MessagePump(delegate, queue)
     self.assertEqual(delegate.log, [
         'schedule'
     ])
     delegate.callback()
     queue.post("Hello")
     queue.post("There")
     delegate.callback()
     self.assertEqual(delegate.log, [
         'schedule',
         'schedule',
         'message_available: Hello',
         'message_available: There',
         'schedule'
     ])
     queue.post("More")
     queue.post("Messages")
     queue.stop()
     delegate.callback()
     self.assertEqual(delegate.log, [
         'schedule',
         'schedule',
         'message_available: Hello',
         'message_available: There',
         'schedule',
         'message_available: More',
         'message_available: Messages',
         'final_message_delivered'
     ])
Пример #2
0
class IRCProxy(object):
    def __init__(self, irc_delegate, irc_bot=IRCBot):
        _log.info("Connecting to IRC")
        self._message_queue = ThreadedMessageQueue()
        self._child_thread = _IRCThread(self._message_queue, irc_delegate, irc_bot)
        self._child_thread.start()

    def post(self, message):
        self._message_queue.post(message)

    def disconnect(self):
        _log.info("Disconnecting from IRC...")
        self._message_queue.stop()
        self._child_thread.join()
Пример #3
0
class IRCProxy(object):
    def __init__(self, irc_delegate, irc_bot=IRCBot):
        _log.info("Connecting to IRC")
        self._message_queue = ThreadedMessageQueue()
        self._child_thread = _IRCThread(self._message_queue, irc_delegate,
                                        irc_bot)
        self._child_thread.start()

    def post(self, message):
        self._message_queue.post(message)

    def disconnect(self):
        _log.info("Disconnecting from IRC...")
        self._message_queue.stop()
        self._child_thread.join()
Пример #4
0
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 process_message(self, message):
        (nick, request) = message
        tokenized_request = request.strip().split(" ")
        if not tokenized_request:
            return
        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
        response = command().execute(nick, args, self._tool, self._sheriff)
        if response:
            self._tool.irc().post(response)

    def process_pending_messages(self):
        (messages, is_running) = self._message_queue.take_all()
        for message in messages:
            self.process_message(message)
Пример #5
0
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 process_message(self, message):
        (nick, request) = message
        tokenized_request = request.strip().split(" ")
        if not tokenized_request:
            return
        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
        response = command().execute(nick, args, self._tool, self._sheriff)
        if response:
            self._tool.irc().post(response)

    def process_pending_messages(self):
        (messages, is_running) = self._message_queue.take_all()
        for message in messages:
            self.process_message(message)
Пример #6
0
class SheriffIRCBot(object):
    # FIXME: Lame.  We should have an auto-registering CommandCenter.
    commands = {
        "last-green-revision": irc_command.LastGreenRevision,
        "restart": irc_command.Restart,
        "rollout": irc_command.Rollout,
        "hi": irc_command.Hi,
    }

    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 process_message(self, message):
        (nick, request) = message
        tokenized_request = request.strip().split(" ")
        if not tokenized_request:
            return
        command = self.commands.get(tokenized_request[0])
        if not command:
            self._tool.irc().post("%s: Available commands: %s" % (
                                  nick, ", ".join(self.commands.keys())))
            return
        response = command().execute(nick,
                                     tokenized_request[1:],
                                     self._tool,
                                     self._sheriff)
        if response:
            self._tool.irc().post(response)

    def process_pending_messages(self):
        (messages, is_running) = self._message_queue.take_all()
        for message in messages:
            self.process_message(message)
 def test_basic(self):
     queue = ThreadedMessageQueue()
     queue.post("Hello")
     queue.post("There")
     (messages, is_running) = queue.take_all()
     self.assertEqual(messages, ["Hello", "There"])
     self.assertTrue(is_running)
     (messages, is_running) = queue.take_all()
     self.assertEqual(messages, [])
     self.assertTrue(is_running)
     queue.post("More")
     queue.stop()
     queue.post("Messages")
     (messages, is_running) = queue.take_all()
     self.assertEqual(messages, ["More", "Messages"])
     self.assertFalse(is_running)
     (messages, is_running) = queue.take_all()
     self.assertEqual(messages, [])
     self.assertFalse(is_running)
 def test_basic(self):
     queue = ThreadedMessageQueue()
     queue.post("Hello")
     queue.post("There")
     (messages, is_running) = queue.take_all()
     self.assertEqual(messages, ["Hello", "There"])
     self.assertTrue(is_running)
     (messages, is_running) = queue.take_all()
     self.assertEqual(messages, [])
     self.assertTrue(is_running)
     queue.post("More")
     queue.stop()
     queue.post("Messages")
     (messages, is_running) = queue.take_all()
     self.assertEqual(messages, ["More", "Messages"])
     self.assertFalse(is_running)
     (messages, is_running) = queue.take_all()
     self.assertEqual(messages, [])
     self.assertFalse(is_running)
Пример #9
0
 def __init__(self, tool, sheriff):
     self._tool = tool
     self._sheriff = sheriff
     self._message_queue = ThreadedMessageQueue()
Пример #10
0
 def __init__(self, irc_delegate, irc_bot=IRCBot):
     _log.info("Connecting to IRC")
     self._message_queue = ThreadedMessageQueue()
     self._child_thread = _IRCThread(self._message_queue, irc_delegate,
                                     irc_bot)
     self._child_thread.start()
Пример #11
0
 def __init__(self, name, tool, agent, commands):
     self._name = name
     self._tool = tool
     self._agent = agent
     self._message_queue = ThreadedMessageQueue()
     self._commands = commands
Пример #12
0
 def __init__(self, tool, sheriff):
     self._tool = tool
     self._sheriff = sheriff
     self._message_queue = ThreadedMessageQueue()
Пример #13
0
 def __init__(self, irc_delegate, irc_bot=IRCBot):
     _log.info("Connecting to IRC")
     self._message_queue = ThreadedMessageQueue()
     self._child_thread = _IRCThread(self._message_queue, irc_delegate, irc_bot)
     self._child_thread.start()