changeset 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 64a0e9636ae6
children c158ad24ef3c
files commands.py
diffstat 1 files changed, 13 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/commands.py
+++ b/commands.py
@@ -158,6 +158,7 @@ def change_bridges_mode(bot, command, ar
 def connections(bot, command, args_array, bridge):
 	parser = ArgumentParser(prog=command)
 	parser.add_argument('--verbose', '-v', default=False, action='store_true')
+	parser.add_argument('--sort', '-s', default=False, action='store_true')
 	try:
 		args = parser.parse_args(args_array)
 	except ArgumentParser.ParseException as e:
@@ -195,6 +196,7 @@ def halt(bot, command, args_array, bridg
 def irc_connections(bot, command, args_array, bridge):
 	parser = ArgumentParser(prog=command)
 	parser.add_argument('--verbose', '-v', default=False, action='store_true')
+	parser.add_argument('--sort', '-s', default=False, action='store_true')
 	try:
 		args = parser.parse_args(args_array)
 	except ArgumentParser.ParseException as e:
@@ -202,7 +204,12 @@ def irc_connections(bot, command, args_a
 	n = len(bot.irc.connections)
 	if args.verbose:
 		ret = 'List of IRC connections ('+str(n)+'):'
-		for c in bot.irc.connections:
+		if args.sort:
+			connections = [str(c) for c in bot.irc.connections]
+			connections.sort()
+		else:
+			connections = bot.irc.connections
+		for c in connections:
 			ret += '\n\t'+str(c)
 	else:
 		ret = 'Number of IRC connections: '+str(n)
@@ -279,6 +286,7 @@ def stop_bridges(bot, command, args_arra
 def xmpp_connections(bot, command, args_array, bridge):
 	parser = ArgumentParser(prog=command)
 	parser.add_argument('--verbose', '-v', default=False, action='store_true')
+	parser.add_argument('--sort', '-s', default=False, action='store_true')
 	try:
 		args = parser.parse_args(args_array)
 	except ArgumentParser.ParseException as e:
@@ -286,7 +294,10 @@ def xmpp_connections(bot, command, args_
 	n = len(bot.xmpp_connections)
 	if args.verbose:
 		ret = 'List of XMPP connections ('+str(n)+'):'
-		for nickname in bot.xmpp_connections.iterkeys():
+		nicknames = bot.xmpp_connections.keys()
+		if args.sort:
+			nicknames.sort()
+		for nickname in nicknames:
 			ret += '\n\t'+nickname
 	else:
 		ret = 'Number of XMPP connections: '+str(n)