comparison commands.py @ 178:891195c47350

catch all exceptions in commands.py Signed-off-by: Charly COSTE <changaco@changaco.net>
author Charly COSTE <changaco@changaco.net>
date Mon, 08 Feb 2010 18:55:36 +0100
parents 6c4aaf8f3733
children 102f895347ff
comparison
equal deleted inserted replaced
177:d1686164b9e3 178:891195c47350
83 parser.add_argument('--mode', choices=Bridge._modes, default='normal') 83 parser.add_argument('--mode', choices=Bridge._modes, default='normal')
84 parser.add_argument('--say-level', choices=Bridge._say_levels, default='all') 84 parser.add_argument('--say-level', choices=Bridge._say_levels, default='all')
85 parser.add_argument('--irc-port', type=int, default=6667) 85 parser.add_argument('--irc-port', type=int, default=6667)
86 try: 86 try:
87 args = parser.parse_args(args_array) 87 args = parser.parse_args(args_array)
88 except ArgumentParser.ParseException as e: 88 except Exception as e:
89 return '\n'+e.args[1] 89 return '\n'+e.args[1]
90 90
91 bot.new_bridge(args.xmpp_room_jid, args.irc_chan, args.irc_server, args.mode, args.say_level, irc_port=args.irc_port) 91 bot.new_bridge(args.xmpp_room_jid, args.irc_chan, args.irc_server, args.mode, args.say_level, irc_port=args.irc_port)
92 92
93 return 'Bridge added.' 93 return 'Bridge added.'
96 def add_xmpp_admin(bot, command, args_array, bridge): 96 def add_xmpp_admin(bot, command, args_array, bridge):
97 parser = ArgumentParser(prog=command) 97 parser = ArgumentParser(prog=command)
98 parser.add_argument('jid', type=str) 98 parser.add_argument('jid', type=str)
99 try: 99 try:
100 args = parser.parse_args(args_array) 100 args = parser.parse_args(args_array)
101 except ArgumentParser.ParseException as e: 101 except Exception as e:
102 return '\n'+e.args[1] 102 return '\n'+e.args[1]
103 bot.admins_jid.append(args.jid) 103 bot.admins_jid.append(args.jid)
104 for b in bot.bridges: 104 for b in bot.bridges:
105 for p in b.participants: 105 for p in b.participants:
106 if p.real_jid != None and xmpp.protocol.JID(args.jid).bareMatch(p.real_jid): 106 if p.real_jid != None and xmpp.protocol.JID(args.jid).bareMatch(p.real_jid):
114 parser.add_argument('--show-mode', default=False, action='store_true') 114 parser.add_argument('--show-mode', default=False, action='store_true')
115 parser.add_argument('--show-say-level', default=False, action='store_true') 115 parser.add_argument('--show-say-level', default=False, action='store_true')
116 parser.add_argument('--show-participants', default=False, action='store_true') 116 parser.add_argument('--show-participants', default=False, action='store_true')
117 try: 117 try:
118 args = parser.parse_args(args_array) 118 args = parser.parse_args(args_array)
119 except ArgumentParser.ParseException as e: 119 except Exception as e:
120 return '\n'+e.args[1] 120 return '\n'+e.args[1]
121 ret = 'List of bridges:' 121 ret = 'List of bridges:'
122 for i, b in enumerate(bot.bridges): 122 for i, b in enumerate(bot.bridges):
123 ret += '\n'+str(i+1)+' - '+str(b) 123 ret += '\n'+str(i+1)+' - '+str(b)
124 if args.show_mode: 124 if args.show_mode:
139 parser = ArgumentParser(prog=command) 139 parser = ArgumentParser(prog=command)
140 parser.add_argument('bridge_id', nargs='+') 140 parser.add_argument('bridge_id', nargs='+')
141 parser.add_argument('new_mode', choices=Bridge._modes) 141 parser.add_argument('new_mode', choices=Bridge._modes)
142 try: 142 try:
143 args = parser.parse_args(args_array) 143 args = parser.parse_args(args_array)
144 except ArgumentParser.ParseException as e: 144 except Exception as e:
145 return '\n'+e.args[1] 145 return '\n'+e.args[1]
146 146
147 found_bridges, ret = _find_bridges(bot, args.bridge_id) 147 found_bridges, ret = _find_bridges(bot, args.bridge_id)
148 for found_bridge in found_bridges: 148 for found_bridge in found_bridges:
149 r = found_bridge.changeMode(args.new_mode) 149 r = found_bridge.changeMode(args.new_mode)
159 parser = ArgumentParser(prog=command) 159 parser = ArgumentParser(prog=command)
160 parser.add_argument('--verbose', '-v', default=False, action='store_true') 160 parser.add_argument('--verbose', '-v', default=False, action='store_true')
161 parser.add_argument('--sort', '-s', default=False, action='store_true') 161 parser.add_argument('--sort', '-s', default=False, action='store_true')
162 try: 162 try:
163 args = parser.parse_args(args_array) 163 args = parser.parse_args(args_array)
164 except ArgumentParser.ParseException as e: 164 except Exception as e:
165 return '\n'+e.args[1] 165 return '\n'+e.args[1]
166 return irc_connections(bot, 'irc-connections', args_array, bridge)+'\n'+xmpp_connections(bot, 'xmpp-connections', args_array, bridge) 166 return irc_connections(bot, 'irc-connections', args_array, bridge)+'\n'+xmpp_connections(bot, 'xmpp-connections', args_array, bridge)
167 167
168 168
169 def debug(bot, command, args_array, bridge): 169 def debug(bot, command, args_array, bridge):
170 parser = ArgumentParser(prog=command) 170 parser = ArgumentParser(prog=command)
171 parser.add_argument('mode', choices=['on', 'off']) 171 parser.add_argument('mode', choices=['on', 'off'])
172 try: 172 try:
173 args = parser.parse_args(args_array) 173 args = parser.parse_args(args_array)
174 except ArgumentParser.ParseException as e: 174 except Exception as e:
175 if len(args_array) == 0: 175 if len(args_array) == 0:
176 if bot.debug: 176 if bot.debug:
177 return 'Debugging is on' 177 return 'Debugging is on'
178 else: 178 else:
179 return 'Debugging is off' 179 return 'Debugging is off'
197 parser = ArgumentParser(prog=command) 197 parser = ArgumentParser(prog=command)
198 parser.add_argument('--verbose', '-v', default=False, action='store_true') 198 parser.add_argument('--verbose', '-v', default=False, action='store_true')
199 parser.add_argument('--sort', '-s', default=False, action='store_true') 199 parser.add_argument('--sort', '-s', default=False, action='store_true')
200 try: 200 try:
201 args = parser.parse_args(args_array) 201 args = parser.parse_args(args_array)
202 except ArgumentParser.ParseException as e: 202 except Exception as e:
203 return '\n'+e.args[1] 203 return '\n'+e.args[1]
204 n = len(bot.irc.connections) 204 n = len(bot.irc.connections)
205 if args.verbose: 205 if args.verbose:
206 ret = 'List of IRC connections ('+str(n)+'):' 206 ret = 'List of IRC connections ('+str(n)+'):'
207 if args.sort: 207 if args.sort:
231 def remove_bridges(bot, command, args_array, bridge): 231 def remove_bridges(bot, command, args_array, bridge):
232 parser = ArgumentParser(prog=command) 232 parser = ArgumentParser(prog=command)
233 parser.add_argument('bridge_id', nargs='+') 233 parser.add_argument('bridge_id', nargs='+')
234 try: 234 try:
235 args = parser.parse_args(args_array) 235 args = parser.parse_args(args_array)
236 except ArgumentParser.ParseException as e: 236 except Exception as e:
237 return '\n'+e.args[1] 237 return '\n'+e.args[1]
238 238
239 found_bridges, ret = _find_bridges(bot, args.bridge_id) 239 found_bridges, ret = _find_bridges(bot, args.bridge_id)
240 240
241 for found_bridge in found_bridges: 241 for found_bridge in found_bridges:
251 def restart_bridges(bot, command, args_array, bridge): 251 def restart_bridges(bot, command, args_array, bridge):
252 parser = ArgumentParser(prog=command) 252 parser = ArgumentParser(prog=command)
253 parser.add_argument('bridge_id', nargs='+') 253 parser.add_argument('bridge_id', nargs='+')
254 try: 254 try:
255 args = parser.parse_args(args_array) 255 args = parser.parse_args(args_array)
256 except ArgumentParser.ParseException as e: 256 except Exception as e:
257 return '\n'+e.args[1] 257 return '\n'+e.args[1]
258 258
259 found_bridges, ret = _find_bridges(bot, args.bridge_id) 259 found_bridges, ret = _find_bridges(bot, args.bridge_id)
260 for found_bridge in found_bridges: 260 for found_bridge in found_bridges:
261 found_bridge.restart() 261 found_bridge.restart()
271 def stop_bridges(bot, command, args_array, bridge): 271 def stop_bridges(bot, command, args_array, bridge):
272 parser = ArgumentParser(prog=command) 272 parser = ArgumentParser(prog=command)
273 parser.add_argument('bridge_id', nargs='+') 273 parser.add_argument('bridge_id', nargs='+')
274 try: 274 try:
275 args = parser.parse_args(args_array) 275 args = parser.parse_args(args_array)
276 except ArgumentParser.ParseException as e: 276 except Exception as e:
277 return '\n'+e.args[1] 277 return '\n'+e.args[1]
278 278
279 found_bridges, ret = _find_bridges(bot, args.bridge_id) 279 found_bridges, ret = _find_bridges(bot, args.bridge_id)
280 for found_bridge in found_bridges: 280 for found_bridge in found_bridges:
281 found_bridge.stop() 281 found_bridge.stop()
287 parser = ArgumentParser(prog=command) 287 parser = ArgumentParser(prog=command)
288 parser.add_argument('--verbose', '-v', default=False, action='store_true') 288 parser.add_argument('--verbose', '-v', default=False, action='store_true')
289 parser.add_argument('--sort', '-s', default=False, action='store_true') 289 parser.add_argument('--sort', '-s', default=False, action='store_true')
290 try: 290 try:
291 args = parser.parse_args(args_array) 291 args = parser.parse_args(args_array)
292 except ArgumentParser.ParseException as e: 292 except Exception as e:
293 return '\n'+e.args[1] 293 return '\n'+e.args[1]
294 n = len(bot.xmpp_connections) 294 n = len(bot.xmpp_connections)
295 if args.verbose: 295 if args.verbose:
296 ret = 'List of XMPP connections ('+str(n)+'):' 296 ret = 'List of XMPP connections ('+str(n)+'):'
297 nicknames = bot.xmpp_connections.keys() 297 nicknames = bot.xmpp_connections.keys()