Пример #1
0
 def testIsEqual(self):
     p = Package('x')
     p.license = 'TestLicense'
     p.version = '1.0'
     p.src_url = 'TestUrl'
     self.package.license = 'TestLicense'
     self.package.version = '2.0'
     self.package.src_url = 'TestUrl'
     self.assertFalse(self.package.is_equal(p))
     p.version = '2.0'
     self.assertTrue(self.package.is_equal(p))
Пример #2
0
 def testIsEqual(self):
     p = Package('p2')
     p.pkg_license = 'Testpkg_license'
     p.version = '1.0'
     p.src_url = 'TestUrl'
     self.p2.pkg_license = 'Testpkg_license'
     self.p2.version = '2.0'
     self.p2.src_url = 'TestUrl'
     self.assertFalse(self.p2.is_equal(p))
     p.version = '2.0'
     self.assertTrue(self.p2.is_equal(p))
Пример #3
0
 def testIsEqual(self):
     p = Package('p2')
     p.pkg_license = 'Testpkg_license'
     p.version = '1.0'
     p.pkg_format = 'rpm'
     p.proj_url = 'TestUrl'
     p.checksum = 'abcdef'
     self.p2.pkg_license = 'Testpkg_license'
     self.p2.version = '2.0'
     self.p2.pkg_format = 'rpm'
     self.p2.proj_url = 'TestUrl'
     self.p2.checksum = 'abcdef'
     self.assertFalse(self.p2.is_equal(p))
     p.version = '2.0'
     self.assertTrue(self.p2.is_equal(p))
Пример #4
0
 def testMerge(self):
     p1 = Package('p1')
     p1.version = '1.0'
     p1.pkg_licenses = ['license1']
     p2 = Package('p1')
     p2.version = '1.0'
     p2.download_url = 'SomeUrl'
     p2.checksum = 'abc'
     p2.pkg_licenses = ['license2']
     self.assertFalse(p1.merge('astring'))
     self.assertTrue(p1.merge(p2))
     self.assertEqual(p1.download_url, 'SomeUrl')
     self.assertEqual(p1.checksum, 'abc')
     self.assertEqual(p1.pkg_licenses, ['license1', 'license2'])
     p2.version = '2.0'
     self.assertFalse(p1.merge(p2))
Пример #5
0
def add_base_packages(image_layer, binary, shell):  # pylint: disable=too-many-locals
    '''Given the image layer, the binary to invoke and shell:
        1. get the listing from the base.yml
        2. Invoke any commands against the base layer
        3. Make a list of packages and add them to the layer'''
    origin_layer = 'Layer: ' + image_layer.fs_hash[:10]
    if image_layer.created_by:
        image_layer.origins.add_notice_to_origins(
            origin_layer,
            Notice(
                formats.layer_created_by.format(
                    created_by=image_layer.created_by), 'info'))
    else:
        image_layer.origins.add_notice_to_origins(
            origin_layer, Notice(formats.no_created_by, 'warning'))
    origin_command_lib = formats.invoking_base_commands
    # find the binary
    listing = command_lib.get_base_listing(binary)
    if listing:
        # put info notice about what is going to be invoked
        snippet_msg = formats.invoke_for_base + '\n' + \
            content.print_base_invoke(binary)
        image_layer.origins.add_notice_to_origins(origin_layer,
                                                  Notice(snippet_msg, 'info'))
        shell, _ = command_lib.get_image_shell(listing)
        if not shell:
            shell = constants.shell
        # get all the packages in the base layer
        names, n_msg = command_lib.get_pkg_attr_list(shell, listing['names'])
        versions, v_msg = command_lib.get_pkg_attr_list(
            shell, listing['versions'])
        licenses, l_msg = command_lib.get_pkg_attr_list(
            shell, listing['licenses'])
        src_urls, u_msg = command_lib.get_pkg_attr_list(
            shell, listing['src_urls'])
        # add a notice to the image if something went wrong
        invoke_msg = n_msg + v_msg + l_msg + u_msg
        if invoke_msg:
            image_layer.origins.add_notice_to_origins(
                origin_layer, Notice(invoke_msg, 'error'))
        if names and len(names) > 1:
            for index, name in enumerate(names):
                pkg = Package(name)
                if len(versions) == len(names):
                    pkg.version = versions[index]
                if len(licenses) == len(names):
                    pkg.license = licenses[index]
                if len(src_urls) == len(names):
                    pkg.src_url = src_urls[index]
                image_layer.add_package(pkg)
    # if there is no listing add a notice
    else:
        image_layer.origins.add_notice_to_origins(
            origin_command_lib,
            Notice(errors.no_listing_for_base_key.format(listing_key=binary),
                   'error'))
Пример #6
0
def get_scancode_package(package_dict):
    '''Given a package dictionary from the scancode results, return a Package
    object with the results'''
    package = Package(package_dict['name'])
    package.version = package_dict['version']
    package.pkg_license = package_dict['declared_license']
    package.copyright = package_dict['copyright']
    package.proj_url = package_dict['repository_homepage_url']
    package.download_url = package_dict['download_url']
    package.licenses = [package_dict['declared_license'],
                        package_dict['license_expression']]
    return package
Пример #7
0
def get_package_from_dict(pkg_dict):
    """The SPDX JSON format contains a list of dictionaries, each containing
    the package metadata. For one package dictionary, return a Package
    object"""
    pkg_obj = Package(pkg_dict['name'])
    pkg_obj.version = ("" if pkg_dict['versionInfo'] == 'NOASSERTION'
                       else pkg_dict['versionInfo'])
    pkg_obj.proj_url = ("" if pkg_dict['downloadLocation'] == 'NONE'
                        else pkg_dict['downloadLocation'])
    pkg_obj.copyright = ("" if pkg_dict['copyrightText'] == 'NONE'
                         else pkg_dict['copyrightText'])
    return pkg_obj