Esempio n. 1
0
 async def add_media(self, file_paths: List[str]) -> None:
     async with self.stub.add_media.open() as stream:
         if self.is_local:
             for file_path in file_paths:
                 await stream.send_message(
                     AddMediaRequest(payload=Payload(file_path=file_path)))
             await stream.end()
             await stream.recv_message()
         else:
             self.logger.info(f"Adding media from {file_paths}")
             generator = stream_map(
                 generate_tar(
                     paths=file_paths,
                     place_in_subfolders=True,
                     verbose=self._is_verbose,
                 ),
                 lambda chunk: AddMediaRequest(payload=Payload(data=chunk)),
             )
             await drain_to_stream(stream=stream,
                                   generator=generator,
                                   logger=self.logger)
Esempio n. 2
0
File: grpc.py Progetto: Vishalan/idb
 async def push(self, src_paths: List[str], bundle_id: str,
                dest_path: str) -> None:
     async with self.stub.push.open() as stream:
         await stream.send_message(
             PushRequest(inner=PushRequest.Inner(bundle_id=bundle_id,
                                                 dst_path=dest_path)))
         if self.is_local:
             for src_path in src_paths:
                 await stream.send_message(
                     PushRequest(payload=Payload(file_path=src_path)))
             await stream.end()
             await stream.recv_message()
         else:
             await drain_to_stream(
                 stream=stream,
                 generator=stream_map(
                     generate_tar(paths=src_paths),
                     lambda chunk: PushRequest(payload=Payload(data=chunk)),
                 ),
                 logger=self.logger,
             )
Esempio n. 3
0
    async def _install_to_destination(
            self, bundle: Bundle,
            destination: Destination) -> 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,
                            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))
            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)
Esempio n. 4
0
    async def _install_to_destination(
            self, bundle: Bundle,
            destination: Destination) -> InstalledArtifact:
        generator = None
        if isinstance(bundle, str):
            url = urllib.parse.urlparse(bundle)
            if url.scheme:
                # send url
                payload = Payload(url=bundle)
                async with self.stub.install.open() as stream:
                    generator = generate_requests(
                        [InstallRequest(payload=payload)])

            else:
                file_path = str(Path(bundle).resolve(strict=True))
                if self.companion_info.is_local:
                    # send file_path
                    async with self.stub.install.open() as stream:
                        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
        async with self.stub.install.open() as stream:
            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)
Esempio n. 5
0
File: client.py Progetto: iqqmuT/idb
 async def push(self, src_paths: List[str], container: FileContainer,
                dest_path: str) -> None:
     async with self.stub.push.open() as stream:
         await stream.send_message(
             PushRequest(inner=PushRequest.Inner(
                 dst_path=dest_path,
                 container=file_container_to_grpc(container))))
         if self.is_local:
             for src_path in src_paths:
                 await stream.send_message(
                     PushRequest(payload=Payload(file_path=src_path)))
             await stream.end()
             await stream.recv_message()
         else:
             await drain_to_stream(
                 stream=stream,
                 generator=stream_map(
                     generate_tar(paths=src_paths,
                                  verbose=self._is_verbose),
                     lambda chunk: PushRequest(payload=Payload(data=chunk)),
                 ),
                 logger=self.logger,
             )
Esempio n. 6
0
async def daemon(client: CompanionClient,
                 stream: Stream[AddMediaResponse, AddMediaRequest]) -> None:
    async with client.stub.add_media.open() as companion:
        if client.is_local:
            generator = stream
        else:
            paths = [request.payload.file_path async for request in stream]
            generator = stream_map(
                generate_tar(paths=paths, place_in_subfolders=True),
                lambda chunk: AddMediaRequest(payload=Payload(data=chunk)),
            )
        response = await drain_to_stream(stream=companion,
                                         generator=generator,
                                         logger=client.logger)
        await stream.send_message(response)
Esempio n. 7
0
async def daemon(client: CompanionClient, stream: Stream[PushResponse,
                                                         PushRequest]) -> None:
    async with client.stub.push.open() as companion:
        await companion.send_message(await stream.recv_message())
        if client.is_local:
            generator = stream
        else:
            paths = [request.payload.file_path async for request in stream]
            generator = stream_map(
                generate_tar(paths=paths),
                lambda chunk: PushRequest(payload=Payload(data=chunk)),
            )
        response = await drain_to_stream(stream=companion,
                                         generator=generator,
                                         logger=client.logger)
        await stream.send_message(response)
Esempio n. 8
0
async def daemon(client: CompanionClient,
                 request: PullRequest) -> PullResponse:
    destination = request.dst_path
    async with client.stub.pull.open() as stream:
        if not client.is_local:
            # not sending the destination to remote companion
            # so it streams the file back
            request = PullRequest(bundle_id=request.bundle_id,
                                  src_path=request.src_path,
                                  dst_path=None)
        await stream.send_message(request, end=True)
        if client.is_local:
            await stream.recv_message()
        else:
            await drain_untar(generate_bytes(stream), output_path=destination)
        client.logger.info(f"pulled file to {destination}")
    return PullResponse(payload=Payload(file_path=destination))
Esempio n. 9
0
 async def pull(self, bundle_id: str, src_path: str, dest_path: str) -> None:
     async with self.get_stub() as stub, stub.pull.open() as stream:
         request = request = PullRequest(
             bundle_id=bundle_id,
             src_path=src_path,
             # not sending the destination to remote companion
             # so it streams the file back
             dst_path=dest_path
             if none_throws(self.companion_info).is_local
             else None,
         )
         await stream.send_message(request)
         await stream.end()
         if none_throws(self.companion_info).is_local:
             await stream.recv_message()
         else:
             await drain_untar(generate_bytes(stream), output_path=dest_path)
         self.logger.info(f"pulled file to {dest_path}")
     return PullResponse(payload=Payload(file_path=dest_path))
Esempio n. 10
0
 async def contacts_update(self, contacts_path: str) -> None:
     async with self.get_stub() as stub:
         data = await create_tar([contacts_path])
         await stub.contacts_update(
             ContactsUpdateRequest(payload=Payload(data=data))
         )
Esempio n. 11
0
async def _generate_framework_chunks(
        path: str, logger: Logger) -> AsyncIterator[InstallRequest]:
    logger.debug(f"Generating chunks for {path}")
    async for chunk in tar.generate_tar([path]):
        yield InstallRequest(payload=Payload(data=chunk))
    logger.debug(f"Finished generating chunks {path}")
Esempio n. 12
0
async def _generate_app_chunks(
        app_path: str, logger: Logger) -> AsyncIterator[InstallRequest]:
    logger.debug(f"Generating chunks for .app {app_path}")
    async for chunk in tar.generate_tar([app_path]):
        yield InstallRequest(payload=Payload(data=chunk))
    logger.debug(f"Finished generating .app chunks {app_path}")
Esempio n. 13
0
async def client(client: CompanionClient, contacts_path: str) -> None:
    data = await create_tar([contacts_path])
    await client.stub.contacts_update(ContactsUpdateRequest(payload=Payload(data=data)))