コード例 #1
0
ファイル: management.py プロジェクト: shahzadmajeed/idb
 async def connect(
     self,
     destination: ConnectionDestination,
     metadata: Optional[Dict[str, str]] = None,
 ) -> CompanionInfo:
     self._logger.debug(
         f"Connecting directly to {destination} with meta {metadata}")
     if isinstance(destination, TCPAddress) or isinstance(
             destination, DomainSocketAddress):
         async with IdbClient.build(address=destination,
                                    is_local=False,
                                    logger=self._logger) as client:
             with tempfile.NamedTemporaryFile(mode="w+b") as f:
                 response = await client.stub.connect(
                     ConnectRequest(metadata=metadata,
                                    local_file_path=f.name))
         companion = CompanionInfo(
             address=destination,
             udid=response.companion.udid,
             is_local=response.companion.is_local,
         )
         self._logger.debug(f"Connected directly to {companion}")
         await self._direct_companion_manager.add_companion(companion)
         return companion
     else:
         companion = await self._spawn_companion(target_udid=destination)
         if companion:
             return companion
         else:
             raise IdbException(f"can't find target for udid {destination}")
コード例 #2
0
ファイル: base.py プロジェクト: HotWordland/idb
async def _get_client(
    args: Namespace, logger: logging.Logger
) -> AsyncContextManager[IdbClient]:
    companion = vars(args).get("companion")
    if companion is not None:
        (host, port) = _parse_companion_info(companion)
        async with IdbClientGrpc.build(
            host=host, port=port, is_local=False, logger=logger
        ) as client:
            yield client
    else:
        async with IdbManagementClientGrpc(
            logger=logger, companion_path=args.companion_path
        ).from_udid(udid=vars(args).get("udid")) as client:
            yield client
コード例 #3
0
ファイル: management.py プロジェクト: HotWordland/idb
 async def _companion_to_target(
         self, companion: CompanionInfo) -> Optional[TargetDescription]:
     try:
         async with IdbClient.build(
                 host=companion.host,
                 port=companion.port,
                 is_local=False,
                 logger=self.logger,
         ) as client:
             return await client.describe()
     except Exception:
         self.logger.warning(f"Failed to describe {companion}, removing it")
         await self.direct_companion_manager.remove_companion(
             Address(host=companion.host, port=companion.port))
         return None
コード例 #4
0
ファイル: __init__.py プロジェクト: shubhral/idb
async def _get_client(
    args: Namespace, logger: logging.Logger
) -> AsyncGenerator[IdbClientGrpc, None]:
    companion = vars(args).get("companion")
    if companion is not None:
        async with IdbClientGrpc.build(
            address=_parse_address(companion),
            is_local=args.companion_local,
            logger=logger,
        ) as client:
            yield client
    else:
        async with IdbManagementClientGrpc(
            logger=logger, companion_path=args.companion_path
        ).from_udid(udid=vars(args).get("udid")) as client:
            yield client
コード例 #5
0
ファイル: management.py プロジェクト: shahzadmajeed/idb
 async def _companion_to_target(
         self, companion: CompanionInfo) -> Optional[TargetDescription]:
     try:
         async with IdbClient.build(address=companion.address,
                                    is_local=False,
                                    logger=self._logger) as client:
             return await client.describe()
     except Exception:
         if not self._prune_dead_companion:
             self._logger.warning(
                 f"Failed to describe {companion}, but not removing it")
             return None
         self._logger.warning(
             f"Failed to describe {companion}, removing it")
         await self._direct_companion_manager.remove_companion(
             companion.address)
         return None
コード例 #6
0
ファイル: management.py プロジェクト: zlhope/idb
 async def from_udid(self, udid: Optional[str]) -> AsyncContextManager[IdbClient]:
     await self._spawn_notifier()
     try:
         companion_info = await self.direct_companion_manager.get_companion_info(
             target_udid=udid
         )
     except IdbException as e:
         # will try to spawn a companion if on mac.
         companion_info = await self._spawn_companion(target_udid=none_throws(udid))
         if companion_info is None:
             raise e
     async with IdbClient.build(
         host=companion_info.host,
         port=companion_info.port,
         is_local=companion_info.is_local,
         logger=self.logger,
     ) as client:
         yield client
コード例 #7
0
ファイル: management.py プロジェクト: shahzadmajeed/idb
 async def from_udid(
         self, udid: Optional[str]) -> AsyncGenerator[IdbClient, None]:
     await self._spawn_notifier()
     try:
         companion_info = await self._direct_companion_manager.get_companion_info(
             target_udid=udid)
     except IdbException as e:
         # will try to spawn a companion if on mac.
         if udid is None:
             raise e
         companion_info = await self._spawn_companion(target_udid=udid)
         if companion_info is None:
             raise e
     async with IdbClient.build(
             address=companion_info.address,
             is_local=companion_info.is_local,
             logger=self._logger,
     ) as client:
         yield client
コード例 #8
0
 async def connect(
     self,
     destination: ConnectionDestination,
     metadata: Optional[Dict[str, str]] = None,
 ) -> CompanionInfo:
     self._logger.debug(
         f"Connecting directly to {destination} with meta {metadata}")
     if isinstance(destination, TCPAddress) or isinstance(
             destination, DomainSocketAddress):
         async with IdbClient.build(address=destination,
                                    is_local=False,
                                    logger=self._logger) as client:
             companion = client.companion
         self._logger.debug(f"Connected directly to {companion}")
         await self._direct_companion_manager.add_companion(companion)
         return companion
     else:
         companion = await self._spawn_companion(target_udid=destination)
         if companion:
             return companion
         else:
             raise IdbException(f"can't find target for udid {destination}")