Example #1
0
async def _install_to_destination(
    client: CompanionClient, bundle: Bundle, destination: Destination
) -> InstalledArtifact:
    if isinstance(bundle, str):
        # Treat as a file path / url
        url = urllib.parse.urlparse(bundle)
        if url.scheme:
            payload = Payload(url=bundle)
        else:
            payload = Payload(file_path=str(Path(bundle).resolve(strict=True)))
        async with client.stub.install.open() as stream:
            await stream.send_message(InstallRequest(destination=destination))
            await stream.send_message(InstallRequest(payload=payload))
            await stream.end()
            response = await stream.recv_message()
            return InstalledArtifact(name=response.name, uuid=response.uuid)
    else:
        # Treat as a binary object (tar of .app or .ipa)
        async with client.stub.install.open() as stream:
            await stream.send_message(InstallRequest(destination=destination))
            response = await drain_to_stream(
                stream=stream,
                generator=_generate_io_chunks(io=bundle, logger=client.logger),
                logger=client.logger,
            )
            return InstalledArtifact(name=response.name, uuid=response.uuid)
Example #2
0
    async def _install_to_destination(
        self, bundle: Bundle, destination: Destination
    ) -> InstalledArtifact:
        async with self.get_stub() as stub, stub.install.open() as stream:
            generator = None
            if isinstance(bundle, str):
                url = urllib.parse.urlparse(bundle)
                if url.scheme:
                    # send url
                    payload = Payload(url=bundle)
                    generator = generate_requests([InstallRequest(payload=payload)])

                else:
                    file_path = str(Path(bundle).resolve(strict=True))
                    if none_throws(self.companion_info).is_local:
                        # send file_path
                        generator = generate_requests(
                            [InstallRequest(payload=Payload(file_path=file_path))]
                        )
                    else:
                        # chunk file from file_path
                        generator = generate_binary_chunks(
                            path=file_path, destination=destination, logger=self.logger
                        )

            else:
                # chunk file from memory
                generator = generate_io_chunks(io=bundle, logger=self.logger)
                # stream to companion
            await stream.send_message(InstallRequest(destination=destination))
            response = await drain_to_stream(
                stream=stream, generator=generator, logger=self.logger
            )
            return InstalledArtifact(name=response.name, uuid=response.uuid)
Example #3
0
    async def _install_to_destination(
        self,
        bundle: Bundle,
        destination: Destination,
        compression: Optional[Compression] = None,
    ) -> AsyncIterator[InstalledArtifact]:
        async with self.stub.install.open() as stream:
            generator = None
            if isinstance(bundle, str):
                url = urllib.parse.urlparse(bundle)
                if url.scheme:
                    # send url
                    payload = Payload(url=bundle)
                    generator = generate_requests([InstallRequest(payload=payload)])

                else:
                    file_path = str(Path(bundle).resolve(strict=True))
                    if self.is_local:
                        # send file_path
                        generator = generate_requests(
                            [InstallRequest(payload=Payload(file_path=file_path))]
                        )
                    else:
                        # chunk file from file_path
                        generator = generate_binary_chunks(
                            path=file_path,
                            destination=destination,
                            compression=compression,
                            logger=self.logger,
                        )

            else:
                # chunk file from memory
                generator = generate_io_chunks(io=bundle, logger=self.logger)
                # stream to companion
            await stream.send_message(InstallRequest(destination=destination))
            if compression is not None:
                await stream.send_message(
                    InstallRequest(
                        payload=Payload(compression=COMPRESSION_MAP[compression])
                    )
                )
            async for message in generator:
                await stream.send_message(message)
            await stream.end()
            async for response in stream:
                yield InstalledArtifact(
                    name=response.name, uuid=response.uuid, progress=response.progress
                )