Beispiel #1
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()
Beispiel #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()
Beispiel #3
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()
Beispiel #4
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()
Beispiel #5
0
def action_gnb_cprt_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('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):
            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.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 += 'export DEBUG_LOG=1 && '
        system_cmd += 'cd ' + build_dir + ' && '
        if num_cmd == 1:
            system_cmd += 'GTEST_FILTER=*' + cmds[0] + '* '
        system_cmd += 'ninja ut'
        xprint_new_line('')
        xprint_head(system_cmd)
        os.system(system_cmd)
        xprint_head('')
        return {'flag': True, 'new_input_cmd': ''}

    show_gnb_cprt_ut_help()
Beispiel #6
0
def action_gnb_cprt_pytest(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('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):
            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.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 + ' && '
        if num_cmd == 0:
            system_cmd += 'cd ' + build_dir + ' && '
            system_cmd += '../gnb/buildscript/CP-RT/run sct_run'
        elif num_cmd == 1:
            system_cmd += 'cd ' + repo_dir + '/cplane/CP-RT/CP-RT/SCT/Pytest/ && '
            system_cmd += './cprt-pytest ' + cmds[0]
        xprint_new_line('')
        os.system(system_cmd)
        xprint_head('')
        return {'flag': True, 'new_input_cmd': ''}

    show_gnb_cprt_pytest_help()
Beispiel #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()
Beispiel #8
0
def action_gnb_cu_pytest(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 sct'
        if num_cmd == 1:
            system_cmd += ' testfilter=' + cmds[0]
        xprint_new_line('')
        os.system(system_cmd)
        xprint_head('')
        return {'flag': True, 'new_input_cmd': ''}

    show_gnb_cu_pytest_help()
Beispiel #9
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()
Beispiel #10
0
def action_gnb_codeformat(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:
        head_offset = 0
        if num_cmd == 1:
            if not cmds[0].isdigit():
                xprint_new_line('\tshould be number, ' + cmds[0] + ' is wrong')
                return {'flag': True, 'new_input_cmd': ''}
            head_offset = int(cmds[0])

        repo_dir, _, _ = get_gnb_dirs('')
        if not repo_dir:
            xprint_new_line('\tNot a git repository')
            return {'flag': True, 'new_input_cmd': ''}
        if not os.path.exists(XConst.CLANG_FORMAT):
            xprint_new_line('\tclang-format command is not found')
            return {'flag': True, 'new_input_cmd': ''}
        system_cmd = 'cd ' + repo_dir + ' && '
        system_cmd += XConst.CLANG_FORMAT
        system_cmd += ' -style=file '
        f = os.popen('cd ' + repo_dir +
                     ' && git diff --stat --name-only HEAD~' +
                     str(head_offset))
        line = f.readline().strip()
        xprint_new_line('')
        while line:
            line = repo_dir + '/' + line
            file_ext = os.path.splitext(line)
            if len(file_ext) <= 1 or file_ext[1] not in ('.hpp', '.cpp', '.h',
                                                         '.c', '.cc'):
                line = f.readline().strip()
                continue
            if not os.path.exists(line):
                line = f.readline().strip()
                continue
            shutil.copy(line, '{}.orig'.format(line))
            new_cmd = system_cmd + ' -i ' + line
            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(line))
            line = f.readline().strip()
        f.close()
        xprint_head('')
        return {'flag': True, 'new_input_cmd': ''}

    show_gnb_codeformat_help()
Beispiel #11
0
def action_gnb_cpnrt_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('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):
            xprint_new_line('\tshould build firstly')
            return {'flag': True, 'new_input_cmd': ''}
        runtime_dir = build_dir + '/runtime_output'
        library_dir = build_dir + '/libs'
        tests_dir = build_dir + '/tests_output'
        ut_output_file = tests_dir + '/ut.xml'
        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 --warn-uninitialized -Werror=dev'
        system_cmd += ' -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + library_dir
        system_cmd += ' -DCMAKE_RUNTIME_OUTPUT_DIRECTORY=' + runtime_dir
        system_cmd += ' -DCMAKE_TEST_OUTPUT_DIRECTORY=' + tests_dir
        system_cmd += ' -DBUILD_TESTS=ON -DBUILD_TTCN3_SCT=OFF'
        system_cmd += ' ' + repo_dir + '/cplane/CP-NRT/ && '
        system_cmd += 'make -j$(nproc) cp-nrt_ut && '
        system_cmd += 'export GTEST_OUTPUT=xml:' + ut_output_file + ' && '
        if num_cmd == 1:
            system_cmd += ' GTEST_FILTER=*' + cmds[0] + '* '
        system_cmd += runtime_dir + '/cp-nrt_ut'
        xprint_new_line('')
        os.system(system_cmd)
        xprint_head('')
        return {'flag': True, 'new_input_cmd': ''}

    show_gnb_cpnrt_build_help()
Beispiel #12
0
def action_gnb_cpnrt_sdk(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, _ = get_gnb_dirs('cpnrt')
        if not repo_dir:
            xprint_new_line('\tNot a git repository')
            return {'flag': True, 'new_input_cmd': ''}
        if os.path.exists(sdk5g_dir):
            xprint_new_line('\tsdk5g is already exits, should remove firstly')
            return {'flag': True, 'new_input_cmd': ''}
        system_cmd = 'export SDK5G_DIR=' + sdk5g_dir + ' && '
        system_cmd += repo_dir + '/' + XConst.CPNRT_SDK_SHELL + ' -t all'
        xprint_new_line('')
        os.system(system_cmd)
        xprint_head('')
        return {'flag': True, 'new_input_cmd': ''}

    show_gnb_cpnrt_sdk_help()