示例#1
0
def is_legal_space(command):
    sub_cmds = command.split()
    if len(sub_cmds) == 0:
        return False
    if re.match('^.*  $', command):
        return False

    last_sub_cmd = sub_cmds[len(sub_cmds) - 1]
    if command[len(command) - 1] != ' ':
        del sub_cmds[len(sub_cmds) - 1]
    sub_cmds.append('')
    cmd_list = get_sub_command_list(sub_cmds, XKey.SPACE)
    result = True
    if cmd_list == None:
        result = False
    err_command = sub_cmds[len(sub_cmds) - 2]
    if cmd_list:
        result = True
        if command[len(command) - 1] != ' ':
            _, result = get_max_same_string(last_sub_cmd, cmd_list)
            err_command = last_sub_cmd
    if not result:
        xprint_new_line('\tno \'{}\' command'.format(err_command))
        return False

    return True
示例#2
0
def action_git_commits(cmds, key):
    num_cmd = len(cmds)
    if cmds[num_cmd - 1] == '':
        del cmds[num_cmd - 1]
        num_cmd -= 1

    if num_cmd >= 0 and key == XKey.ENTER:
        repo_dir, _, _ = get_gnb_dirs('')
        if not repo_dir:
            xprint_new_line('\tNot a git repository')
            return {'flag': True, 'new_input_cmd': ''}
        common_part = '--graph --pretty=format:\'%Cred%h%Creset,%C(yellow)%cd%Creset,%Cgreen%ae%Creset,%s\' --abbrev-commit --date=short'
        message, author, start, end, before, after, self_dir = parse_commits_cmds(
            cmds)
        start_end = format_start_end(start, end)
        xprint_new_line('')
        #xprint_head(message + ' ' + author + ' ' + start + ' ' + end + ' ' + before + ' ' + after + ' ' + self_dir)
        system_cmd = 'git log ' + start_end + ' ' + message + ' ' + author
        system_cmd = system_cmd + ' ' + before + ' ' + after + ' ' + common_part + ' ' + self_dir
        system_cmd = re.sub(' +', ' ', system_cmd)
        #xprint_head(system_cmd)
        #os.system(system_cmd)
        child = subprocess.Popen(system_cmd,
                                 shell=True,
                                 stdout=subprocess.PIPE)
        output = child.communicate()[0].split('\n')
        parse_commits_output(output)
        return {'flag': True, 'new_input_cmd': ''}

    show_git_commits_help()
示例#3
0
def action_gnb_cprt_build(cmds, key):
    num_cmd = len(cmds)
    if cmds[num_cmd - 1] == '':
        del cmds[num_cmd - 1]
        num_cmd -= 1

    if num_cmd == 0 and key == XKey.ENTER:
        repo_dir, sdk5g_dir, build_dir = get_gnb_dirs('cprt')
        if not repo_dir:
            xprint_new_line('\tNot a git repository')
            return {'flag': True, 'new_input_cmd': ''}
        if not os.path.exists(build_dir):
            os.makedirs(build_dir)
        env_path = os.getenv('PATH')
        env_prefix_type = os.getenv('PREFIX_TYPE')
        if not env_prefix_type:
            env_prefix_type = XConst.CPRT_PREFIX_TYPE
        system_cmd = ''
        if not re.search('sdk5g.+prefix_root_' + env_prefix_type, env_path):
            system_cmd += 'source ' + sdk5g_dir + '/prefix_root_' + env_prefix_type + '/environment-setup.sh && '
        system_cmd += 'export BUILD_DIR=' + build_dir + ' && '
        system_cmd += 'cd ' + build_dir + ' && '
        system_cmd += 'cmake -GNinja -DBUILD_TESTS=ON ' + repo_dir + '/cplane/CP-RT/CP-RT/ && '
        system_cmd += 'ninja'
        xprint_new_line(system_cmd)
        os.system(system_cmd)
        xprint_head('')
        return {'flag': True, 'new_input_cmd': ''}

    show_gnb_cprt_build_help()
示例#4
0
def action_gnb_cpnrt_ttcn(cmds, key):
    num_cmd = len(cmds)
    if cmds[num_cmd - 1] == '':
        del cmds[num_cmd - 1]
        num_cmd -= 1

    if num_cmd <= 2 and key == XKey.ENTER:
        repo_dir, sdk5g_dir, build_dir = get_gnb_dirs('cpnrt')
        if not repo_dir:
            xprint_new_line('\tNot a git repository')
            return {'flag': True, 'new_input_cmd': ''}
        if not os.path.exists(build_dir):
            os.makedirs(build_dir)
        env_path = os.getenv('PATH')
        env_prefix_type = os.getenv('PREFIX_TYPE')
        if not env_prefix_type:
            env_prefix_type = XConst.CPNRT_PREFIX_TYPE
        system_cmd = ''
        if not re.search('sdk5g.+prefix_root_' + env_prefix_type, env_path):
            system_cmd += 'source ' + sdk5g_dir + '/prefix_root_' + env_prefix_type + '/environment-setup.sh && '
        system_cmd += 'cd ' + build_dir + ' && '
        system_cmd += 'cmake ' + repo_dir + '/cplane/CP-NRT -DBUILD_TTCN3_SCT=ON && '
        system_cmd += 'make sct_run_cp_nrt -j$(nproc) -l$(nproc) '
        if num_cmd >= 1:
            system_cmd += 'SCT_TEST_PATTERNS=' + cmds[0]
        if num_cmd == 2:
            system_cmd += ' SCT_TTCN3_REPEAT_COUNT=' + cmds[1]
        xprint_new_line('')
        xprint_head(system_cmd)
        os.system(system_cmd)
        xprint_head('')
        return {'flag': True, 'new_input_cmd': ''}

    show_gnb_cpnrt_ttcn_help()
示例#5
0
def action_replace(cmds, key):
    num_cmd = len(cmds)
    if cmds[num_cmd - 1] == '':
        del cmds[num_cmd - 1]
        num_cmd -= 1

    if num_cmd > 0 and num_cmd <= 2 and key == XKey.ENTER:
        old_string = cmds[0]
        new_string = ''
        if num_cmd == 2:
            new_string = cmds[1]

        xprint_new_line('')
        for root, dirs, files in os.walk('./'):
            for item in files:
                path = os.path.join(root, item)
                #print(os.path.join(root, item))
                shutil.copy(path, '{}.orig'.format(path))
                new_cmd = 'sed -ri \'s/' + old_string + '/' + new_string + '/g\' ' + path
                if os.path.exists('/usr/bin/colordiff'):
                    new_cmd += ' && colordiff -u ' + line + '.orig' + ' ' + line
                elif os.path.exists('/usr/bin/diff'):
                    new_cmd += ' && diff -u ' + line + '.orig' + ' ' + line
                os.system(new_cmd)
                os.unlink('{}/{}.orig'.format(repo_dir, line))
        xprint_head('')
        return {'flag': True, 'new_input_cmd': ''}

    show_replace_help()
示例#6
0
def get_login_history_by_name(name):
    if os.path.getsize(XConst.LOGIN_HISTORY_FILE) == 0:
        xprint_new_line('\tno any login history')
        return None

    f = open(XConst.LOGIN_HISTORY_FILE, 'r')
    line = f.readline()
    while line:
        sub_cmds = line.strip('\n').split()
        if len(sub_cmds) != XConst.NUM_ELEM_PER_LOGIN_HISTORY_ITEM:
            line = f.readline()
            continue
        if name == sub_cmds[0]:
            f.close()
            return {
                'name': sub_cmds[0],
                'ip': sub_cmds[1],
                'user': sub_cmds[2],
                'password': sub_cmds[3]
            }
        line = f.readline()
    f.close()

    xprint_new_line('\tno login history for name = {}'.format(name))
    return None
示例#7
0
def action_gnb_cu_build(cmds, key):
    num_cmd = len(cmds)
    if cmds[num_cmd - 1] == '':
        del cmds[num_cmd - 1]
        num_cmd -= 1

    if num_cmd == 0 and key == XKey.ENTER:
        repo_dir, sdk5g_dir, build_dir = get_gnb_dirs('cu')
        if not repo_dir:
            xprint_new_line('\tNot a git repository')
            return {'flag': True, 'new_input_cmd': ''}
        if not os.path.exists(build_dir):
            os.makedirs(build_dir)
        env_path = os.getenv('PATH')
        env_prefix_type = os.getenv('PREFIX_TYPE')
        if not env_prefix_type:
            env_prefix_type = XConst.CU_PREFIX_TYPE
        system_cmd = ''
        if not re.search('sdk5g.+prefix_root_' + env_prefix_type, env_path):
            system_cmd += 'source ' + sdk5g_dir + '/prefix_root_' + env_prefix_type + '/environment-linsee-setup.sh && '
        system_cmd += 'cd ' + build_dir + ' && '
        system_cmd += 'cmake --version && echo $PATH && '
        system_cmd += 'cmake ' + repo_dir + '/cplane && '
        system_cmd += 'make -j$(nproc)'
        xprint_new_line('')
        xprint_head(system_cmd)
        os.system(system_cmd)
        xprint_head('')
        return {'flag': True, 'new_input_cmd': ''}

    show_gnb_cu_build_help()
示例#8
0
def show_ssh_help():
    xprint_new_line('\t# ssh [NAME] [IP] [USER] [PASSWORD]',
                    XPrintStyle.YELLOW)
    xprint_head('\t# ssh [NAME | IP] -', XPrintStyle.YELLOW)
    xprint_head('\tExample 1: # ssh DU10 1.2.3.4 root rootme')
    xprint_head(
        '\t           -> NAME=DU10, IP=1.2.3.4, USER=root PASSWORD=rootme')
    xprint_head(
        '\t           -> form to [email protected] with password=rootme to login remote'
    )
    xprint_head('\t           -> store this login to history named DU10')
    xprint_head('\tExample 2: # ssh DU10')
    xprint_head(
        '\t           -> get detail of DU10 in Example 1 to login remote')
    xprint_head('\tExample 3: # ssh DU10 -')
    xprint_head('\t           -> remove DU10 from history')
    xprint_head(
        '\t           -> only in this format, DU10 can be regular expression')
    xprint_head('\tExample 3.1: # ssh 1.2.3.4 -')
    xprint_head('\tExample 3.2: # ssh ^du.*$ -')
    xprint_head(
        '\tExample 3.3: # ssh ^[0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}[.]10$ -')
    xprint_head(
        '\t             -> Example 3 and 3.1 only remove history which name = DU10 or ip = 1.2.3.4'
    )
    xprint_head(
        '\t             -> Example 3.2 remove history that name begin with du, like as du10, du1, du300, etc.'
    )
    xprint_head(
        '\t             -> Example 3.3 remove history that ip end with .10, like as 1.2.3.10, 10.34.200.10, etc.'
    )
    xprint_head(
        '\t             -> regular expression should be begin with ^ and end with $, otherwise handle as normal string'
    )
示例#9
0
def action_git_lines(cmds, key):
    num_cmd = len(cmds)
    if cmds[num_cmd - 1] == '':
        del cmds[num_cmd - 1]
        num_cmd -= 1

    if num_cmd >= 0 and key == XKey.ENTER:
        xprint_new_line('')
        print('\rparsing params and preparing git data...', end='')
        repo_dir, _, _ = get_gnb_dirs('')
        if not repo_dir:
            xprint_new_line('\tNot a git repository')
            return {'flag': True, 'new_input_cmd': ''}
        common_part = '--format=\'%ae\''
        message, author, start, end, before, after, self_dir = parse_commits_cmds(
            cmds)
        start_end = format_start_end(start, end)
        #xprint_head(message + ' ' + author + ' ' + start + ' ' + end + ' ' + before + ' ' + after + ' ' + self_dir)
        system_cmd = 'git log ' + start_end + ' ' + message + ' ' + author + ' ' + before + ' ' + after
        system_cmd = system_cmd + ' ' + common_part + ' ' + self_dir + ' | sort -u'
        system_cmd = re.sub(' +', ' ', system_cmd)
        #xprint_head(system_cmd)
        #os.system(system_cmd)
        child = subprocess.Popen(system_cmd,
                                 shell=True,
                                 stdout=subprocess.PIPE)
        output = child.communicate()[0].split('\n')
        print('\rparsing params and preparing git data... Done', end='')
        parse_lines_mails_output(output, start_end, message, before, after,
                                 self_dir)
        return {'flag': True, 'new_input_cmd': ''}

    show_git_lines_help()
示例#10
0
def show_install_help():
    xprint_new_line('\t# install [PATH]', XPrintStyle.YELLOW)
    xprint_head('\tExample 1: # install')
    xprint_head('\t           -> install ' + XConst.PYFILE_NAME +
                ' in /usr/bin/ as default')
    xprint_head('\tExample 2: # install /bin')
    xprint_head('\t           -> install ' + XConst.PYFILE_NAME + ' in /bin')
示例#11
0
def show_install_help():
    xprint_new_line('\t# cd [ACTION]')
    xprint_head('\tExample 1: # cd install')
    xprint_head('\t           -> only support one ACTION as install currently')
    xprint_head(
        '\t           -> it will install a command named xcd which can be used directly in console'
    )
    xprint_head('\t           -> detail for xcd to be continued')
示例#12
0
def show_log_extract_help():
    xprint_new_line('\t# log extract [DIR] [DEPTH]', XPrintStyle.YELLOW)
    xprint_head('\tExample 1: # log extract')
    xprint_head('\t           -> extract all files in current directory to *_extract/')
    xprint_head('\tExample 2: # log extract /test/')
    xprint_head('\t           -> extract all files in /test/ to /test_extract/')
    xprint_head('\tExample 3: # log extract /test/ 3')
    xprint_head('\t           -> extract files with 3 depth sub-dir in /test/ to /test_extract/')
示例#13
0
def show_gnb_cpnrt_ut_help():
    xprint_new_line('\t# gnb cpnrt ut [PATTERN]', XPrintStyle.YELLOW)
    xprint_head('\tExample 1: # gnb cpnrt ut')
    xprint_head('\t           -> run all ut cases for cpnrt')
    xprint_head('\tExample 2: # gnb cpnrt ut TeidHelperTests')
    xprint_head(
        '\t           -> run ut cases that name contains TeidHelperTests for cpnrt'
    )
示例#14
0
def show_gnb_cpnrt_pytest_help():
    xprint_new_line('\t# gnb cpnrt pytest [PATTERN]', XPrintStyle.YELLOW)
    xprint_head('\tExample 1: # gnb cpnrt pytest')
    xprint_head('\t           -> run all pytest cases for cpnrt')
    xprint_head('\tExample 2: # gnb cpnrt pytest test_case_name')
    xprint_head(
        '\t           -> run pytest cases that name contains test_case_name for cpnrt'
    )
示例#15
0
def show_gnb_cu_mt_help():
    xprint_new_line('\t# gnb cu mt [PATTERN]', XPrintStyle.YELLOW)
    xprint_head('\tExample 1: # gnb cu mt')
    xprint_head('\t           -> run all mt cases for cu')
    xprint_head('\tExample 2: # gnb cu mt TeidHelperTests')
    xprint_head(
        '\t           -> run mt cases that name contains TeidHelperTests for cu'
    )
示例#16
0
def show_remove_result(result):
    xprint_new_line()
    if result == None or len(result) == 0:
        xprint_head('\tno any login history to remove')
        return
    for item in result:
        show_info = '\tremove: name=' + item['name'] + ' ip=' + item[
            'ip'] + ' user='******'user'] + ' password='******'password']
        xprint_head(show_info)
示例#17
0
def action_gnb_cu_ut(cmds, key):
    num_cmd = len(cmds)
    if cmds[num_cmd - 1] == '':
        del cmds[num_cmd - 1]
        num_cmd -= 1

    if num_cmd <= 1 and key == XKey.ENTER:
        repo_dir, sdk5g_dir, build_dir = get_gnb_dirs('cu')
        if not repo_dir:
            xprint_new_line('\tNot a git repository')
            return {'flag': True, 'new_input_cmd': ''}
        if not os.path.exists(build_dir):
            xprint_new_line('\tshould build firstly')
            return {'flag': True, 'new_input_cmd': ''}
        env_path = os.getenv('PATH')
        env_prefix_type = os.getenv('PREFIX_TYPE')
        if not env_prefix_type:
            env_prefix_type = XConst.CU_PREFIX_TYPE
        system_cmd = ''
        if not re.search('sdk5g.+prefix_root_' + env_prefix_type, env_path):
            system_cmd += 'source ' + sdk5g_dir + '/prefix_root_' + env_prefix_type + '/environment-linsee-setup.sh && '
        system_cmd += 'cd ' + build_dir + ' && '
        system_cmd += 'make -j$(nproc) '
        if num_cmd == 1:
            uts = os.popen('cd ' + build_dir + ' && ' + 'ls ./bin | grep -w ' +
                           cmds[0])
            line = uts.readline()
            uts.close()
            if line:
                system_cmd += '&& ./bin/' + cmds[0]
            else:
                system_cmd += '&& '
                xprint_new_line('Searching ' + cmds[0] + ' ...')
                uts = os.popen('cd ' + build_dir + ' && ' + 'grep -lr ' +
                               cmds[0] + ' ./bin/')
                line = uts.readline()
                if not line:
                    xprint_new_line('\tcan not find case include ' + cmds[0])
                    return {'flag': True, 'new_input_cmd': ''}
                while line:
                    system_cmd += 'GTEST_FILTER=*' + cmds[
                        0] + '* ' + line.strip() + ' && '
                    line = uts.readline()
                uts.close()
                system_cmd = system_cmd[0:-3]
        else:
            system_cmd += 'ut'
            xprint_new_line('')
        xprint_head(system_cmd)
        #os.system('find ' + repo_dir + ' -name ut_main.cpp | xargs sed -i \"s/spdlog::level::off/spdlog::level::trace/\"')
        os.system(system_cmd)
        xprint_head('')
        return {'flag': True, 'new_input_cmd': ''}

    show_gnb_cu_ut_help()
示例#18
0
def show_gnb_cprt_ttcn_help():
    xprint_new_line('\t# gnb cprt ttcn [PATTERN] [-]', XPrintStyle.YELLOW)
    xprint_head('\tExample 1: # gnb cprt pytest')
    xprint_head('\t           -> run all ttcn3 cases for cprt')
    xprint_head('\tExample 2: # gnb cprt ttcn test_case_name')
    xprint_head(
        '\t           -> run ttcn cases that name contains test_case_name for cprt'
    )
    xprint_head('\tExample 3: # gnb cprt ttcn test_case_name -')
    xprint_head(
        '\t           -> remove build dirctory and re-compile, then run ttcn cases that name contains test_case_name for cprt'
    )
示例#19
0
def show_gnb_cpnrt_ttcn_help():
    xprint_new_line('\t# gnb cpnrt ttcn [PATTERN] [REPEAT_COUNT]',
                    XPrintStyle.YELLOW)
    xprint_head('\tExample 1: # gnb cpnrt ttcn')
    xprint_head('\t           -> run all ttcn cases for cpnrt')
    xprint_head('\tExample 2: # gnb cpnrt ttcn test_set.test_case_name')
    xprint_head(
        '\t           -> run ttcn cases that name contains test_case_name for cpnrt'
    )
    xprint_head('\tExample 3: # gnb cpnrt ttcn test_case_name 100')
    xprint_head(
        '\t           -> run ttcn cases that name contains test_case_name for cpnrt 100 times'
    )
示例#20
0
def action_gnb_clone(cmds, key):
    num_cmd = len(cmds)
    if cmds[num_cmd - 1] == '':
        del cmds[num_cmd - 1]
        num_cmd -= 1

    if num_cmd == 0 and key == XKey.ENTER:
        xprint_new_line('')
        os.system('git clone ' + XConst.GNB_REPO)
        xprint_head('')
        return {'flag': True, 'new_input_cmd': ''}

    show_gnb_clone()
示例#21
0
def show_gnb_cu_mct_help():
    xprint_new_line('\t# gnb cu mct [PATTERN] [REPEAT_COUNT]',
                    XPrintStyle.YELLOW)
    xprint_head('\tExample 1: # gnb cu mct')
    xprint_head('\t           -> run all ttcn3 cases in mct for cu')
    xprint_head('\tExample 2: # gnb cu mct test_case_name')
    xprint_head(
        '\t           -> run mct cases that name contains test_case_name for cu'
    )
    xprint_head('\tExample 2: # gnb cu mct test_case_name 100')
    xprint_head(
        '\t           -> run mct cases that name contains test_case_name for cu 100 times'
    )
示例#22
0
def action_log_find_path(cmds, key):
    num_cmd = len(cmds)
    if cmds[num_cmd - 1] == '':
        del cmds[num_cmd - 1]
        num_cmd -= 1

    if num_cmd == 1 and key == XKey.ENTER:
        log_type = cmds[0]
        extract_dir = os.getcwd()
        xprint_new_line()
        precheck_log(extract_dir, log_type)
        return {'flag': True, 'new_input_cmd': ''}

    show_log_find_path_help()
示例#23
0
def action_lines(cmds, key):
    num_cmd = len(cmds)
    if cmds[num_cmd - 1] == '':
        del cmds[num_cmd - 1]
        num_cmd -= 1

    lines_dir = './'
    lines_level = XConst.MAX_DIR_DEPTH
    lines_black = ''
    lines_white = ''
    if num_cmd >= 1 and cmds[0] != '-' and key == XKey.ENTER:
        if not os.path.exists(cmds[0]):
            xprint_new_line('\t' + cmds[0] + ' is not exists')
            return {'flag': True, 'new_input_cmd': ''}
        lines_dir = cmds[0]
    if num_cmd >= 2 and cmds[1] != '-' and key == XKey.ENTER:
        if not re.match('^[0-9]+$', cmds[1]):
            xprint_new_line('\tDEPTH should be number, ' + cmds[1] +
                            ' is wrong')
            return {'flag': True, 'new_input_cmd': ''}
        if int(cmds[1]) >= XConst.MAX_DIR_DEPTH or int(cmds[1]) < 1:
            xprint_new_line('\tDEPTH ' + cmds[1] + ' is wrong')
            return {'flag': True, 'new_input_cmd': ''}
        lines_level = int(cmds[1])
    if num_cmd == 3 and key == XKey.ENTER:
        if re.match('^b-', cmds[2]):
            lines_black = cmds[2][2:]
        if re.match('^w-', cmds[2]):
            lines_white = cmds[2][2:]
    if key == XKey.ENTER and num_cmd <= 3:
        xprint_new_line()
        lines_statistic(lines_dir, lines_level, lines_black, lines_white)
        return {'flag': True, 'new_input_cmd': ''}

    show_lines_help()
示例#24
0
def show_gnb_cu_ttcn_help():
    xprint_new_line('\t# gnb cu ttcn [MODULE] [PATTERN] [REPEAT_COUNT]',
                    XPrintStyle.YELLOW)
    xprint_head('\tExample 1: # gnb cu ttcn3 cp_if')
    xprint_head('\t           -> run all ttcn3 cases in cp-if for cu')
    xprint_head(
        '\t           -> MODULE should be cp_if, cp_ue, cp_nb, cp_sb, cp_cl')
    xprint_head('\tExample 2: # gnb cu ttcn3 cp_if test_case_name')
    xprint_head(
        '\t           -> run ttcn3 cases that name contains test_case_name for cu'
    )
    xprint_head('\tExample 2: # gnb cu ttcn3 cp_if test_case_name 100')
    xprint_head(
        '\t           -> run ttcn3 cases that name contains test_case_name for cu 100 times'
    )
示例#25
0
def action_log_sort(cmds, key):
    num_cmd = len(cmds)
    if cmds[num_cmd - 1] == '':
        del cmds[num_cmd - 1]
        num_cmd -= 1

    if num_cmd == 1 and key == XKey.ENTER:
        if not os.path.exists(cmds[0]):
            xprint_new_line('\t' + cmdss[0] + ' is not exists')
            return {'flag': True, 'new_input_cmd': ''}
        sort_contents_in_file(cmds[0], './', 'x')

        return {'flag': True, 'new_input_cmd': ''}

    show_log_sort_help()
示例#26
0
def action_log_find_lifecycle(cmds, key):
    num_cmd = len(cmds)
    if cmds[num_cmd - 1] == '':
        del cmds[num_cmd - 1]
        num_cmd -= 1

    if num_cmd == 1 and key == XKey.ENTER:
        if not os.path.exists(cmds[0]):
            xprint_new_line('\t' + cmdss[0] + ' is not exists')
            return {'flag': True, 'new_input_cmd': ''}
        xprint_new_line('')
        find_lifecycle(cmds[0])
        collect_lifecycle_started_finished(cmds[0])
        return {'flag': True, 'new_input_cmd': ''}

    show_log_find_lifecycle_help()
示例#27
0
def show_login_history(name=None):
    xprint_new_line()
    seq = 0
    count = 0
    f = os.popen('cat ' + XConst.LOGIN_HISTORY_FILE + ' | tr -d \' \' | wc -L')
    max_length = int(f.readline()) + 5
    f.close()
    xlogger.debug('max_length = {}'.format(max_length))
    f = open(XConst.LOGIN_HISTORY_FILE, 'r')
    line = f.readline()
    new_line = ''
    match_name_list = []
    while line:
        sub_cmds = line.strip('\n').split()
        if len(sub_cmds) != XConst.NUM_ELEM_PER_LOGIN_HISTORY_ITEM:
            line = f.readline()
            continue
        xlogger.debug('NAME: {}, IP: {}, USER: {}, PASSWORD: {}'.format(
            sub_cmds[0], sub_cmds[1], sub_cmds[2], sub_cmds[3]))
        if name:
            if re.match(name, sub_cmds[0]) == None:
                line = f.readline()
                continue
            match_name_list.append(sub_cmds[0])
        new_item = sub_cmds[0] + ': ' + sub_cmds[2] + '@' + sub_cmds[
            1] + ' *' + sub_cmds[3]
        len_new_item = len(new_item)
        new_item = format_color_string(
            sub_cmds[0], XPrintStyle.GREEN_U
        ) + ': ' + sub_cmds[2] + '@' + sub_cmds[1] + ' *' + sub_cmds[3]
        if len_new_item < max_length:
            new_item = new_item + ' ' * (max_length - len_new_item)
        new_line = new_line + '\t' + new_item
        seq += 1
        count += 1
        if seq == XConst.NUM_ITEM_PER_LOGIN_HISTORY_LINE:
            seq = 0
            xprint_head(new_line)
            new_line = ''
        line = f.readline()

    f.close()
    if seq:
        xprint_head(new_line)
    if count == 0 and name == None:
        xprint_head('\tthere is no login history')
    return match_name_list
示例#28
0
def action_log_find_context(cmds, key):
    num_cmd = len(cmds)
    if cmds[num_cmd - 1] == '':
        del cmds[num_cmd - 1]
        num_cmd -= 1

    if num_cmd == 1 and key == XKey.ENTER:
        xprint_new_line(' ')
        ueidcus = []
        if cmds[0] == "cpue":
            ueidcus = find_and_show_id_map()
        find_warn_logs()
        find_error_logs()
        find_all_ueidcus(ueidcus)

        return {'flag': True, 'new_input_cmd': ''}

    show_log_find_context_help()
示例#29
0
def show_git_commits_help():
    xprint_new_line('\t# git commits [message=PATTERN] [author=PATTERN]',
                    XPrintStyle.YELLOW)
    xprint_head('\t#             [start=commit id] [end=commit id]',
                XPrintStyle.YELLOW)
    xprint_head('\t#             [before=date] [after=date]',
                XPrintStyle.YELLOW)
    xprint_head('\t#             [dir=path]', XPrintStyle.YELLOW)
    xprint_head(
        '\tExample 1: # gnb commits start=3357da6805e0 end=e943f54c2b5e dir=.')
    xprint_head(
        '\t           -> show all commits in current dir between 3357da6805e0 and e943f54c2b5e'
    )
    xprint_head(
        '\tExample 2: # gnb commits message=5GC002497 author=feng after=2020-12-31 dir=src/ dir=UT/'
    )
    xprint_head(
        '\t           -> show all fengh\'s commits for 5GC002497 in src/ or UT/ after 2020-12-31'
    )
示例#30
0
def action_install(cmds, key):
    num_cmd = len(cmds)
    if cmds[num_cmd - 1] == '':
        del cmds[num_cmd - 1]
        num_cmd -= 1

    install_dir = '/usr/bin'
    if num_cmd == 1:
        if not os.path.exists(cmds[0]):
            xprint_new_line('\t' + cmds[0] + ' is not exists')
            return {'flag': True, 'new_input_cmd': ''}
        install_dir = cmds[0]
    if key == XKey.ENTER and num_cmd <= 1:
        xprint_new_line()
        xprint_same_line('\tinstalling ')
        install_myself(install_dir)
        return {'flag': True, 'new_input_cmd': ''}

    show_install_help()