Exemple #1
0
        def generate_installer_file_index(component, architecture):
            nonlocal release
            nonlocal file_references

            installer_file_index_dir = os.path.join(
                os.path.basename(component),
                "installer-{}".format(architecture),
                "current",
                "images",
            )
            log.info("Downloading installer files from {}".format(
                installer_file_index_dir))
            d_artifacts = []
            for filename in InstallerFileIndex.FILE_ALGORITHM.keys():
                path = os.path.join(installer_file_index_dir, filename)
                if path in file_references:
                    d_artifacts.append(to_d_artifact(
                        file_references.pop(path)))
            if not d_artifacts:
                return
            content_unit = InstallerFileIndex(
                release=release,
                component=component,
                architecture=architecture,
                sha256=d_artifacts[0].artifact.sha256,
                relative_path=os.path.join(
                    os.path.dirname(release.relative_path),
                    installer_file_index_dir),
            )
            d_content = DeclarativeContent(content=content_unit,
                                           d_artifacts=d_artifacts,
                                           does_batch=False)
            yield d_content
    async def _handle_installer_file_index(self, release_file,
                                           release_component, architecture,
                                           file_references):
        # Create installer file index
        release_base_path = os.path.dirname(release_file.relative_path)
        installer_file_index_dir = os.path.join(
            release_component.plain_component,
            "installer-{}".format(architecture),
            "current",
            "images",
        )
        d_artifacts = []
        for filename in InstallerFileIndex.FILE_ALGORITHM.keys():
            path = os.path.join(installer_file_index_dir, filename)
            if path in file_references:
                relative_path = os.path.join(release_base_path, path)
                d_artifacts.append(
                    self._to_d_artifact(relative_path, file_references[path]))
        if not d_artifacts:
            return
        log.info("Downloading installer files from {}".format(
            installer_file_index_dir))
        content_unit = InstallerFileIndex(
            release=release_file,
            component=release_component.component,
            architecture=architecture,
            sha256=d_artifacts[0].artifact.sha256,
            relative_path=os.path.join(release_base_path,
                                       installer_file_index_dir),
        )
        d_content = DeclarativeContent(content=content_unit,
                                       d_artifacts=d_artifacts)
        installer_file_index = await self._create_unit(d_content)
        # Interpret policy to download Artifacts or not
        deferred_download = self.remote.policy != Remote.IMMEDIATE
        # Parse installer file index
        file_list = defaultdict(dict)
        for content_artifact in installer_file_index.contentartifact_set.all():
            algorithm = InstallerFileIndex.FILE_ALGORITHM.get(
                os.path.basename(content_artifact.relative_path))
            if not algorithm:
                continue
            for line in content_artifact.artifact.file:
                digest, filename = line.decode().strip().split(maxsplit=1)
                filename = os.path.normpath(filename)
                if filename in InstallerFileIndex.FILE_ALGORITHM:  # strangely they may appear here
                    continue
                file_list[filename][algorithm] = digest

        for filename, digests in file_list.items():
            relpath = os.path.join(installer_file_index.relative_path,
                                   filename)
            urlpath = os.path.join(self.parsed_url.path, relpath)
            content_unit = GenericContent(sha256=digests["sha256"],
                                          relative_path=relpath)
            d_artifact = DeclarativeArtifact(
                artifact=Artifact(**digests),
                url=urlunparse(self.parsed_url._replace(path=urlpath)),
                relative_path=relpath,
                remote=self.remote,
                deferred_download=deferred_download,
            )
            d_content = DeclarativeContent(content=content_unit,
                                           d_artifacts=[d_artifact])
            await self.put(d_content)