Exemple #1
0
def print_full_report(image):
    '''Given an image, go through the Origins object and collect all the
    notices for the image, layers and packages'''
    notes = ''
    for image_origin in image.origins.origins:
        notes = notes + content.print_notices(image_origin, '', '\t')
    for layer in image.layers:
        if layer.import_image:
            notes = notes + print_full_report(layer.import_image)
        else:
            if len(layer.origins.origins) == 0:
                notes += '\tLayer: {0}:\n'.format(layer.fs_hash[:10])
            else:
                for layer_origin in layer.origins.origins:
                    notes = notes + content.print_notices(
                        layer_origin, '\t', '\t\t')
            (layer_pkg_list, layer_license_list,
             file_level_licenses) = get_layer_info_list(layer)
            # Collect files + packages + licenses in the layer
            notes += formats.layer_file_licenses_list.format(
                list=file_level_licenses)
            notes += formats.layer_packages_list.format(
                list=", ".join(layer_pkg_list) if layer_pkg_list else 'None')
            notes += formats.layer_licenses_list.format(list=", ".join(
                layer_license_list) if layer_license_list else 'None')
            notes = notes + formats.package_demarkation
    return notes
Exemple #2
0
def print_full_report(image):
    '''Given an image, go through the Origins object and collect all the
    notices for the image, layers and packages'''
    notes = ''
    for image_origin in image.origins.origins:
        notes = notes + content.print_notices(image_origin, '', '\t')
    for layer in image.layers:
        if layer.import_image:
            notes = notes + print_full_report(layer.import_image)
        else:
            for layer_origin in layer.origins.origins:
                notes = notes + content.print_notices(layer_origin,
                                                      '\t', '\t\t')
            layer_pkg_list = []
            layer_license_list = []
            for package in layer.packages:
                pkg = package.name + "-" + package.version
                if pkg not in layer_pkg_list and pkg:
                    layer_pkg_list.append(pkg)
                if package.pkg_license not in layer_license_list and \
                        package.pkg_license:
                    layer_license_list.append(package.pkg_license)
            # Collect packages + licenses in the layer
            notes = notes + formats.layer_packages_list.format(
                list=", ".join(layer_pkg_list) if layer_pkg_list else 'None')
            notes = notes + formats.layer_licenses_list.format(list=", ".join(
                layer_license_list) if layer_license_list else 'None')
            notes = notes + formats.package_demarkation
    return notes
Exemple #3
0
def print_full_report(image, print_inclusive):
    '''Generate a report for:
        1. Full image if image.load_until_layer is 0
        2. Only layer image.load_until_layer if print_inclusive is False
        3. Layers up to image.load_until_layer if print_inclusive is True
    Goes through the Origins object and collects all necessary (as outlined
    above) notices for the image, layers and packages'''

    notes = ''
    for image_origin in image.origins.origins:
        notes = notes + content.print_notices(image_origin, '', '\t')

    # collect extension's header per layer
    headers = get_extension_headers(image.layers)
    for header in headers:
        notes = notes + header + '\n\n'

    for layer in image.layers:
        if image.load_until_layer != 0 and \
           layer.layer_index is not image.load_until_layer and \
           print_inclusive is False:
            continue
        if layer.import_image:
            notes = notes + print_full_report(layer.import_image,
                                              print_inclusive)
        else:
            notes += print_layer_report(layer)
            notes += formats.package_demarkation
    return notes
Exemple #4
0
def print_full_report(image):
    '''Given an image, go through the Origins object and collect all the
    notices for the image, layers and packages'''
    notes = ''
    for image_origin in image.origins.origins:
        notes = notes + content.print_notices(image_origin, '', '\t')

    # collect extension's header per layer
    headers = get_extension_headers(image.layers)
    for header in headers:
        notes = notes + header + '\n\n'

    for layer in image.layers:
        if layer.import_image:
            notes = notes + print_full_report(layer.import_image)
        else:
            notes = notes + get_layer_notices(layer)
            (layer_pkg_list, layer_license_list,
             file_level_licenses) = get_layer_info_list(layer)
            # Collect files + packages + licenses in the layer
            notes += formats.layer_file_licenses_list.format(
                list=file_level_licenses)
            notes += formats.layer_packages_list.format(
                list=", ".join(layer_pkg_list) if layer_pkg_list else 'None')
            notes += formats.layer_licenses_list.format(list=", ".join(
                layer_license_list) if layer_license_list else 'None')
            notes = notes + formats.package_demarkation
    return notes
Exemple #5
0
def get_package_comment(package):
    '''Given a package object, return a PackageComment string for a list of
    NoticeOrigin objects'''
    comment = ''
    if package.origins.origins:
        for notice_origin in package.origins.origins:
            comment = comment + content.print_notices(notice_origin, '', '\t')
    return comment
Exemple #6
0
def print_full_report(image):
    '''Given an image, go through the Origins object and collect all the
    notices for the image, layers and packages'''
    notes = ''
    for image_origin in image.origins.origins:
        notes = notes + content.print_notices(image_origin, '', '\t')
    for layer in image.layers:
        if layer.import_image:
            notes = notes + print_full_report(layer.import_image)
        else:
            if len(layer.origins.origins) == 0:
                notes += '\tLayer: {0}:\n'.format(layer.fs_hash[:10])
            else:
                for layer_origin in layer.origins.origins:
                    notes = notes + content.print_notices(
                        layer_origin, '\t', '\t\t')
            layer_pkg_list = []
            layer_license_list = []
            layer_file_licenses_list = []
            file_level_licenses = None

            for f in layer.files:
                layer_file_licenses_list.extend(f.license_expressions)

            layer_file_licenses_list = list(set(layer_file_licenses_list))
            if layer_file_licenses_list:
                file_level_licenses = ", ".join(layer_file_licenses_list)

            for package in layer.packages:
                pkg = package.name + "-" + package.version
                if pkg not in layer_pkg_list and pkg:
                    layer_pkg_list.append(pkg)
                if package.pkg_license not in layer_license_list and \
                        package.pkg_license:
                    layer_license_list.append(package.pkg_license)

            # Collect files + packages + licenses in the layer
            notes += formats.layer_file_licenses_list.format(
                list=file_level_licenses)
            notes += formats.layer_packages_list.format(
                list=", ".join(layer_pkg_list) if layer_pkg_list else 'None')
            notes += formats.layer_licenses_list.format(list=", ".join(
                layer_license_list) if layer_license_list else 'None')
            notes = notes + formats.package_demarkation
    return notes
Exemple #7
0
def get_package_comment(package_obj):
    '''Return a PackageComment tag-value text block for a list of
    NoticeOrigin objects'''
    comment = ''
    if package_obj.origins.origins:
        for notice_origin in package_obj.origins.origins:
            comment = comment + content.print_notices(notice_origin, '', '\t')
        return spdx_formats.package_comment.format(comment=comment)
    return comment
Exemple #8
0
def get_layer_comment(layer_obj):
    '''Return a PackageComment tag-value text block for a list of NoticeOrigin
    objects for the given layer object'''
    comment = ''
    if not layer_obj.origins.is_empty():
        for notice_origin in layer_obj.origins.origins:
            comment = comment + content.print_notices(
                notice_origin, '', '\t')
        return spdx_formats.package_comment.format(comment=comment)
    return comment
Exemple #9
0
def get_layer_package_comment(layer_obj):
    '''Return a package comment string value for a list of NoticeOrigin
    objects for the given layer object'''
    comment = ''
    if "headers" in layer_obj.extension_info.keys():
        for header in layer_obj.extension_info.get("headers"):
            comment += header
            comment += '\n'
    if not layer_obj.origins.is_empty():
        for notice_origin in layer_obj.origins.origins:
            comment += content.print_notices(notice_origin, '', '\t')
    return comment
Exemple #10
0
def get_layer_notices(layer):
    '''
    Given a image layer, collect all notices attached
    to it.
    '''
    notices = ''
    if len(layer.origins.origins) == 0:
        notices = '\tLayer {0}:\n'.format(layer.layer_index)
    else:
        for layer_origin in layer.origins.origins:
            notices += content.print_notices(layer_origin, '\t', '\t\t')

    return notices
Exemple #11
0
def get_layer_comment(layer_obj):
    '''Return a PackageComment tag-value text block for a list of NoticeOrigin
    objects for the given layer object'''
    comment = ''
    # add any headers here
    if "headers" in layer_obj.extension_info.keys():
        for header in layer_obj.extension_info.get("headers"):
            comment += header + '\n'
    if not layer_obj.origins.is_empty():
        for notice_origin in layer_obj.origins.origins:
            comment = comment + content.print_notices(notice_origin, '', '\t')
        return spdx_formats.package_comment.format(comment=comment)
    return comment
Exemple #12
0
def print_full_report(image, print_inclusive):
    '''Generate a report for:
        1. Full image if image.load_until_layer is 0
        2. Only layer image.load_until_layer if print_inclusive is False
        3. Layers up to image.load_until_layer if print_inclusive is True
    Goes through the Origins object and collects all necessary (as outlined
    above) notices for the image, layers and packages'''

    notes = ''
    for image_origin in image.origins.origins:
        notes = notes + content.print_notices(image_origin, '', '\t')

    # collect extension's header per layer
    headers = get_extension_headers(image.layers)
    for header in headers:
        notes = notes + header + '\n\n'

    for layer in image.layers:
        if image.load_until_layer != 0 and \
           layer.layer_index is not image.load_until_layer and \
           print_inclusive is False:
            continue
        if layer.import_image:
            notes = notes + print_full_report(layer.import_image,
                                              print_inclusive)
        else:
            notes = notes + get_layer_notices(layer)
            (layer_pkg_list, layer_license_list,
             file_level_licenses) = get_layer_info_list(layer)
            # Collect files + packages + licenses in the layer
            notes += formats.layer_file_licenses_list.format(
                list=file_level_licenses)
            notes += formats.layer_packages_list.format(
                list=", ".join(layer_pkg_list) if layer_pkg_list else 'None')
            notes += formats.layer_licenses_list.format(list=", ".join(
                layer_license_list) if layer_license_list else 'None')
            notes = notes + formats.package_demarkation
    return notes