Ejemplo n.º 1
0
        def generate_translation_files(component):
            nonlocal release
            nonlocal file_references

            translation_dir = os.path.join(os.path.basename(component), "i18n")
            paths = [
                path for path in file_references.keys()
                if path.startswith(translation_dir)
            ]
            translations = {}
            for path in paths:
                d_artifact = to_d_artifact(file_references.pop(path))
                key, ext = os.path.splitext(path)
                if key not in translations:
                    translations[key] = {"sha256": None, "d_artifacts": []}
                if not ext:
                    translations[key]["sha256"] = d_artifact.artifact.sha256
                translations[key]["d_artifacts"].append(d_artifact)

            for path, translation in translations.items():
                content_unit = GenericContent(
                    sha256=translation["sha256"],
                    relative_path=os.path.join(
                        os.path.dirname(release.relative_path), path),
                )
                d_content = DeclarativeContent(
                    content=content_unit,
                    d_artifacts=translation["d_artifacts"])
                yield d_content
Ejemplo n.º 2
0
    async def _handle_translation_files(self, release_file, release_component,
                                        file_references):
        translation_dir = os.path.join(release_component.plain_component,
                                       "i18n")
        paths = [
            path for path in file_references.keys()
            if path.startswith(translation_dir)
        ]
        translations = {}
        for path in paths:
            relative_path = os.path.join(
                os.path.dirname(release_file.relative_path))
            d_artifact = self._to_d_artifact(relative_path,
                                             file_references[path])
            key, ext = os.path.splitext(relative_path)
            if key not in translations:
                translations[key] = {"sha256": None, "d_artifacts": []}
            if not ext:
                translations[key]["sha256"] = d_artifact.artifact.sha256
            translations[key]["d_artifacts"].append(d_artifact)

        for relative_path, translation in translations.items():
            content_unit = GenericContent(sha256=translation["sha256"],
                                          relative_path=relative_path)
            await self.put(
                DeclarativeContent(content=content_unit,
                                   d_artifacts=translation["d_artifacts"]))
Ejemplo n.º 3
0
    async def _read_installer_file_index(self, installer_file_index):
        """
        Parse an installer file index file of apt Repositories.

        Put DeclarativeContent in the queue accordingly.

        Args:
            installer_file_index: object of type :class:`InstallerFileIndex`

        """
        # Interpret policy to download Artifacts or not
        deferred_download = self.remote.policy != Remote.IMMEDIATE

        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]
            )
            yield d_content
Ejemplo n.º 4
0
    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)