changeset 2683:58660fc20599

Add a runtime test for pyxmpp version (detect api incompatibility)
author Karol Nowak <grzywacz@sul.uni.lodz.pl>
date Thu, 16 Aug 2007 01:26:58 +0200
parents b0a44fc4d87d
children f9bf8c57c8e3
files jabberbot/bot.py
diffstat 1 files changed, 24 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/jabberbot/bot.py	Wed Aug 15 22:09:52 2007 +0200
+++ b/jabberbot/bot.py	Thu Aug 16 01:26:58 2007 +0200
@@ -16,9 +16,32 @@
 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 relay 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 revision 665 to run this bot. Exiting...'
+        sys.exit(1)
+
 def main():
+    """Starts the jabber bot"""
+
+    _check_xmpp_version()
+
     args = sys.argv
-
     if "--help" in args:
         print """MoinMoin notification bot