Back to index

moin  1.9.0~rc2
Functions
jabberbot.bot Namespace Reference

Functions

def _check_xmpp_version
def main

Function Documentation

Checks if available version of pyxmpp is recent enough

Since __revision__ is broken in current trunk, we can't rely on it.
Therefore a simple check for known problems is used to determine if
we can start the bot with it.

Definition at line 19 of file bot.py.

00019 
00020 def _check_xmpp_version():
00021     """Checks if available version of pyxmpp is recent enough
00022 
00023     Since __revision__ is broken in current trunk, we can't rely on it.
00024     Therefore a simple check for known problems is used to determine if
00025     we can start the bot with it.
00026 
00027     """
00028     import pyxmpp
00029 
00030     msg = pyxmpp.message.Message()
00031     form = pyxmpp.jabber.dataforms.Form()
00032 
00033     try:
00034         msg.add_content(form)
00035     except TypeError:
00036         print 'Your version of pyxmpp is too old!'
00037         print 'You need a least revision 665 to run this bot. Exiting...'
00038         sys.exit(1)

Here is the caller graph for this function:

Starts the jabber bot

Definition at line 39 of file bot.py.

00039 
00040 def main():
00041     """Starts the jabber bot"""
00042 
00043     _check_xmpp_version()
00044 
00045     args = sys.argv
00046     if "--help" in args:
00047         print """MoinMoin notification bot
00048 
00049         Usage: %(myname)s [--server server] [--xmpp_port port] [--user user] [--resource resource] [--password pass] [--xmlrpc_host host] [--xmlrpc_port port]
00050         """ % {"myname": os.path.basename(args[0])}
00051 
00052         raise SystemExit
00053 
00054     log = logging.getLogger(__name__)
00055     log.setLevel(logging.DEBUG)
00056     log.addHandler(logging.StreamHandler())
00057 
00058     init_i18n(BotConfig)
00059 
00060     # TODO: actually accept options from the help string
00061     commands_from_xmpp = Queue()
00062     commands_to_xmpp = Queue()
00063 
00064     xmpp_bot = None
00065     xmlrpc_client = None
00066     xmlrpc_server = None
00067 
00068     while True:
00069         try:
00070             if not xmpp_bot or not xmpp_bot.isAlive():
00071                 log.info("(Re)starting XMPP thread...")
00072                 xmpp_bot = XMPPBot(BotConfig, commands_from_xmpp, commands_to_xmpp)
00073                 xmpp_bot.setDaemon(True)
00074                 xmpp_bot.start()
00075 
00076             if not xmlrpc_client or not xmlrpc_client.isAlive():
00077                 log.info("(Re)starting XMLRPC client thread...")
00078                 xmlrpc_client = XMLRPCClient(BotConfig, commands_from_xmpp, commands_to_xmpp)
00079                 xmlrpc_client.setDaemon(True)
00080                 xmlrpc_client.start()
00081 
00082             if not xmlrpc_server or not xmlrpc_server.isAlive():
00083                 log.info("(Re)starting XMLRPC server thread...")
00084                 xmlrpc_server = XMLRPCServer(BotConfig, commands_to_xmpp)
00085                 xmlrpc_server.setDaemon(True)
00086                 xmlrpc_server.start()
00087 
00088             time.sleep(5)
00089 
00090         except KeyboardInterrupt, i:
00091             xmpp_bot.stop()
00092             xmlrpc_client.stop()
00093 
00094             log.info("Stopping XMPP bot thread, please wait...")
00095             xmpp_bot.join(5)
00096             log.info("Stopping XMLRPC client thread, please wait...")
00097             xmlrpc_client.join(5)
00098 
00099             sys.exit(0)
00100 

Here is the call graph for this function:

Here is the caller graph for this function: