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)
async def _generate_dylib_chunks( path: str, logger: Logger) -> AsyncIterator[InstallRequest]: logger.debug(f"Generating chunks for {path}") yield InstallRequest(name_hint=os.path.basename(path)) async for chunk in gzip.generate_gzip(path): yield InstallRequest(payload=Payload(data=chunk)) logger.debug(f"Finished generating chunks {path}")
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)
async def _install_to_destination(client: CompanionClient, path: str, destination: Destination) -> str: url = urllib.parse.urlparse(path) if url.scheme: payload = Payload(url=path) else: payload = Payload(file_path=str(Path(path).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 response.bundle_id
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 )
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}")
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}")
async def _generate_dsym_chunks( path: str, compression: Compression, logger: Logger) -> AsyncIterator[InstallRequest]: logger.debug(f"Generating chunks for {path}") async for chunk in tar.generate_tar([path], compression): yield InstallRequest(payload=Payload(data=chunk)) logger.debug(f"Finished generating chunks {path}")
async def _generate_io_chunks(io: IO[bytes], logger: Logger) -> AsyncIterator[InstallRequest]: logger.debug("Generating io chunks") while True: chunk = io.read(CHUNK_SIZE) if not chunk: logger.debug(f"Finished generating byte chunks") return yield InstallRequest(payload=Payload(data=chunk)) logger.debug("Finished generating io chunks")
async def _generate_ipa_chunks( ipa_path: str, logger: Logger) -> AsyncIterator[InstallRequest]: logger.debug(f"Generating Chunks for .ipa {ipa_path}") async with aiofiles.open(ipa_path, "r+b") as file: while True: chunk = await file.read(CHUNK_SIZE) if not chunk: logger.debug(f"Finished generating .ipa chunks for {ipa_path}") return yield InstallRequest(payload=Payload(data=chunk))