コード例 #1
0
def cli(license_dir, verbose):
    """
    Create one SPDX tag-value document for each non-SPDX ScanCode licenses.
    Store these in the DIR directory
    """

    base_kwargs = dict(
        license=True,
        license_text=True,
        info=True,
        strip_root=True,
        quiet=True,
        return_results=False,
    )

    licenses_by_key = load_licenses(with_deprecated=False)

    for i, lic in enumerate(licenses_by_key.values()):
        ld = lic.to_dict()

        if lic.spdx_license_key:
            if verbose:
                click.echo(
                    "Skipping ScanCode: {key} that is an SPDX license: {spdx_license_key}"
                    .format(**ld))
            continue

        if not lic.text_file or not os.path.exists(lic.text_file):
            if verbose:
                click.echo("Skipping license without text: {key}".format(**ld))
            continue

        if lic.category not in FOSS_CATEGORIES:
            if verbose:
                click.echo("Skipping non FOSS license: {key}".format(**ld))
            continue

        output = "licenseref-scancode-{key}.spdx".format(**ld)
        output = os.path.join(license_dir, output)

        if verbose:
            click.echo(
                "Creating SPDX document for license: {key}".format(**ld))
            click.echo("at: {output}".format(**locals()))

        with io.open(output, "w", encoding="utf-8") as ouput_file:
            kwargs = dict(input=lic.text_file, spdx_tv=ouput_file)
            kwargs.update(base_kwargs)
            run_scan(**kwargs)
コード例 #2
0
def test_can_call_run_scan_as_a_function():
    from scancode.cli import run_scan
    test_dir = test_env.get_test_loc('license', copy=True)
    rc, results = run_scan(test_dir, license=True, copyright=True, return_results=True)
    assert rc
    assert len(results['files']) == 2
    assert not results['headers'][0]['errors']
コード例 #3
0
def test_run_scan_includes_outdated_in_extra():
    from scancode.cli import run_scan
    test_dir = test_env.get_test_loc('license', copy=True)
    rc, results = run_scan(test_dir,
                           outdated='out of date',
                           return_results=True)
    assert rc
    assert results['headers'][0]['extra_data']['OUTDATED'] == 'out of date'
コード例 #4
0
ファイル: scanserv.py プロジェクト: sthagen/scancode-toolkit
def run_scan(location, **kwargs):
    from scancode import cli

    pretty = kwargs.pop("pretty", True)
    return as_json(cli.run_scan(location, **kwargs), pretty=pretty)
コード例 #5
0
def run_scan(scan_kwargs):
    from scancode import cli
    print('Running scan for: {}'.format(scan_kwargs.get('input', '')))
    success, _results = cli.run_scan(**scan_kwargs)
    return success