From 1959c685b94dc8fd7b56d1d4da3f0975cd1481e5 Mon Sep 17 00:00:00 2001 From: ibuler Date: Fri, 1 Apr 2016 17:52:47 +0800 Subject: [PATCH] new feature (connect) Ignore case in searching finshed --- connect.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/connect.py b/connect.py index c23c33356..79966cb2e 100755 --- a/connect.py +++ b/connect.py @@ -489,8 +489,10 @@ class Nav(object): except (ValueError, TypeError): # 匹配 ip, hostname, 备注 - self.search_result = [asset for asset in self.perm_assets if str_r in str(asset.ip) - or str_r in str(asset.hostname) or str_r in str(asset.comment)] + str_r = str_r.lower() + self.search_result = [asset for asset in self.perm_assets if str_r in str(asset.ip).lower() + or str_r in str(asset.hostname).lower() + or str_r in str(asset.comment).lower()] else: # 如果没有输入就展现所有 self.search_result = self.perm_assets @@ -532,8 +534,8 @@ class Nav(object): color_print('没有映射用户', 'red') return - ssh_tty = SshTty(login_user, asset, role) print('Connecting %s ...' % asset.hostname) + ssh_tty = SshTty(login_user, asset, role) ssh_tty.connect() except (KeyError, ValueError): color_print('请输入正确ID', 'red') @@ -781,6 +783,7 @@ def main(): else: nav.search(option) if len(nav.search_result) == 1: + print('Only match Host: %s ' % nav.search_result[0].hostname) nav.try_connect() else: nav.print_search_result()