コード例 #1
0
ファイル: tasks.py プロジェクト: hyounes4560/scancode.io
def run_scancode(download_location, output_file):
    """
    Run the scanning task where `location` is the path containing the archive.
    """
    extractcode_args = [
        get_bin_executable("extractcode"),
        shlex.quote(str(download_location)),
    ]
    extract_exitcode, extract_output = run_command(extractcode_args)

    scan_input = get_scan_input_location(download_location)
    if not scan_input:
        return 1, "Scan input could not be determined."

    scancode_args = [
        get_bin_executable("scancode"),
        shlex.quote(str(scan_input)),
        "--classify",
        "--consolidate",
        "--copyright",
        "--email",
        "--info",
        "--is-license-text",
        "--license",
        "--license-clarity-score",
        "--license-text",
        "--package",
        "--summary",
        "--summary-key-files",
        "--url",
        f"--processes {SCAN_PROCESSES}",
        f"--max-in-memory {SCAN_MAX_IN_MEMORY}",
        f"--json-pp {output_file}",
    ]
    scan_exitcode, scan_output = run_command(scancode_args)

    exitcode = extract_exitcode + scan_exitcode
    output = "\n".join([extract_output, scan_output])
    return exitcode, output
コード例 #2
0
def run_extractcode(location, options=None, raise_on_error=False):
    """
    Extract content at `location` with extractcode.
    Optional arguments for the `extractcode` executable can be provided with the
    `options` list.
    If `raise_on_error` is enabled, a ScancodeError will be raised if the
    exitcode greater than 0.
    """
    extractcode_args = [
        pipes.get_bin_executable("extractcode"),
        shlex.quote(location),
    ]

    if options:
        extractcode_args.extend(options)

    exitcode, output = pipes.run_command(extractcode_args)
    if exitcode > 0 and raise_on_error:
        raise ScancodeError(output)

    return exitcode, output
コード例 #3
0
def run_scancode(location, output_file, options, raise_on_error=False):
    """
    Scan `location` content and write results into `output_file`.
    The `scancode` executable will be run using the provided `options`.
    If `raise_on_error` is enabled, a ScancodeError will be raised if the
    exitcode greater than 0.
    """
    default_options = getattr(settings, "SCANCODE_DEFAULT_OPTIONS", [])

    scancode_args = [
        pipes.get_bin_executable("scancode"),
        shlex.quote(location),
        *default_options,
        *options,
        f"--json-pp {shlex.quote(output_file)}",
    ]

    exitcode, output = pipes.run_command(scancode_args)
    if exitcode > 0 and raise_on_error:
        raise ScancodeError(output)

    return exitcode, output