Esempio n. 1
0
 def print_value(self, value):
     value_str = VERTICAL_LINE
     segmemt = ''
     for i in range(len(value)):
         val = UseStyle(value[i], fore='green') if i > 0 else UseStyle(value[i], mode='bold', fore='red')
         # val = value[i]
         value_str += (SPACE * EMPTY
                       + val
                       + (self.header_width[i] - len(value[i]) - EMPTY) * SPACE
                       + VERTICAL_LINE)
         segmemt += (SPACE * 1 + self.header_width[i] * HORIZON_LINE)
     value_str += NEWLINE
     segmemt += NEWLINE
     # return value_str
     return value_str + segmemt
Esempio n. 2
0
    def login(self, host, user=None, password=None, port=22):
        if user is not None and password is not None:
            self.pexpClient.set_param(host, user, password, port)
            self.pexpClient.connect()
            try:
                import sys
                sys.stdout.write(
                    UseStyle("Try to login %s@%s \n" % (user, host),
                             mode='bold',
                             fore='green'))
                # sys.stdout.write(UseStyle("**********************************\n", mode = 'bold',fore='cyan'))
                # sys.stdout.write(UseStyle("*     __  __   ____    _   _     *\n", mode = 'bold',fore='cyan'))
                # sys.stdout.write(UseStyle("*    |  \/  | / ___|  | | | |    *\n", mode = 'bold',fore='cyan'))
                # sys.stdout.write(UseStyle("*    | |\/| | \___ \  | |_| |    *\n", mode = 'bold',fore='cyan'))
                # sys.stdout.write(UseStyle("*    | |  | |  ___) | |  _  |    *\n", mode = 'bold',fore='cyan'))
                # sys.stdout.write(UseStyle("*    |_|  |_| |____/  |_| |_|    *\n", mode = 'bold',fore='cyan'))
                # sys.stdout.write(UseStyle("*                                *\n", mode='bold', fore='cyan'))
                # sys.stdout.write(UseStyle("**********************************\n", mode='bold', fore='cyan'))

                self.pexpClient.login()
                self.pexpClient.interact()
            except PasswordErrorException, e:
                print redStr(
                    "Password error, please make sure the correctness of password!"
                )
                raise
Esempio n. 3
0
    def print_header(self):
        segment = ''
        value = VERTICAL_LINE
        for i in range(len(self.headers)):
            segment += (SPACE * 1 + self.header_width[i] * HORIZON_LINE)
            value += (
                SPACE * EMPTY + UseStyle(self.headers[i], fore='red') +
                (self.header_width[i] - len(self.headers[i]) - EMPTY) * SPACE +
                VERTICAL_LINE)

        return segment + NEWLINE + value + NEWLINE + segment + NEWLINE
Esempio n. 4
0
 def login_with_password(self):
     if self.password is None or self.password.strip() == '':
         # sys.stdout.write('\n')
         password = getpass.getpass(
             UseStyle('Input Your Password:'******'bold', fore='green'))
         self.child.sendline(password)
     else:
         self.child.sendline(self.password)
     self.child.expect("Permission denied|Password:|password:|[#\$]|\s")
     if self.child.after == "Permission denied" or self.child.after == "Password:"******"password:":
         raise PasswordErrorException
     else:
         sys.stdout.write(self.child.before + self.child.after)
Esempio n. 5
0
 def login(self, host, user=None, password=None):
     if user is not None and password is not None:
         self.pexpClient.set_param(host, user, password)
         self.pexpClient.connect()
         try:
             import sys
             sys.stdout.write(
                 UseStyle("Prepare for login ==> %s@%s" % (user, host),
                          mode='bold',
                          fore='black',
                          back='cyan'))
             sys.stdout.write('\n')
             self.pexpClient.login()
             self.pexpClient.interact()
         except PasswordErrorException, e:
             print "密码错误,请确认后再连接"
             raise
Esempio n. 6
0
# -*- coding:utf8 -*-
import sys, os
from msh.service.color import UseStyle, redStr, greenStr

SPACE = ' '
HORIZON_LINE = UseStyle('-', fore='blue')
VERTICAL_LINE = UseStyle('|', fore='blue')
BOTTOM_LINE = UseStyle('_', fore='blue')
EMPTY = 1
NEWLINE = '\n'


class OutputClient:
    def __init__(self):
        self.headers = None
        self.header_width = None
        self.values = None
        self.values_dict = None

    def set_header(self, headers, header_width):
        if not isinstance(headers, list) and not isinstance(
                header_width, list):
            raise Exception("The format of parameters is not correct")
        self.headers = headers
        self.header_width = header_width

    def set_values(self, values):
        self.values_dict = values
        self.values = self._convert(values)

    def _convert(self, ssh_list_dict):