/usr/share/pyshared/jabberbot/bot.py is in python-moinmoin 1.9.3-1ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | #!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
"""
MoinMoin - jabber bot main file
@copyright: 2007 by Karol Nowak <grywacz@gmail.com>
@license: GNU GPL, see COPYING for details.
"""
import logging, os, sys, time
from Queue import Queue
from jabberbot.config import BotConfig
from jabberbot.i18n import init_i18n
from jabberbot.xmppbot import XMPPBot
from jabberbot.xmlrpcbot import XMLRPCServer, XMLRPCClient
def _check_xmpp_version():
"""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.
"""
import pyxmpp
msg = pyxmpp.message.Message()
form = pyxmpp.jabber.dataforms.Form()
try:
msg.add_content(form)
except TypeError:
print 'Your version of pyxmpp is too old!'
print 'You need a least pyxmpp SVN revision 665 to run this bot.'
print 'pyxmpp release 1.0.1 works, too.'
print 'Exiting...'
sys.exit(1)
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)
if __name__ == "__main__":
main()
|