Mercurial > xib
comparison commands.py @ 173:6c4aaf8f3733
added "--sort" option to the "connections" command
Signed-off-by: Charly COSTE <changaco@changaco.net>
author | Charly COSTE <changaco@changaco.net> |
---|---|
date | Wed, 03 Feb 2010 18:40:47 +0100 |
parents | d3b619cd60fb |
children | 891195c47350 |
comparison
equal
deleted
inserted
replaced
172:64a0e9636ae6 | 173:6c4aaf8f3733 |
---|---|
156 | 156 |
157 | 157 |
158 def connections(bot, command, args_array, bridge): | 158 def connections(bot, command, args_array, bridge): |
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 try: | 162 try: |
162 args = parser.parse_args(args_array) | 163 args = parser.parse_args(args_array) |
163 except ArgumentParser.ParseException as e: | 164 except ArgumentParser.ParseException as e: |
164 return '\n'+e.args[1] | 165 return '\n'+e.args[1] |
165 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) |
193 | 194 |
194 | 195 |
195 def irc_connections(bot, command, args_array, bridge): | 196 def irc_connections(bot, command, args_array, bridge): |
196 parser = ArgumentParser(prog=command) | 197 parser = ArgumentParser(prog=command) |
197 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') | |
198 try: | 200 try: |
199 args = parser.parse_args(args_array) | 201 args = parser.parse_args(args_array) |
200 except ArgumentParser.ParseException as e: | 202 except ArgumentParser.ParseException as e: |
201 return '\n'+e.args[1] | 203 return '\n'+e.args[1] |
202 n = len(bot.irc.connections) | 204 n = len(bot.irc.connections) |
203 if args.verbose: | 205 if args.verbose: |
204 ret = 'List of IRC connections ('+str(n)+'):' | 206 ret = 'List of IRC connections ('+str(n)+'):' |
205 for c in bot.irc.connections: | 207 if args.sort: |
208 connections = [str(c) for c in bot.irc.connections] | |
209 connections.sort() | |
210 else: | |
211 connections = bot.irc.connections | |
212 for c in connections: | |
206 ret += '\n\t'+str(c) | 213 ret += '\n\t'+str(c) |
207 else: | 214 else: |
208 ret = 'Number of IRC connections: '+str(n) | 215 ret = 'Number of IRC connections: '+str(n) |
209 return ret | 216 return ret |
210 | 217 |
277 | 284 |
278 | 285 |
279 def xmpp_connections(bot, command, args_array, bridge): | 286 def xmpp_connections(bot, command, args_array, bridge): |
280 parser = ArgumentParser(prog=command) | 287 parser = ArgumentParser(prog=command) |
281 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') | |
282 try: | 290 try: |
283 args = parser.parse_args(args_array) | 291 args = parser.parse_args(args_array) |
284 except ArgumentParser.ParseException as e: | 292 except ArgumentParser.ParseException as e: |
285 return '\n'+e.args[1] | 293 return '\n'+e.args[1] |
286 n = len(bot.xmpp_connections) | 294 n = len(bot.xmpp_connections) |
287 if args.verbose: | 295 if args.verbose: |
288 ret = 'List of XMPP connections ('+str(n)+'):' | 296 ret = 'List of XMPP connections ('+str(n)+'):' |
289 for nickname in bot.xmpp_connections.iterkeys(): | 297 nicknames = bot.xmpp_connections.keys() |
298 if args.sort: | |
299 nicknames.sort() | |
300 for nickname in nicknames: | |
290 ret += '\n\t'+nickname | 301 ret += '\n\t'+nickname |
291 else: | 302 else: |
292 ret = 'Number of XMPP connections: '+str(n) | 303 ret = 'Number of XMPP connections: '+str(n) |
293 return ret | 304 return ret |
294 | 305 |