comparison start_bots_from_xml_config.py @ 0:4c842d23d4ce

Initial commit, version 0.1 Signed-off-by: Charly COSTE <changaco@changaco.net>
author Charly COSTE <changaco@changaco.net>
date Sun, 16 Aug 2009 01:47:03 +0200
parents
children a9077fa9cac9
comparison
equal deleted inserted replaced
-1:000000000000 0:4c842d23d4ce
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4
5 # *** LICENSE ***
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19
20 from bot import bot
21 from time import sleep
22 from xml.dom.minidom import parse
23
24
25 bots = []
26
27 try:
28 config = parse('config.xml')
29 except IOError:
30 print 'Error: config.xml is missing or cannot be read'
31 quit(1)
32
33 bots_jids = []
34 for bot_el in config.getElementsByTagName('bot'):
35 if bot_el.getAttribute('jid') in bots_jids:
36 print 'Error: you cannot have two bots using the same JID'
37 quit(2)
38 bots_jids.append(bot_el.getAttribute('jid'))
39 for bot_el in config.getElementsByTagName('bot'):
40 debug = False
41 if bot_el.hasAttribute('debug'):
42 if bot_el.getAttribute('debug') == 'true':
43 debug = True
44 bot_ = bot(bot_el.getAttribute('jid'), bot_el.getAttribute('password'), bot_el.getAttribute('nickname'), debug=debug)
45 bots.append(bot_)
46 for bridge_el in bot_el.getElementsByTagName('bridge'):
47 xmpp_room = bridge_el.getElementsByTagName('xmpp-room')[0]
48 irc = bridge_el.getElementsByTagName('irc')[0]
49 bridge_ = bot_.new_bridge(xmpp_room.getAttribute('jid'), irc.getAttribute('chan'), irc.getAttribute('server'))
50
51
52 try:
53 while True:
54 sleep(1)
55 except:
56 del bots
57 quit(3)