async def run_with_client(self, args: Namespace, client: IdbManagementClient) -> None: try: destination = get_destination(args=args) connect_response = await client.connect( destination=destination, metadata={ key: value for ( key, value) in plugin.resolve_metadata(self.logger).items() if isinstance(value, str) }, ) if connect_response: if args.json: print( json.dumps({ "udid": connect_response.udid, "is_local": connect_response.is_local, })) else: print( f"udid: {connect_response.udid} is_local: {connect_response.is_local}" ) except IdbException: raise ConnectCommandException( f"""Could not connect to {args.companion:}:{args.port}. Make sure both host and port are correct and reachable""")
async def build( cls, address: Address, logger: logging.Logger, is_local: Optional[bool] = None, exchange_metadata: bool = True, extra_metadata: Optional[Dict[str, str]] = None, use_tls: bool = False, ) -> AsyncGenerator["Client", None]: metadata_to_companion = ( { **{ key: value for (key, value) in plugin.resolve_metadata(logger=logger).items() if isinstance(value, str) }, **(extra_metadata or {}), } if exchange_metadata else {} ) ssl_context = plugin.channel_ssl_context() if use_tls else None if use_tls: assert ssl_context is not None async with ( Channel( host=address.host, port=address.port, loop=asyncio.get_event_loop(), ssl=ssl_context, ) if isinstance(address, TCPAddress) else Channel(path=address.path, loop=asyncio.get_event_loop()) ) as channel: stub = CompanionServiceStub(channel=channel) with tempfile.NamedTemporaryFile(mode="w+b") as f: try: response = await stub.connect( ConnectRequest( metadata=metadata_to_companion, local_file_path=f.name ) ) except Exception as ex: raise IdbException( f"Failed to connect to companion at address {address}: {ex}" ) companion = companion_to_py( companion=response.companion, address=address, is_local=is_local ) if exchange_metadata: metadata_from_companion = { key: value for (key, value) in companion.metadata.items() if isinstance(value, str) } plugin.append_companion_metadata( logger=logger, metadata=metadata_from_companion ) yield Client(stub=stub, companion=companion, logger=logger)
async def run(self, args: Namespace) -> None: # Set the log level on the base logger logging.getLogger().setLevel(args.log_level) name = self.__class__.__name__ self.logger.debug(f"{name} command run with: {args}") async with log_call( name=name, metadata=plugin.resolve_metadata(logger=self.logger)): await self._run_impl(args)
async def run(self, args: Namespace) -> None: # In order to keep the argparse compatible with old invocations # We should use the --log after command if set, otherwise use the pre-command --log logging.getLogger().setLevel(args.log_level_deprecated or args.log_level) name = self.__class__.__name__ self.logger.debug(f"{name} command run with: {args}") if args.log_level_deprecated is not None: self.logger.warning( f"Setting --log after the command is deprecated, please place it at the start of the invocation" ) async with log_call( name=name, metadata=plugin.resolve_metadata(logger=self.logger) ): await self._run_impl(args)