annotate start_bots_from_xml_config.py @ 139:38eb220142a1

fixed minimal→*limited mode changing Signed-off-by: Charly COSTE <changaco@changaco.net>
author Charly COSTE <changaco@changaco.net>
date Sat, 16 Jan 2010 22:59:42 +0100
parents 99f3dee1fad7
children e0eea72ea493
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1 #!/usr/bin/env python
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
3
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
4
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
5 # *** LICENSE ***
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
6 # This program is free software: you can redistribute it and/or modify
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
7 # it under the terms of the GNU General Public License as published by
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
8 # the Free Software Foundation, either version 3 of the License, or
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
9 # (at your option) any later version.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
10 #
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
11 # This program is distributed in the hope that it will be useful,
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
14 # GNU General Public License for more details.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
15 #
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
16 # You should have received a copy of the GNU General Public License
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
18
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
19
124
99f3dee1fad7 code cleaning
Charly COSTE <changaco@changaco.net>
parents: 86
diff changeset
20 from xml.dom.minidom import parse
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
21 from time import sleep
13
a9077fa9cac9 Added optional parameter to start_bots_from_xml_config.py
Charly COSTE <changaco@changaco.net>
parents: 0
diff changeset
22 import sys
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 13
diff changeset
23 import traceback
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
24
124
99f3dee1fad7 code cleaning
Charly COSTE <changaco@changaco.net>
parents: 86
diff changeset
25 from bot import Bot
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
26
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
27
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
28 try:
13
a9077fa9cac9 Added optional parameter to start_bots_from_xml_config.py
Charly COSTE <changaco@changaco.net>
parents: 0
diff changeset
29 if len(sys.argv) > 1:
a9077fa9cac9 Added optional parameter to start_bots_from_xml_config.py
Charly COSTE <changaco@changaco.net>
parents: 0
diff changeset
30 config = parse(sys.argv[1])
a9077fa9cac9 Added optional parameter to start_bots_from_xml_config.py
Charly COSTE <changaco@changaco.net>
parents: 0
diff changeset
31 else:
a9077fa9cac9 Added optional parameter to start_bots_from_xml_config.py
Charly COSTE <changaco@changaco.net>
parents: 0
diff changeset
32 config = parse('config.xml')
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
33 except IOError:
19
c1b84196c100 Changed format of non-debug error messages, fixed IRC namreply handling, prevented crash when receiving bad XMPP stanza.
Charly COSTE <changaco@changaco.net>
parents: 17
diff changeset
34 print '[Error] configuration file is missing or cannot be read'
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
35 quit(1)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
36
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
37 bots_jids = []
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
38 for bot_el in config.getElementsByTagName('bot'):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
39 if bot_el.getAttribute('jid') in bots_jids:
19
c1b84196c100 Changed format of non-debug error messages, fixed IRC namreply handling, prevented crash when receiving bad XMPP stanza.
Charly COSTE <changaco@changaco.net>
parents: 17
diff changeset
40 print '[Error] you cannot have two bots using the same JID'
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
41 quit(2)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
42 bots_jids.append(bot_el.getAttribute('jid'))
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
43
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
44
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
45 try:
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 13
diff changeset
46 bots = []
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 13
diff changeset
47 for bot_el in config.getElementsByTagName('bot'):
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 13
diff changeset
48 debug = False
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 13
diff changeset
49 if bot_el.hasAttribute('debug'):
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 13
diff changeset
50 if bot_el.getAttribute('debug') == 'true':
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 13
diff changeset
51 debug = True
86
bfa32b017fc9 First hack at an error notification system
Charly COSTE <changaco@changaco.net>
parents: 21
diff changeset
52 admins_jid = []
bfa32b017fc9 First hack at an error notification system
Charly COSTE <changaco@changaco.net>
parents: 21
diff changeset
53 for admin_el in bot_el.getElementsByTagName('admin'):
bfa32b017fc9 First hack at an error notification system
Charly COSTE <changaco@changaco.net>
parents: 21
diff changeset
54 if admin_el.hasAttribute('jid'):
bfa32b017fc9 First hack at an error notification system
Charly COSTE <changaco@changaco.net>
parents: 21
diff changeset
55 admins_jid.append(admin_el.getAttribute('jid'))
124
99f3dee1fad7 code cleaning
Charly COSTE <changaco@changaco.net>
parents: 86
diff changeset
56 bot = Bot(bot_el.getAttribute('jid'), bot_el.getAttribute('password'), bot_el.getAttribute('nickname'), admins_jid=admins_jid, debug=debug)
99f3dee1fad7 code cleaning
Charly COSTE <changaco@changaco.net>
parents: 86
diff changeset
57 bots.append(bot)
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 13
diff changeset
58 for bridge_el in bot_el.getElementsByTagName('bridge'):
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 13
diff changeset
59 xmpp_room = bridge_el.getElementsByTagName('xmpp-room')[0]
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 13
diff changeset
60 irc = bridge_el.getElementsByTagName('irc')[0]
21
801160b4136f Introduced a bridge's "say" attribute to offer more flexibility in what the bot says.
Charly COSTE <changaco@changaco.net>
parents: 19
diff changeset
61 say_level = 'all'
801160b4136f Introduced a bridge's "say" attribute to offer more flexibility in what the bot says.
Charly COSTE <changaco@changaco.net>
parents: 19
diff changeset
62 if bridge_el.hasAttribute('say_level'):
801160b4136f Introduced a bridge's "say" attribute to offer more flexibility in what the bot says.
Charly COSTE <changaco@changaco.net>
parents: 19
diff changeset
63 say_level = bridge_el.getAttribute('say_level')
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 13
diff changeset
64 if bridge_el.hasAttribute('mode'):
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 13
diff changeset
65 mode = bridge_el.getAttribute('mode')
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 13
diff changeset
66 else:
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 13
diff changeset
67 mode = 'normal'
124
99f3dee1fad7 code cleaning
Charly COSTE <changaco@changaco.net>
parents: 86
diff changeset
68 bot.new_bridge(xmpp_room.getAttribute('jid'), irc.getAttribute('chan'), irc.getAttribute('server'), mode, say_level)
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 13
diff changeset
69
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 13
diff changeset
70
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
71 while True:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
72 sleep(1)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
73 except:
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 13
diff changeset
74 for bot in bots:
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 13
diff changeset
75 del bot
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 13
diff changeset
76 traceback.print_exc()
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
77 quit(3)