comparison start_bots_from_xml_config.py @ 155:63db565438bd

fixed the halt command Signed-off-by: Charly COSTE <changaco@changaco.net>
author Charly COSTE <changaco@changaco.net>
date Sun, 17 Jan 2010 23:24:00 +0100
parents e0eea72ea493
children c021656e4c54
comparison
equal deleted inserted replaced
154:25f6778b8841 155:63db565438bd
56 bot = Bot(bot_el.getAttribute('jid'), bot_el.getAttribute('password'), bot_el.getAttribute('nickname'), admins_jid=admins_jid, debug=debug) 56 bot = Bot(bot_el.getAttribute('jid'), bot_el.getAttribute('password'), bot_el.getAttribute('nickname'), admins_jid=admins_jid, debug=debug)
57 bots.append(bot) 57 bots.append(bot)
58 for bridge_el in bot_el.getElementsByTagName('bridge'): 58 for bridge_el in bot_el.getElementsByTagName('bridge'):
59 xmpp_room = bridge_el.getElementsByTagName('xmpp-room')[0] 59 xmpp_room = bridge_el.getElementsByTagName('xmpp-room')[0]
60 irc = bridge_el.getElementsByTagName('irc')[0] 60 irc = bridge_el.getElementsByTagName('irc')[0]
61
61 irc_connection_interval = 1 62 irc_connection_interval = 1
62 if irc.hasAttribute('connection_interval'): 63 if irc.hasAttribute('connection_interval'):
63 try: 64 try:
64 irc_connection_interval = float(irc.getAttribute('connection_interval')) 65 irc_connection_interval = float(irc.getAttribute('connection_interval'))
65 except ValueError: 66 except ValueError:
66 print '[Error] the value of connection_interval must be a number' 67 print '[Error] the value of connection_interval must be a number'
67 say_level = 'all' 68
68 if bridge_el.hasAttribute('say_level'): 69 if bridge_el.hasAttribute('say_level'):
69 say_level = bridge_el.getAttribute('say_level') 70 say_level = bridge_el.getAttribute('say_level')
71 else:
72 say_level = 'all'
73
70 if bridge_el.hasAttribute('mode'): 74 if bridge_el.hasAttribute('mode'):
71 mode = bridge_el.getAttribute('mode') 75 mode = bridge_el.getAttribute('mode')
72 else: 76 else:
73 mode = 'normal' 77 mode = 'normal'
78
74 bot.new_bridge(xmpp_room.getAttribute('jid'), irc.getAttribute('chan'), irc.getAttribute('server'), mode, say_level, irc_connection_interval=irc_connection_interval) 79 bot.new_bridge(xmpp_room.getAttribute('jid'), irc.getAttribute('chan'), irc.getAttribute('server'), mode, say_level, irc_connection_interval=irc_connection_interval)
75 80
76 81
82 if len(bots) == 0:
83 print 'No bots in the configuration file, exiting ...'
84 exit(0)
85
77 while True: 86 while True:
78 sleep(1) 87 for bot in bots:
88 if len(bot.xmpp_connections) == 0:
89 bots.remove(bot)
90 if len(bots) == 0:
91 raise Exception()
92 sleep(10)
79 except: 93 except:
94 if len(bots) == 0:
95 print 'All bots have been shut down, exiting ...'
96 exit(0)
97
80 for bot in bots: 98 for bot in bots:
99 bots.remove(bot)
81 del bot 100 del bot
82 traceback.print_exc() 101 traceback.print_exc()
83 quit(3) 102 quit(3)