def display_search_result(self): """打印搜索的结果""" if self.assets is None: self.assets = self.get_my_assets() if not self.search_result: self.search_result = self.assets hostname_length = max_length( [asset.hostname for asset in self.search_result]) system_user_length = system_user_max_length(self.assets) line = '[%-4s] %-16s %-5s %-' + str(hostname_length) + 's %-' + str( system_user_length + 2) + 's ' comment_length = request.win_width - len(line % ((' ', ) * 5)) - 5 line += ('%-' + str(comment_length) + 's') self.client_channel.send( wr( title( line % ('ID', 'IP', 'Port', 'Hostname', 'Username', 'Comment')))) for index, asset in enumerate(self.search_result): system_users = '[' + ', '.join( [system_user.username for system_user in asset.system_users]) \ + ']' self.client_channel.send( wr(line % (index, asset.ip, asset.port, asset.hostname, system_users, asset.comment))) self.client_channel.send(wr(''))
def display_asset_groups(self): """打印授权的资产组""" self.asset_groups = self.get_my_asset_groups() name_max_length = max_length([asset_group.name for asset_group in self.asset_groups], max_=20) comment_max_length = max_length([asset_group.comment for asset_group in self.asset_groups], max_=30) line = '[%-3s] %-' + str(name_max_length) + 's %-6s %-' \ + str(comment_max_length) + 's' self.client_channel.send(wr(title(line % ('ID', 'Name', 'Assets', 'Comment')))) for index, asset_group in enumerate(self.asset_groups): self.client_channel.send(wr(line % ( index, asset_group.name, asset_group.assets_amount, asset_group.comment[:comment_max_length]))) self.client_channel.send(wr(''))
def display_search_result(self): """打印搜索的结果""" if self.assets is None: self.assets = self.get_my_assets() if not self.search_result: self.search_result = self.assets hostname_length = max_length([asset.hostname for asset in self.search_result]) system_user_length = system_user_max_length(self.assets) line = '[%-4s] %-16s %-5s %-' + str(hostname_length) + 's %-' + str(system_user_length+2) + 's ' comment_length = request.win_width-len(line % ((' ',) * 5)) - 5 line += ('%-' + str(comment_length) + 's') self.client_channel.send(wr(title(line % ( 'ID', 'IP', 'Port', 'Hostname', 'Username', 'Comment')))) for index, asset in enumerate(self.search_result): system_users = '[' + ', '.join( [system_user.username for system_user in asset.system_users]) \ + ']' self.client_channel.send(wr( line % (index, asset.ip, asset.port, asset.hostname, system_users, asset.comment))) self.client_channel.send(wr(''))