Ejemplo n.º 1
0
def handle_list_results(args):
    client = setupClient(args.host, args.port, '/')

    run_info = check_run_names(client, [args.name])

    run_id, run_date = run_info.get(args.name)

    limit = 500
    offset = 0

    filters = []
    if args.suppressed:
        report_filter = codeCheckerDBAccess.ttypes.ReportFilter(
            suppressed=True)
    else:
        report_filter = codeCheckerDBAccess.ttypes.ReportFilter(
            suppressed=False)

    add_filter_conditions(report_filter, args.filter)
    filters.append(report_filter)

    all_results = []
    results = client.getRunResults(run_id, limit, offset, None, filters)

    while results:
        all_results.extend(results)
        offset += limit
        results = client.getRunResults(run_id, limit, offset, None, filters)

    if args.output_format == 'json':
        print(CmdLineOutputEncoder().encode(all_results))
    else:
        rows = []
        if args.suppressed:
            rows.append(
                ('File', 'Checker', 'Severity', 'Msg', 'Suppress comment'))
        else:
            rows.append(('File', 'Checker', 'Severity', 'Msg'))

        for res in all_results:
            bug_line = res.lastBugPosition.startLine
            checked_file = res.checkedFile + ' @ ' + str(bug_line)
            sev = shared.ttypes.Severity._VALUES_TO_NAMES[res.severity]

            if args.suppressed:
                rows.append((checked_file, res.checkerId, sev, res.checkerMsg,
                             res.suppressComment))
            else:
                rows.append((checked_file, res.checkerId, sev, res.checkerMsg))

        if args.output_format == 'csv':
            writer = csv.writer(sys.stdout)
            writer.writerows(rows)
        else:
            print_table(rows)
Ejemplo n.º 2
0
def handle_list_result_types(args):
    client = setupClient(args.host, args.port, '/')

    filters = []
    if args.suppressed:
        report_filter = codeCheckerDBAccess.ttypes.ReportFilter(
            suppressed=True)
    else:
        report_filter = codeCheckerDBAccess.ttypes.ReportFilter(
            suppressed=False)

    add_filter_conditions(report_filter, args.filter)
    filters.append(report_filter)

    if args.all_results:
        items = check_run_names(client, None).items()
    else:
        items = []
        run_info = check_run_names(client, args.names)
        for name in args.names:
            items.append((name, run_info.get(name)))

    results_collector = []
    for name, run_info in items:
        run_id, run_date = run_info
        results = client.getRunResultTypes(run_id, filters)

        if args.output_format == 'json':
            results_collector.append({name: results})
        else:  # plaintext, csv
            print('Check date: ' + run_date)
            print('Check name: ' + name)
            rows = []
            rows.append(('Checker', 'Severity', 'Count'))
            for res in results:
                sev = shared.ttypes.Severity._VALUES_TO_NAMES[res.severity]
                rows.append((res.checkerId, sev, str(res.count)))

            if args.output_format == 'csv':
                writer = csv.writer(sys.stdout)
                writer.writerows(rows)
            else:
                print_table(rows)

    if args.output_format == 'json':
        print(CmdLineOutputEncoder().encode(results_collector))
Ejemplo n.º 3
0
def handle_list_runs(args):
    client = setupClient(args.host, args.port, '/')
    runs = client.getRunData()

    if args.output_format == 'json':
        results = []
        for run in runs:
            results.append({run.name: run})
        print(CmdLineOutputEncoder().encode(results))

    else:  # plaintext, csv
        rows = [('Name', 'ResultCount', 'RunDate')]
        for run in runs:
            rows.append((run.name, str(run.resultCount), run.runDate))

        if args.output_format == 'csv':
            writer = csv.writer(sys.stdout)
            writer.writerows(rows)
        else:
            print_table(rows)
Ejemplo n.º 4
0
    def printResult(getterFn, baseid, newid, suppr, output_format):
        report_filter = [
            codeCheckerDBAccess.ttypes.ReportFilter(suppressed=suppr)
        ]
        add_filter_conditions(report_filter[0], args.filter)

        sort_type = None
        limit = 500
        offset = 0

        all_results = []
        results = getterFn(baseid, newid, limit, offset, sort_type,
                           report_filter)

        while results:
            all_results.extend(results)
            offset += limit
            results = getterFn(baseid, newid, limit, offset, sort_type,
                               report_filter)

        if output_format == 'json':
            print(CmdLineOutputEncoder().encode(all_results))
        else:
            rows = []
            rows.append(('File', 'Checker', 'Severity', 'Msg'))
            for res in all_results:
                bug_line = res.lastBugPosition.startLine
                sev = shared.ttypes.Severity._VALUES_TO_NAMES[res.severity]
                checked_file = res.checkedFile + ' @ ' + str(bug_line)
                rows.append((checked_file, res.checkerId, sev, res.checkerMsg))

            if output_format == 'csv':
                writer = csv.writer(sys.stdout)
                writer.writerows(rows)
            else:
                print_table(rows)
Ejemplo n.º 5
0
def handle_server(args):
    """
    Starts the report viewer server.
    """
    if not host_check.check_zlib():
        sys.exit(1)

    workspace = args.workspace

    if (args.list or args.stop or args.stop_all) and \
            not (args.list ^ args.stop ^ args.stop_all):
        print("CodeChecker server: error: argument -l/--list and -s/--stop"
              "and --stop-all are mutually exclusive.")
        sys.exit(2)

    if args.list:
        instances = instance_manager.list()

        instances_on_multiple_hosts = any(
            True for inst in instances
            if inst['hostname'] != socket.gethostname())
        if not instances_on_multiple_hosts:
            rows = [('Workspace', 'View port')]
        else:
            rows = [('Workspace', 'Computer host', 'View port')]

        for instance in instance_manager.list():
            if not instances_on_multiple_hosts:
                rows.append((instance['workspace'], str(instance['port'])))
            else:
                rows.append(
                    (instance['workspace'], instance['hostname']
                     if instance['hostname'] != socket.gethostname() else '',
                     str(instance['port'])))

        print("Your running CodeChecker servers:")
        util.print_table(rows)
        sys.exit(0)
    elif args.stop or args.stop_all:
        for i in instance_manager.list():
            # A STOP only stops the server associated with the given workspace
            # and view-port.
            if i['hostname'] != socket.gethostname() or (
                    args.stop
                    and not (i['port'] == args.view_port and os.path.abspath(
                        i['workspace']) == os.path.abspath(workspace))):
                continue

            try:
                util.kill_process_tree(i['pid'])
                LOG.info("Stopped CodeChecker server running on port {0} "
                         "in workspace {1} (PID: {2})".format(
                             i['port'], i['workspace'], i['pid']))
            except:
                # Let the exception come out if the commands fail
                LOG.error("Couldn't stop process PID #" + str(i['pid']))
                raise
        sys.exit(0)

    # WARNING
    # In case of SQLite args.dbaddress default value is used
    # for which the is_localhost should return true.
    if util.is_localhost(args.dbaddress) and not os.path.exists(workspace):
        os.makedirs(workspace)

    suppress_handler = generic_package_suppress_handler.\
        GenericSuppressHandler()
    if args.suppress is None:
        LOG.warning('No suppress file was given, suppressed results will '
                    'be only stored in the database.')
    else:
        if not os.path.exists(args.suppress):
            LOG.error('Suppress file ' + args.suppress + ' not found!')
            sys.exit(1)

    context = generic_package_context.get_context()
    context.codechecker_workspace = workspace
    session_manager.SessionManager.CodeChecker_Workspace = workspace
    context.db_username = args.dbusername

    check_env = analyzer_env.get_check_env(context.path_env_extra,
                                           context.ld_lib_path_extra)

    sql_server = SQLServer.from_cmdline_args(args,
                                             context.codechecker_workspace,
                                             context.migration_root, check_env)
    conn_mgr = client.ConnectionManager(sql_server, args.check_address,
                                        args.check_port)
    if args.check_port:
        LOG.debug('Starting CodeChecker server and database server.')
        sql_server.start(context.db_version_info,
                         wait_for_start=True,
                         init=True)
        conn_mgr.start_report_server()
    else:
        LOG.debug('Starting database.')
        sql_server.start(context.db_version_info,
                         wait_for_start=True,
                         init=True)

    # Start database viewer.
    db_connection_string = sql_server.get_connection_string()

    suppress_handler.suppress_file = args.suppress
    LOG.debug('Using suppress file: ' + str(suppress_handler.suppress_file))

    checker_md_docs = os.path.join(context.doc_root, 'checker_md_docs')
    checker_md_docs_map = os.path.join(checker_md_docs, 'checker_doc_map.json')
    with open(checker_md_docs_map, 'r') as dFile:
        checker_md_docs_map = json.load(dFile)

    package_data = {
        'www_root': context.www_root,
        'doc_root': context.doc_root,
        'checker_md_docs': checker_md_docs,
        'checker_md_docs_map': checker_md_docs_map,
        'version': context.package_git_tag
    }

    try:
        client_db_access_server.start_server(package_data, args.view_port,
                                             db_connection_string,
                                             suppress_handler,
                                             args.not_host_only, context)
    except socket.error as err:
        if err.errno == errno.EADDRINUSE:
            LOG.error("Server can't be started, maybe the given port number "
                      "({}) is already used. Check the connection "
                      "parameters.".format(args.view_port))
            sys.exit(1)
        else:
            raise