From f73ba9cc4a9814cf54eb7bc921cf8dc0939da012 Mon Sep 17 00:00:00 2001 From: ibuler Date: Fri, 26 Dec 2014 21:39:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=98=BE=E7=A4=BAid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- connect.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/connect.py b/connect.py index 488264d82..5e39dcb40 100755 --- a/connect.py +++ b/connect.py @@ -151,7 +151,7 @@ def posix_shell(chan, user, host): def get_user_host(username): - hosts_comments = {} + hosts_attr = {} try: user = User.objects.get(username=username) except ObjectDoesNotExist: @@ -159,10 +159,10 @@ def get_user_host(username): else: perm_all = user.permission_set.all() for perm in perm_all: - hosts_comments[perm.asset.ip] = perm.asset.comment - hosts = hosts_comments.keys() + hosts_attr[perm.asset.ip] = [perm.asset.id, perm.asset.comment] + hosts = hosts_attr.keys() hosts.sort() - return hosts_comments, hosts + return hosts_attr, hosts def get_connect_item(username, ip): @@ -190,14 +190,14 @@ def get_connect_item(username, ip): def verify_connect(username, part_ip): ip_matched = [] - hosts_comments, hosts = get_user_host(username) + hosts_mix, hosts = get_user_host(username) for ip in hosts: if part_ip in ip: ip_matched.append(ip) if len(ip_matched) > 1: for ip in ip_matched: - print '%s -- %s' % (ip, hosts_comments[ip]) + print '[%s] %s -- %s' % (hosts_mix[ip][0], ip, hosts_mix[ip][1]) elif len(ip_matched) < 1: red_print('No Permission or No host.') else: @@ -220,9 +220,9 @@ def print_prompt(): def print_user_host(username): - hosts_comments, hosts = get_user_host(username) + hosts_attr, hosts = get_user_host(username) for ip in hosts: - print '%s -- %s' % (ip, hosts_comments[ip]) + print '[%s] %s -- %s' % (hosts_attr[ip][0], ip, hosts_attr[ip][1]) def connect(username, password, host, port):