コード例 #1
0
async def client(client: CompanionClient, file_paths: List[str]) -> None:
    async with client.stub.add_media.open() as stream:
        for file_path in file_paths:
            await stream.send_message(
                AddMediaRequest(payload=Payload(file_path=file_path)))
        await stream.end()
        await stream.recv_message()
コード例 #2
0
 async def add_media(self, file_paths: List[str]) -> None:
     async with self.get_stub() as stub, stub.add_media.open() as stream:
         if none_throws(self.companion_info).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:
             generator = stream_map(
                 generate_tar(paths=file_paths, place_in_subfolders=True),
                 lambda chunk: AddMediaRequest(payload=Payload(data=chunk)),
             )
             await drain_to_stream(stream=stream,
                                   generator=generator,
                                   logger=self.logger)
コード例 #3
0
ファイル: client.py プロジェクト: trantrungtin/idb
 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)
コード例 #4
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)