コード例 #1
0
ファイル: main.py プロジェクト: guhappranavk/idb
async def gen_main(cmd_input: Optional[List[str]] = None, ) -> int:
    # Make sure all files are created with global rw permissions
    os.umask(0o000)
    # Setup parser
    parser = argparse.ArgumentParser(
        description=
        "idb: a versatile tool to communicate with iOS Simulators and Devices",
        epilog="See Also: https://www.fbidb.io/docs/guided-tour",
        formatter_class=argparse.RawTextHelpFormatter,
    )
    parser.add_argument(
        "--log",
        dest="log_level",
        choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
        default="WARNING",
        help="Set the logging level",
    )
    parser.add_argument(
        "--companion",
        type=str,
        default=os.environ.get("IDB_COMPANION"),
        help=
        "A string of the form HOSTNAME:PORT that will describe the companion connect to."
        "Can also be set with the IDB_COMPANION environment variable",
    )
    parser.add_argument(
        "--companion-path",
        type=str,
        default="/usr/local/bin/idb_companion",
        help="The path to the idb companion binary",
    )
    commands: List[Command] = [
        AppInstallCommand(),
        AppUninstallCommand(),
        AppListCommand(),
        LaunchCommand(),
        AppTerminateCommand(),
        CommandGroup(
            name="xctest",
            description="Operations with xctest on target",
            commands=[
                XctestInstallCommand(),
                XctestsListBundlesCommand(),
                XctestListTestsCommand(),
                XctestRunCommand(),
            ],
        ),
        CommandGroup(
            name="file",
            description="File operations on target",
            commands=[
                FSMoveCommand(),
                FSPullCommand(),
                FSPushCommand(),
                FSMkdirCommand(),
                FSRemoveCommand(),
                FSListCommand(),
            ],
        ),
        CommandGroup(
            name="contacts",
            description="Contacts database operations on target",
            commands=[ContactsUpdateCommand()],
        ),
        LogCommand(),
        CommandGroup(
            name="record",
            description="Record what the screen is doing",
            commands=[RecordVideoCommand()],
        ),
        RecordVideoCommand(),
        DeprecatedPushCommand(),
        DeprecatedPullCommand(),
        UrlOpenCommand(),
        KeychainClearCommand(),
        LocationSetCommand(),
        ApproveCommand(),
        TargetConnectCommand(),
        TargetDisconnectCommand(),
        TargetListCommand(),
        TargetDescribeCommand(),
        TargetBootCommand(),
        DaemonCommand(),
        ScreenshotCommand(),
        CommandGroup(
            name="ui",
            description="UI interactions on target",
            commands=[
                AccessibilityInfoAllCommand(),
                AccessibilityInfoAtPointCommand(),
                TapCommand(),
                ButtonCommand(),
                TextCommand(),
                KeyCommand(),
                KeySequenceCommand(),
                SwipeCommand(),
            ],
        ),
        CommandGroup(
            name="crash",
            description="Operations on crashes",
            commands=[
                CrashListCommand(),
                CrashShowCommand(),
                CrashDeleteCommand()
            ],
        ),
        InstrumentsCommand(),
        KillCommand(),
        MediaAddCommand(),
        FocusCommand(),
        CommandGroup(
            name="debugserver",
            description="debugserver interactions",
            commands=[
                DebugServerStartCommand(),
                DebugServerStopCommand(),
                DebugServerStatusCommand(),
            ],
        ),
        CommandGroup(name="dsym",
                     description="dsym commands",
                     commands=[DsymInstallCommand()]),
        CommandGroup(name="dylib",
                     description="dylib commands",
                     commands=[DylibInstallCommand()]),
        CommandGroup(
            name="framework",
            description="framework commands",
            commands=[FrameworkInstallCommand()],
        ),
        CommandGroup(
            name="companion",
            description="commands related to the companion",
            commands=[CompanionLogCommand()],
        ),
    ]
    commands.extend(plugin.get_commands())
    root_command = CommandGroup(
        name="root_command",
        description="",
        commands=sorted(commands, key=lambda command: command.name),
    )
    root_command.add_parser_arguments(parser)

    # Parse input and run
    cmd_input = cmd_input or sys.argv[1:]

    try:
        args = parser.parse_args(cmd_input)
        plugin.on_launch(logger)
        await root_command.run(args)
        return 0
    except ConnectCommandException as e:
        print(str(e), file=sys.stderr)
        return 1
    except IdbException as e:
        print(e.args[0], file=sys.stderr)
        return 1
    except Exception:
        logger.exception("Exception thrown in main")
        return 1
    finally:
        await plugin.on_close(logger)
        pending = set(asyncio.all_tasks())
        current_task = asyncio.current_task()
        if current_task is not None:
            pending.discard(current_task)
        await drain_coroutines(pending)
コード例 #2
0
ファイル: main.py プロジェクト: avistyles/FBSimulatorControl
async def gen_main(cmd_input: Optional[List[str]] = None) -> int:
    # Make sure all files are created with global rw permissions
    os.umask(0o000)
    # Setup parser
    parser = argparse.ArgumentParser(
        description=
        "idb: a versatile tool to communicate with iOS Simulators and Devices",
        epilog="See Also: https://www.fbidb.io/docs/guided-tour",
        formatter_class=argparse.RawTextHelpFormatter,
    )
    parser.add_argument(
        "--log",
        dest="log_level",
        choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
        default="WARNING",
        help="Set the logging level",
    )
    parser.add_argument(
        "--compression",
        dest="compression",
        choices=[str(key) for (key, _) in Compression.__members__.items()],
        default=None,
        help="Compression algorithm, default: GZIP. "
        "Compressor should be available at this host. "
        "Decompressor should be available at the destination site (where IDB companion is hosted)",
    )
    parser.add_argument(
        "--companion",
        type=str,
        default=os.environ.get("IDB_COMPANION"),
        help=
        "A string of the form HOSTNAME:PORT that will describe the companion connect to."
        "Can also be set with the IDB_COMPANION environment variable",
    )
    parser.add_argument(
        "--companion-path",
        type=str,
        default=get_default_companion_path(),
        help=
        "The path to the idb companion binary. This is only valid when running on macOS platforms",
    )
    parser.add_argument(
        "--companion-local",
        action="store_true",
        default=bool(os.environ.get("IDB_COMPANION_LOCAL")),
        help=
        "If set, any companion provided via IDB_COMPANION or --companion will be assumed to be running on this host."
        "Even if the companion provided is 'localhost' idb will still assume it is remote."
        "The reason for this is that idb shouldn't assume there are no tunnels from localhost to a remote host."
        "Can also be set with the IDB_COMPANION_LOCAL environment variable",
    )
    parser.add_argument(
        "--companion-tls",
        action="store_true",
        default=bool(os.environ.get("IDB_COMPANION_TLS")),
        help=
        "Will force idb client to use TLS encrypted connection to companion."
        "Can also be set with the IDB_COMPANION_TLS environment variable",
    )
    parser.add_argument(
        "--no-prune-dead-companion",
        dest="prune_dead_companion",
        action="store_false",
        default=True,
        help=
        "If flagged will not modify local state when a companion is known to be unresponsive",
    )
    shell_command = ShellCommand(parser=parser)
    commands: List[Command] = [
        AppInstallCommand(),
        AppUninstallCommand(),
        AppListCommand(),
        LaunchCommand(),
        AppTerminateCommand(),
        CommandGroup(
            name="xctest",
            description="Operations with xctest on target",
            commands=[
                XctestInstallCommand(),
                XctestsListBundlesCommand(),
                XctestListTestsCommand(),
                XctestRunCommand,
            ],
        ),
        CommandGroup(
            name="file",
            description="File operations on target",
            commands=[
                FSMoveCommand(),
                FSPullCommand(),
                FSPushCommand(),
                FSMkdirCommand(),
                FSRemoveCommand(),
                FSListCommand(),
                FBSReadCommand(),
                FSWriteCommand(),
            ],
        ),
        CommandGroup(
            name="contacts",
            description="Contacts database operations on target",
            commands=[ContactsUpdateCommand()],
        ),
        LogCommand(),
        CommandGroup(
            name="record",
            description="Record what the screen is doing",
            commands=[VideoRecordCommand()],
        ),
        VideoRecordCommand(),
        VideoStreamCommand(),
        UrlOpenCommand(),
        KeychainClearCommand(),
        LocationSetCommand(),
        ApproveCommand(),
        TargetConnectCommand(),
        TargetDisconnectCommand(),
        TargetListCommand(),
        TargetDescribeCommand(),
        TargetCreateCommand(),
        TargetBootCommand(),
        TargetShutdownCommand(),
        TargetEraseCommand(),
        TargetCloneCommand(),
        TargetDeleteCommand(),
        TargetDeleteAllCommand(),
        DaemonCommand(),
        ScreenshotCommand(),
        CommandGroup(
            name="ui",
            description="UI interactions on target",
            commands=[
                AccessibilityInfoAllCommand(),
                AccessibilityInfoAtPointCommand(),
                TapCommand(),
                ButtonCommand(),
                TextCommand(),
                KeyCommand(),
                KeySequenceCommand(),
                SwipeCommand(),
            ],
        ),
        CommandGroup(
            name="crash",
            description="Operations on crashes",
            commands=[
                CrashListCommand(),
                CrashShowCommand(),
                CrashDeleteCommand()
            ],
        ),
        InstrumentsCommand(),
        KillCommand(),
        MediaAddCommand(),
        FocusCommand(),
        CommandGroup(
            name="debugserver",
            description="debugserver interactions",
            commands=[
                DebugServerStartCommand(),
                DebugServerStopCommand(),
                DebugServerStatusCommand(),
            ],
        ),
        CommandGroup(name="dsym",
                     description="dsym commands",
                     commands=[DsymInstallCommand()]),
        CommandGroup(name="dylib",
                     description="dylib commands",
                     commands=[DylibInstallCommand()]),
        CommandGroup(
            name="framework",
            description="framework commands",
            commands=[FrameworkInstallCommand()],
        ),
        CommandGroup(
            name="companion",
            description="commands related to the companion",
            commands=[CompanionLogCommand()],
        ),
        CommandGroup(
            name="xctrace",
            description="Run xctrace commands",
            commands=[XctraceRecordCommand()],
        ),
        SetCommand,
        GetCommand,
        ListCommand,
        shell_command,
    ]
    commands.extend(plugin.get_commands())
    root_command = CommandGroup(
        name="root_command",
        description="",
        commands=sorted(commands, key=lambda command: command.name),
    )
    root_command.add_parser_arguments(parser)
    shell_command.root_command = root_command

    # Parse input and run
    cmd_input = cmd_input or sys.argv[1:]

    try:
        args = parser.parse_args(cmd_input)
        plugin.on_launch(logger)
        await root_command.run(args)
        return 0
    except ConnectCommandException as e:
        print(str(e), file=sys.stderr)
        return 1
    except IdbException as e:
        print(e.args[0], file=sys.stderr)
        return 1
    except ExitWithCodeException as e:
        return e.exit_code
    except SystemExit as e:
        return e.code
    except Exception:
        logger.exception("Exception thrown in main")
        return 1
    finally:
        await plugin.on_close(logger)
        pending = set(asyncio.all_tasks())
        current_task = asyncio.current_task()
        if current_task is not None:
            pending.discard(current_task)
        await drain_coroutines(pending)
コード例 #3
0
ファイル: main.py プロジェクト: zeng4250538/idb
async def gen_main(cmd_input: Optional[List[str]] = None, ) -> int:
    # Setup parser
    parser = argparse.ArgumentParser(
        description=
        "idb: a versatile tool to communicate with iOS Simulators and Devices",
        epilog="See Also: https://www.fbidb.io/docs/guided-tour",
        formatter_class=argparse.RawTextHelpFormatter,
    )
    commands: List[Command] = [
        DescribeCommand(),
        AppInstallCommand(),
        AppUninstallCommand(),
        ListAppsCommand(),
        LaunchCommand(),
        AppTerminateCommand(),
        CommandGroup(
            name="xctest",
            description="Operations with xctest on target",
            commands=[
                XctestInstallCommand(),
                XctestsListBundlesCommand(),
                XctestListTestsCommand(),
                XctestRunCommand(),
            ],
        ),
        CommandGroup(
            name="file",
            description="File operations on target",
            commands=[
                FSMoveCommand(),
                FSPullCommand(),
                FSPushCommand(),
                FSMkdirCommand(),
                FSRemoveCommand(),
                FSListCommand(),
            ],
        ),
        CommandGroup(
            name="contacts",
            description="Contacts database operations on target",
            commands=[ContactsUpdateCommand()],
        ),
        LogCommand(),
        CommandGroup(
            name="record",
            description="Record what the screen is doing",
            commands=[RecordVideoCommand()],
        ),
        RecordVideoCommand(),
        DeprecatedPushCommand(),
        DeprecatedPullCommand(),
        OpenUrlCommand(),
        ClearKeychainCommand(),
        SetLocationCommand(),
        ApproveCommand(),
        ConnectCommand(),
        DisconnectCommand(),
        ListTargetsCommand(),
        DaemonCommand(),
        ScreenshotCommand(),
        CommandGroup(
            name="ui",
            description="UI interactions on target",
            commands=[
                AccessibilityInfoAllCommand(),
                AccessibilityInfoAtPointCommand(),
                TapCommand(),
                ButtonCommand(),
                TextCommand(),
                KeyCommand(),
                KeySequenceCommand(),
                SwipeCommand(),
            ],
        ),
        CommandGroup(
            name="crash",
            description="Operations on crashes",
            commands=[
                CrashListCommand(),
                CrashShowCommand(),
                CrashDeleteCommand()
            ],
        ),
        InstrumentsCommand(),
        KillCommand(),
        AddMediaCommand(),
        FocusCommand(),
        BootCommand(),
        CommandGroup(
            name="debugserver",
            description="debugserver interactions",
            commands=[
                DebugServerStartCommand(),
                DebugServerStopCommand(),
                DebugServerStatusCommand(),
            ],
        ),
        CommandGroup(name="dsym",
                     description="dsym commands",
                     commands=[DsymInstallCommand()]),
        CommandGroup(name="dylib",
                     description="dylib commands",
                     commands=[DylibInstallCommand()]),
        CommandGroup(
            name="framework",
            description="framework commands",
            commands=[FrameworkInstallCommand()],
        ),
        CommandGroup(
            name="companion",
            description="commands related to the companion",
            commands=[CompanionLogCommand()],
        ),
    ]
    commands.extend(plugin.get_commands())
    sorted_commands = sorted(commands, key=lambda command: command.name)
    root_command = CommandGroup("root_command", "", sorted_commands)
    root_command.add_parser_arguments(parser)

    # Parse input and run
    cmd_input = cmd_input or sys.argv[1:]

    try:
        args = parser.parse_args(cmd_input)
        plugin.on_launch(logger)
        await root_command.run(args)
        return 0
    except ConnectCommandException as e:
        print(str(e))
        return 1
    except IdbException as e:
        print(e.args[0])
        return 1
    except Exception:
        logger.exception("Exception thrown in main")
        return 1
    finally:
        await plugin.on_close(logger)
        pending = set(asyncio.Task.all_tasks())
        pending.discard(asyncio.Task.current_task())
        await drain_coroutines(pending)