Example #1
0
def install_package(artifact, arch, here):
    """
    search for artifact and untar the corresponding archive file.

    artifacts are search in the a list of packages home directory. The first valid occurence found is installed.

    :param artifact: an artifacts.Artifact instance
    :param arch: a valid target processor architecture (x86, ...)
    :param here: path to the installation directory.
    :return: True if successfull
    """

    status = False

    assert isinstance(
        artifact, artifacts.Artifact
    ), "{}.install_package expects a Artifact instance, you passed {}".format(
        __name__, artifact.__class__.__name__)

    package = artifacts.Package(artifact, target_arch=arch)

    if package.id() not in PACKAGES.keys():
        for packages_home in artifacts.PACKAGES_HOME_PATH:
            if package.id() not in PACKAGES.keys():
                try:
                    archive_file = os.path.join(packages_home,
                                                package.archive())
                    assert os.path.isfile(
                        archive_file
                    ), "archive file '{}' not found here {}.".format(
                        package.archive(), packages_home)

                    digest_file = os.path.join(packages_home,
                                               package.archive_digest())
                    assert os.path.isfile(
                        digest_file
                    ), "archive digest file '{}' not found here {}.".format(
                        digest_file, packages_home)

                    check_integrity(archive_file, digest_file)

                    with tarfile.open(archive_file, "r:gz") as archive_reader:
                        archive_reader.extractall(path=here)

                    print("installed '{}' here '{}'".format(
                        archive_file, packages_home, arch, here))

                    PACKAGES[package.id()] = package
                    status = True

                except AssertionError as err:
                    print(err)

    else:
        print("package '{}' already deployed here '{}'.".format(
            package.id(), here))

    return status
    def test_packaging_archive_digest(self):
        package = artifacts.Package(artifacts.Artifact('common-qnx-1.2.3'), 'x86')
        self.assertEqual(package.archive_digest(),
                         "common-qnx-1.2.3-x86.tar.gz.md5",
                         msg="wrong packaging archive digest name for artefact '{}'".format(package))

        package.target_arch('armv7')
        self.assertEqual(package.archive_digest(),
                         "common-qnx-1.2.3-armv7.tar.gz.md5",
                         msg="wrong packaging archive digest name for artefact '{}'".format(package))
    def test_packaging_archive(self):
        package = artifacts.Package(artifacts.Artifact('common-qnx-1.2.3'), 'x86')
        self.assertEqual(package.archive(),
                         "common-qnx-1.2.3-x86.tar.gz",
                         msg="wrong packaging archive name for package \n{}".format(package))

        package.target_arch('armv7')
        self.assertEqual(package.archive(),
                         "common-qnx-1.2.3-armv7.tar.gz",
                         msg="wrong packaging archive name for package \n{}".format(package))
Example #4
0
def copy_package(archive, to):
    """
    copy given archive to a directory.

    The archive parameter is expected to contain a valid package and artifact descrption string. Before copying, the
    archive file is checked against the content of the archive's digest file. If the digests match, the archive will be
    copied.

    :param archive: relative or absolute path to an archive
    :param to: target directory.
    :return:
    """

    status = False
    try:
        basename = os.path.basename(archive)
        dirname = os.path.dirname(archive)

        package = artifacts.Package(basename)

        source_archive = os.path.join(dirname, package.archive())
        source_archive_digest = os.path.join(dirname, package.archive_digest())
        target_archive = os.path.join(to, package.archive())
        target_archive_digest = os.path.join(to, package.archive_digest())

        if package.artifact.is_snapshot():
            check_integrity(source_archive, source_archive_digest)
            shutil.copy(source_archive, target_archive)
            shutil.copy(source_archive_digest, target_archive_digest)
            print("copied {} to {}".format(source_archive, to))
            status = True

        elif not package.artifact.is_snapshot():
            if not os.path.isfile(target_archive):
                check_integrity(source_archive, source_archive_digest)
                shutil.copy(source_archive, target_archive)
                shutil.copy(source_archive_digest, target_archive_digest)
                print("copied {} to {}".format(source_archive, to))
                status = True

            else:
                print(
                    "package '{}' found here '{}', the package is considered stable and will not be overwritten"
                    .format(package.id(), to))

    except AssertionError as err:
        print("won't copy '{}', {}".format(archive, err))

    except Exception as err:
        print("function {}.copy_package('{}') failed, {}".format(
            __name__, archive, err))
        raise err

    return status
    def test_load_from_text_file(self):
        path_to_text_file = 'tests/dependencies.txt'
        expected_values= ['ipcm-api-qnx-1.42.0-armv7','common-qnx-2.0.1-armv7','cpp-pthread-Darwin-1.11.0-armv7']

        requirements = artifacts.load_requirements_from(path_to_text_file)

        self.assertIsNotNone(requirements, msg="failed to load requirements from file '{}'".format(path_to_text_file))
        self.assertEqual(len(requirements), 3, msg="unexpected number requirments found in '{}'".format(path_to_text_file))

        for artefact in requirements:
            package = artifacts.Package(artefact, 'armv7')
            # DEBUG  print ("{}: {}".format(__name__, package.id()))
            self.assertTrue(package.id() in expected_values,
                            "Expect {} found in {} to be in {}".format(
                                package.id(),
                                path_to_text_file,
                                expected_values))
    def test_load_from_yaml_file(self):
        path_to_yaml_files = ['tests/dependencies.yml']

        expected_values = ['ipcm-api-qnx-1.42.0-armv7', 'common-qnx-2.0.1-armv7', 'my-lib-qnx-2.0.1-snapshot-armv7']

        for path_to_yaml_file in path_to_yaml_files:
            requirements = artifacts.load_requirements_from(path_to_yaml_file)

            self.assertIsNotNone(requirements, msg="failed to load requirements from file '{}'".format(path_to_yaml_file))
            self.assertEqual(2, len(requirements), msg="unexpected number requirements found in '{}'".format(path_to_yaml_file))

            for artefact in requirements:
                package = artifacts.Package(artefact, 'armv7')
                # DEBUG print ("{}: {}".format(__name__, package.id()))
                self.assertTrue(package.id() in expected_values,
                                "Expect {id} to be in {expected} ({path})".format(
                                    id=package.id(),
                                    path=path_to_yaml_file,
                                    expected=expected_values))