# HG changeset patch # User Charly COSTE # Date 1265218847 -3600 # Node ID 6c4aaf8f3733bbae86e62d89f47f22277c51f184 # Parent 64a0e9636ae68f13323ea0cc3b0631af176cb5f3 added "--sort" option to the "connections" command Signed-off-by: Charly COSTE diff --git a/commands.py b/commands.py --- 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)