Exemple #1
0
def main():
    """Starts the jabber bot"""

    _check_xmpp_version()

    args = sys.argv
    if "--help" in args:
        print """MoinMoin notification bot

        Usage: %(myname)s [--server server] [--xmpp_port port] [--user user] [--resource resource] [--password pass] [--xmlrpc_host host] [--xmlrpc_port port]
        """ % {"myname": os.path.basename(args[0])}

        raise SystemExit

    log = logging.getLogger(__name__)
    log.setLevel(logging.DEBUG)
    log.addHandler(logging.StreamHandler())

    init_i18n(BotConfig)

    # TODO: actually accept options from the help string
    commands_from_xmpp = Queue()
    commands_to_xmpp = Queue()

    xmpp_bot = None
    xmlrpc_client = None
    xmlrpc_server = None

    while True:
        try:
            if not xmpp_bot or not xmpp_bot.isAlive():
                log.info("(Re)starting XMPP thread...")
                xmpp_bot = XMPPBot(BotConfig, commands_from_xmpp, commands_to_xmpp)
                xmpp_bot.setDaemon(True)
                xmpp_bot.start()

            if not xmlrpc_client or not xmlrpc_client.isAlive():
                log.info("(Re)starting XMLRPC client thread...")
                xmlrpc_client = XMLRPCClient(BotConfig, commands_from_xmpp, commands_to_xmpp)
                xmlrpc_client.setDaemon(True)
                xmlrpc_client.start()

            if not xmlrpc_server or not xmlrpc_server.isAlive():
                log.info("(Re)starting XMLRPC server thread...")
                xmlrpc_server = XMLRPCServer(BotConfig, commands_to_xmpp)
                xmlrpc_server.setDaemon(True)
                xmlrpc_server.start()

            time.sleep(5)

        except KeyboardInterrupt, i:
            xmpp_bot.stop()
            xmlrpc_client.stop()

            log.info("Stopping XMPP bot thread, please wait...")
            xmpp_bot.join(5)
            log.info("Stopping XMLRPC client thread, please wait...")
            xmlrpc_client.join(5)

            sys.exit(0)
Exemple #2
0
def main():
    """Starts the jabber bot"""

    _check_xmpp_version()

    args = sys.argv
    if "--help" in args:
        print """MoinMoin notification bot

        Usage: %(myname)s [--server server] [--xmpp_port port] [--user user] [--resource resource] [--password pass] [--xmlrpc_host host] [--xmlrpc_port port]
        """ % {"myname": os.path.basename(args[0])}

        raise SystemExit

    log = logging.getLogger(__name__)
    log.setLevel(logging.DEBUG)
    log.addHandler(logging.StreamHandler())

    init_i18n(BotConfig)

    # TODO: actually accept options from the help string
    commands_from_xmpp = Queue()
    commands_to_xmpp = Queue()

    xmpp_bot = None
    xmlrpc_client = None
    xmlrpc_server = None

    while True:
        try:
            if not xmpp_bot or not xmpp_bot.isAlive():
                log.info("(Re)starting XMPP thread...")
                xmpp_bot = XMPPBot(BotConfig, commands_from_xmpp, commands_to_xmpp)
                xmpp_bot.setDaemon(True)
                xmpp_bot.start()

            if not xmlrpc_client or not xmlrpc_client.isAlive():
                log.info("(Re)starting XMLRPC client thread...")
                xmlrpc_client = XMLRPCClient(BotConfig, commands_from_xmpp, commands_to_xmpp)
                xmlrpc_client.setDaemon(True)
                xmlrpc_client.start()

            if not xmlrpc_server or not xmlrpc_server.isAlive():
                log.info("(Re)starting XMLRPC server thread...")
                xmlrpc_server = XMLRPCServer(BotConfig, commands_to_xmpp)
                xmlrpc_server.setDaemon(True)
                xmlrpc_server.start()

            time.sleep(5)

        except KeyboardInterrupt, i:
            xmpp_bot.stop()
            xmlrpc_client.stop()

            log.info("Stopping XMPP bot thread, please wait...")
            xmpp_bot.join(5)
            log.info("Stopping XMLRPC client thread, please wait...")
            xmlrpc_client.join(5)

            sys.exit(0)
Exemple #3
0
 def setup_class(self):
     self.from_xmlrpc = Queue()
     self.to_xmlrpc = Queue()
     self.bot = XMPPBot(BotConfig, self.from_xmlrpc, self.to_xmlrpc)
Exemple #4
0
class TestXMPPBotCommands:
    """Various tests for the XMPP bot receiving commands from Wiki"""
    def setup_class(self):
        self.from_xmlrpc = Queue()
        self.to_xmlrpc = Queue()
        self.bot = XMPPBot(BotConfig, self.from_xmlrpc, self.to_xmlrpc)

    def setup_method(self, method):
        self.called = False
        self.bot.send_message = self.dummy_method
        self.bot.ask_for_subscription = self.dummy_method
        self.bot.remove_subscription = self.dummy_method

    def dummy_method(self, *args, **kwargs):
        self.called = True

    def testNotificationCommand(self):
        """Check if send_message is triggered for tested commands"""

        data = {
            'text': 'Some notification',
            'subject': 'It is optional',
            'url_list': []
        }
        cmds = []
        cmds.append(
            commands.NotificationCommand(["*****@*****.**"], data, True))
        cmds.append(
            commands.NotificationCommandI18n(["*****@*****.**"], data, True))
        cmds.append(commands.GetPage("*****@*****.**", "TestPage"))
        cmds.append(commands.GetPageHTML("*****@*****.**", "TestPage"))

        tmp_cmd = commands.GetPageList("*****@*****.**")
        tmp_cmd.data = ""
        cmds.append(tmp_cmd)

        tmp_cmd = commands.GetPageInfo("*****@*****.**", "TestPage")
        tmp_cmd.data = {
            'author': 'dude',
            'lastModified': '200708060T34350',
            'version': 42
        }
        cmds.append(tmp_cmd)

        for cmd in cmds:
            self.called = False
            self.bot.handle_command(cmd)
            if not self.called:
                print "The bot should send a notification when %s arrives!" % (
                    cmd.__class__.__name__, )
                raise Exception()

    def testRosterCommands(self):
        """Test if appropriate functions are called for (Add|Remove)JIDFromRosterCommand"""

        command = commands.AddJIDToRosterCommand("*****@*****.**")
        self.bot.handle_command(command)

        if not self.called:
            print "The bot should do something when AddJIDToRosterCommand arrives!"
            raise Exception()

        self.called = False
        command = commands.RemoveJIDFromRosterCommand("*****@*****.**")
        self.bot.handle_command(command)

        if not self.called:
            print "The bot should do something when RemoveJIDFromRosterCommand arrives!"
            raise Exception()

    def testInternalHelp(self):
        """Check if there's help for every known command"""

        commands = self.bot.internal_commands + self.bot.xmlrpc_commands.values(
        )
        for cmd in commands:
            print "There should be help on %s command!" % (cmd, )
            assert self.bot.help_on("*****@*****.**", cmd)
 def setup_class(self):
     self.from_xmlrpc = Queue()
     self.to_xmlrpc = Queue()
     self.bot = XMPPBot(BotConfig, self.from_xmlrpc, self.to_xmlrpc)
class TestXMPPBotCommands:
    """Various tests for the XMPP bot receiving commands from Wiki"""

    def setup_class(self):
        self.from_xmlrpc = Queue()
        self.to_xmlrpc = Queue()
        self.bot = XMPPBot(BotConfig, self.from_xmlrpc, self.to_xmlrpc)

    def setup_method(self, method):
        self.called = False
        self.bot.send_message = self.dummy_method
        self.bot.ask_for_subscription = self.dummy_method
        self.bot.remove_subscription = self.dummy_method

    def dummy_method(self, *args, **kwargs):
        self.called = True

    def testNotificationCommand(self):
        """Check if send_message is triggered for tested commands"""

        data = {'text': 'Some notification', 'subject': 'It is optional', 'url_list': []}
        cmds = []
        cmds.append(commands.NotificationCommand(["*****@*****.**"], data, True))
        cmds.append(commands.NotificationCommandI18n(["*****@*****.**"], data, True))
        cmds.append(commands.GetPage("*****@*****.**", "TestPage"))
        cmds.append(commands.GetPageHTML("*****@*****.**", "TestPage"))

        tmp_cmd = commands.GetPageList("*****@*****.**")
        tmp_cmd.data = ""
        cmds.append(tmp_cmd)

        tmp_cmd = commands.GetPageInfo("*****@*****.**", "TestPage")
        tmp_cmd.data = {'author': 'dude', 'lastModified': '200708060T34350', 'version': 42}
        cmds.append(tmp_cmd)

        for cmd in cmds:
            self.called = False
            self.bot.handle_command(cmd)
            if not self.called:
                print "The bot should send a notification when %s arrives!" % (cmd.__class__.__name__, )
                raise Exception()

    def testRosterCommands(self):
        """Test if appropriate functions are called for (Add|Remove)JIDFromRosterCommand"""

        command = commands.AddJIDToRosterCommand("*****@*****.**")
        self.bot.handle_command(command)

        if not self.called:
            print "The bot should do something when AddJIDToRosterCommand arrives!"
            raise Exception()

        self.called = False
        command = commands.RemoveJIDFromRosterCommand("*****@*****.**")
        self.bot.handle_command(command)

        if not self.called:
            print "The bot should do something when RemoveJIDFromRosterCommand arrives!"
            raise Exception()

    def testInternalHelp(self):
        """Check if there's help for every known command"""

        commands = self.bot.internal_commands + self.bot.xmlrpc_commands.values()
        for cmd in commands:
            print "There should be help on %s command!" % (cmd, )
            assert self.bot.help_on("*****@*****.**", cmd)