<s> """<STR_LIT>""" <EOL> import argparse <EOL> import functools <EOL> import logging <EOL> import os <EOL> import stat <EOL> import sys <EOL> import time <EOL> from adb import adb_commands <EOL> from adb import common_cli <EOL> try : <EOL> from adb import sign_m2crypto <EOL> rsa_signer = sign_m2crypto . M2CryptoSigner <EOL> except ImportError : <EOL> try : <EOL> from adb import sign_pythonrsa <EOL> rsa_signer = sign_pythonrsa . PythonRSASigner . FromRSAKeyPath <EOL> except ImportError : <EOL> rsa_signer = None <EOL> def Devices ( args ) : <EOL> """<STR_LIT>""" <EOL> for d in adb_commands . AdbCommands . Devices ( ) : <EOL> if args . output_port_path : <EOL> print ( '<STR_LIT>' % ( <EOL> d . serial_number , '<STR_LIT:U+002C>' . join ( str ( p ) for p in d . port_path ) ) ) <EOL> else : <EOL> print ( '<STR_LIT>' % d . serial_number ) <EOL> return <NUM_LIT:0> <EOL> def List ( self , device_path ) : <EOL> """<STR_LIT>""" <EOL> files = adb_commands . AdbCommands . List ( self , device_path ) <EOL> files . sort ( key = lambda x : x . filename ) <EOL> maxname = max ( len ( f . filename ) for f in files ) <EOL> maxsize = max ( len ( str ( f . size ) ) for f in files ) <EOL> for f in files : <EOL> mode = ( <EOL> ( '<STR_LIT:d>' if stat . S_ISDIR ( f . mode ) else '<STR_LIT:->' ) + <EOL> ( '<STR_LIT:r>' if f . mode & stat . S_IRUSR else '<STR_LIT:->' ) + <EOL> ( '<STR_LIT:w>' if f . mode & stat . S_IWUSR else '<STR_LIT:->' ) + <EOL> ( '<STR_LIT:x>' if f . mode & stat . S_IXUSR else '<STR_LIT:->' ) + <EOL> ( '<STR_LIT:r>' if f . mode & stat . S_IRGRP else '<STR_LIT:->' ) + <EOL> ( '<STR_LIT:w>' if f . mode & stat . S_IWGRP else '<STR_LIT:->' ) + <EOL> ( '<STR_LIT:x>' if f . mode & stat . S_IXGRP else '<STR_LIT:->' ) + <EOL> ( '<STR_LIT:r>' if f . mode & stat . S_IROTH else '<STR_LIT:->' ) + <EOL> ( '<STR_LIT:w>' if f . mode & stat . S_IWOTH else '<STR_LIT:->' ) + <EOL> ( '<STR_LIT:x>' if f . mode & stat . S_IXOTH else '<STR_LIT:->' ) ) <EOL> t = time . gmtime ( f . mtime ) <EOL> yield '<STR_LIT>' % ( <EOL> mode , maxsize , f . size , <EOL> t . tm_year , t . tm_mon , t . tm_mday , t . tm_hour , t . tm_min , t . tm_sec , <EOL> maxname , f . filename ) <EOL> @ functools . wraps ( adb_commands . AdbCommands . Logcat ) <EOL> def Logcat ( self , * options ) : <EOL> return adb_commands . AdbCommands . Logcat ( self , '<STR_LIT:U+0020>' . join ( options ) ) <EOL> def Shell ( self , * command ) : <EOL> """<STR_LIT>""" <EOL> return adb_commands . AdbCommands . StreamingShell ( self , '<STR_LIT:U+0020>' . join ( command ) ) <EOL> def main ( ) : <EOL> common = common_cli . GetCommonArguments ( ) <EOL> common . add_argument ( <EOL> '<STR_LIT>' , action = '<STR_LIT>' , default = [ ] , <EOL> metavar = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> common . add_argument ( <EOL> '<STR_LIT>' , default = <NUM_LIT> , metavar = '<STR_LIT>' , type = int , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> device = common_cli . GetDeviceArguments ( ) <EOL> parents = [ common , device ] <EOL> parser = argparse . ArgumentParser ( <EOL> description = sys . modules [ __name__ ] . __doc__ , parents = [ common ] ) <EOL> subparsers = parser . add_subparsers ( title = '<STR_LIT>' , dest = '<STR_LIT>' ) <EOL> subparser = subparsers . add_parser ( <EOL> name = '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> subparser = subparsers . add_parser ( <EOL> name = '<STR_LIT>' , help = '<STR_LIT>' , parents = [ common ] ) <EOL> subparser . add_argument ( <EOL> '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> common_cli . MakeSubparser ( <EOL> subparsers , parents , adb_commands . AdbCommands . Install ) <EOL> common_cli . MakeSubparser ( subparsers , parents , List ) <EOL> common_cli . MakeSubparser ( subparsers , parents , Logcat ) <EOL> common_cli . MakeSubparser ( <EOL> subparsers , parents , adb_commands . AdbCommands . Push , <EOL> { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> common_cli . MakeSubparser ( <EOL> subparsers , parents , adb_commands . AdbCommands . Pull , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> } ) <EOL> common_cli . MakeSubparser ( <EOL> subparsers , parents , adb_commands . AdbCommands . Reboot ) <EOL> common_cli . MakeSubparser ( <EOL> subparsers , parents , adb_commands . AdbCommands . RebootBootloader ) <EOL> common_cli . MakeSubparser ( <EOL> subparsers , parents , adb_commands . AdbCommands . Remount ) <EOL> common_cli . MakeSubparser ( subparsers , parents , adb_commands . AdbCommands . Root ) <EOL> common_cli . MakeSubparser ( subparsers , parents , Shell ) <EOL> if len ( sys . argv ) == <NUM_LIT:1> : <EOL> parser . print_help ( ) <EOL> return <NUM_LIT:2> <EOL> args = parser . parse_args ( ) <EOL> if args . verbose : <EOL> logging . basicConfig ( level = logging . DEBUG ) <EOL> if not args . rsa_key_path : <EOL> default = os . path . expanduser ( '<STR_LIT>' ) <EOL> if os . path . isfile ( default ) : <EOL> args . rsa_key_path = [ default ] <EOL> if args . rsa_key_path and not rsa_signer : <EOL> parser . error ( '<STR_LIT>' ) <EOL> if args . command_name == '<STR_LIT>' : <EOL> return Devices ( args ) <EOL> if args . command_name == '<STR_LIT>' : <EOL> parser . print_help ( ) <EOL> return <NUM_LIT:0> <EOL> if args . command_name == '<STR_LIT>' : <EOL> args . positional = args . options <EOL> elif args . command_name == '<STR_LIT>' : <EOL> args . positional = args . command <EOL> return common_cli . StartCli ( <EOL> args , <EOL> adb_commands . AdbCommands . ConnectDevice , <EOL> auth_timeout_ms = args . auth_timeout_s * <NUM_LIT:1000> , <EOL> rsa_keys = [ rsa_signer ( path ) for path in args . rsa_key_path ] ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> sys . exit ( main ( ) ) </s>
