Exemplo n.º 1
0
def compute_normalized_license(package, resource, codebase):
    """
    Return a normalized license expression string detected from a list of
    declared license items.
    """
    declared_licenses = package.declared_license
    if not declared_licenses:
        return

    declared_licenses = set(declared_licenses)

    license_expressions = []

    parent = resource.parent(codebase)
    # FIXME: we should be able to get the path relatively to the ABOUT file resource
    for child in parent.children(codebase):
        if child.name in declared_licenses:
            licenses = get_licenses(child.location)
            if not licenses:
                license_expressions.append('unknown')
            else:
                license_expressions.extend(
                    licenses.get('license_expressions', []))

    return combine_expressions(license_expressions)
Exemplo n.º 2
0
 def test_get_license_with_expression(self):
     test_file = self.get_test_loc('api/license/apache-1.0.txt')
     results = api.get_licenses(test_file)
     expected = [
         'apache-1.0',
         'gpl-2.0 WITH linux-syscall-exception-gpl OR linux-openib'
     ]
     assert expected == results['license_expressions']
Exemplo n.º 3
0
def scan_one(input_file, copyright, license, verbose=False):
    """
    Scan one file and return scanned data.
    """
    if verbose:
        click.secho('Scanning: %(input_file)s: ' % locals(), nl=False, fg='blue')
    data = {'location': input_file}
    if copyright:
        if verbose:
            click.secho('copyrights. ', nl=False, fg='green')
        data['copyrights'] = list(get_copyrights(input_file))
    if license:
        if verbose:
            click.secho('licenses. ', nl=False, fg='green')
        data['licenses'] = list(get_licenses(input_file))
    if verbose:
        click.secho('', nl=True)
    return data
Exemplo n.º 4
0
def detect_license_in_unstructured_text(location):
    """
    Return a detected license expression string from a file at `location`
    """
    from scancode.api import get_licenses
    detected = get_licenses(location)
    if not detected:
        # we have no match: return an unknown key
        return 'unknown'

    detected_expressions = detected['license_expressions']

    if TRACE:
        logger_debug(
            'detect_license_in_unstructured_text: detected_expressions:',
            detected_expressions)

    return combine_expressions(detected_expressions)
Exemplo n.º 5
0
    def compute_normalized_license(self):
        """
        Return a normalized license expression string detected from a list of
        declared license items.
        """
        declared_license = self.declared_license
        manifest_parent_path = self.root_path

        if not declared_license or not manifest_parent_path:
            return

        license_expressions = []
        for license_file in declared_license:
            license_file_path = os.path.join(manifest_parent_path, license_file)
            if os.path.exists(license_file_path) and os.path.isfile(license_file_path):
                licenses = get_licenses(license_file_path)
                license_expressions.extend(licenses.get('license_expressions', []))

        return combine_expressions(license_expressions)
Exemplo n.º 6
0
def scan_one(input_file,
             copyright,
             license,
             verbose=False):  # @ReservedAssignment
    """
    Scan one file and return scanned data.
    """
    if verbose:
        click.secho('Scanning: %(input_file)s: ' % locals(),
                    nl=False,
                    fg='blue')
    data = {'location': input_file}
    if copyright:
        if verbose:
            click.secho('copyrights. ', nl=False, fg='green')
        data['copyrights'] = list(get_copyrights(input_file))
    if license:
        if verbose:
            click.secho('licenses. ', nl=False, fg='green')
        data['licenses'] = list(get_licenses(input_file))
    if verbose:
        click.secho('', nl=True)
    return data
Exemplo n.º 7
0
 def test_get_license_returns_correct_lines(self):
     test_file = self.get_test_loc('api/license/correct_lines2')
     results = api.get_licenses(test_file)
     assert ['mit'] == results['license_expressions']
     assert 2 == results['licenses'][0]['start_line']
     assert 4 == results['licenses'][0]['end_line']
Exemplo n.º 8
0
 def test_get_license_with_expression2(self):
     test_file = self.get_test_loc('api/license/expression.RULE')
     results = api.get_licenses(test_file)
     expected = ['gpl-2.0 WITH linux-syscall-exception-gpl OR linux-openib']
     assert results['license_expressions'] == expected
Exemplo n.º 9
0
import scancode
from scancode import api

print('Hello World')
ordered_dictionary = api.get_licenses('../scancode-toolkit-2.0.0.rc2/src/commoncode/command.py')
for i in ordered_dictionary:
	print(i)
	print('Printing')
print('Goodbye')