Exemple #1
0
def main():
    common = common_cli.GetCommonArguments()
    common.add_argument(
        '--rsa_key_path',
        action='append',
        default=[],
        metavar='~/.android/adbkey',
        help='RSA key(s) to use, use multiple times to load mulitple keys')
    common.add_argument(
        '--auth_timeout_s',
        default=60.,
        metavar='60',
        type=int,
        help='Seconds to wait for the dialog to be accepted when using '
        'authenticated ADB.')
    device = common_cli.GetDeviceArguments()
    parents = [common, device]

    parser = argparse.ArgumentParser(description=sys.modules[__name__].__doc__,
                                     parents=[common])
    subparsers = parser.add_subparsers(title='Commands', dest='command_name')

    subparser = subparsers.add_parser(name='help',
                                      help='Prints the commands available')
    subparser = subparsers.add_parser(name='devices',
                                      help='Lists the available devices',
                                      parents=[common])
    subparser.add_argument('--output_port_path',
                           action='store_true',
                           help='Outputs the port_path alongside the serial')
    subparser = subparsers.add_parser(name='keygen',
                                      help='generate adb public/private key '
                                      'private key stored in {filepath} '
                                      'public key stored in {filepath}.pub '
                                      '(existing files overwritten)')
    subparser.add_argument(
        'filepath',
        help=
        'File path to write the private/public keypair (existing files overwritten)'
    )

    common_cli.MakeSubparser(subparsers, parents,
                             adb_commands.AdbCommands.Install)
    common_cli.MakeSubparser(subparsers, parents,
                             adb_commands.AdbCommands.Uninstall)
    common_cli.MakeSubparser(subparsers, parents, List)
    common_cli.MakeSubparser(subparsers, parents, Logcat)
    common_cli.MakeSubparser(
        subparsers, parents, adb_commands.AdbCommands.Push,
        {'source_file': 'Filename or directory to push to the device.'})
    common_cli.MakeSubparser(
        subparsers, parents, adb_commands.AdbCommands.Pull, {
            'dest_file':
            'Filename to write to on the host, if not specified, '
            'prints the content to stdout.',
        })
    common_cli.MakeSubparser(subparsers, parents,
                             adb_commands.AdbCommands.Reboot)
    common_cli.MakeSubparser(subparsers, parents,
                             adb_commands.AdbCommands.RebootBootloader)
    common_cli.MakeSubparser(subparsers, parents,
                             adb_commands.AdbCommands.Remount)
    common_cli.MakeSubparser(subparsers, parents,
                             adb_commands.AdbCommands.Root)
    common_cli.MakeSubparser(subparsers, parents,
                             adb_commands.AdbCommands.EnableVerity)
    common_cli.MakeSubparser(subparsers, parents,
                             adb_commands.AdbCommands.DisableVerity)
    common_cli.MakeSubparser(subparsers, parents, Shell)

    if len(sys.argv) == 1:
        parser.print_help()
        return 2

    args = parser.parse_args()
    if args.verbose:
        logging.basicConfig(level=logging.DEBUG)
    if not args.rsa_key_path:
        default = os.path.expanduser('~/.android/adbkey')
        if os.path.isfile(default):
            args.rsa_key_path = [default]
    if args.rsa_key_path and not rsa_signer:
        parser.error(
            'Please install either cryptography, python-rsa, or PycryptoDome')

    # Hacks so that the generated doc is nicer.
    if args.command_name == 'devices':
        return Devices(args)
    if args.command_name == 'help':
        parser.print_help()
        return 0
    if args.command_name == 'keygen':
        return android_pubkey.keygen(args.filepath)
    if args.command_name == 'logcat':
        args.positional = args.options
    elif args.command_name == 'shell':
        args.positional = args.command

    return common_cli.StartCli(
        args,
        adb_commands.AdbCommands,
        auth_timeout_ms=int(args.auth_timeout_s * 1000),
        rsa_keys=[rsa_signer(path) for path in args.rsa_key_path])
Exemple #2
0
def main():
    common = common_cli.GetCommonArguments()
    device = common_cli.GetDeviceArguments()
    device.add_argument(
        '--chunk_kb',
        type=int,
        default=1024,
        metavar='1024',
        help='Size of packets to write in Kb. For older devices, it may be '
        'required to use 4.')
    parents = [common, device]

    parser = argparse.ArgumentParser(description=sys.modules[__name__].__doc__,
                                     parents=[common])
    subparsers = parser.add_subparsers(title='Commands', dest='command_name')

    subparser = subparsers.add_parser(name='help',
                                      help='Prints the commands available')
    subparser = subparsers.add_parser(name='devices',
                                      help='Lists the available devices',
                                      parents=[common])
    common_cli.MakeSubparser(subparsers, parents,
                             fastboot.FastbootCommands.Continue)

    common_cli.MakeSubparser(subparsers, parents,
                             fastboot.FastbootCommands.Download,
                             {'source_file': 'Filename on the host to push'})
    common_cli.MakeSubparser(subparsers, parents,
                             fastboot.FastbootCommands.Erase)
    common_cli.MakeSubparser(subparsers, parents,
                             fastboot.FastbootCommands.Flash)
    common_cli.MakeSubparser(subparsers, parents,
                             fastboot.FastbootCommands.Getvar)
    common_cli.MakeSubparser(subparsers, parents,
                             fastboot.FastbootCommands.Oem)
    common_cli.MakeSubparser(subparsers, parents,
                             fastboot.FastbootCommands.Reboot)

    if len(sys.argv) == 1:
        parser.print_help()
        return 2

    args = parser.parse_args()
    if args.verbose:
        logging.basicConfig(level=logging.DEBUG)
    if args.command_name == 'devices':
        return Devices(args)
    if args.command_name == 'help':
        parser.print_help()
        return 0

    kwargs = {}
    argspec = inspect.getargspec(args.method)
    if 'info_cb' in argspec.args:
        kwargs['info_cb'] = _InfoCb
    if 'progress_callback' in argspec.args and progressbar:
        bar = progressbar.ProgessBar(
            widgets=[progressbar.Bar(),
                     progressbar.Percentage()])
        bar.start()

        def SetProgress(current, total):
            bar.update(current / total * 100.0)
            if current == total:
                bar.finish()

        kwargs['progress_callback'] = SetProgress

    return common_cli.StartCli(args,
                               fastboot.FastbootCommands,
                               chunk_kb=args.chunk_kb,
                               extra=kwargs)