Skip to content

Commit cd354ef

Browse files
committed
'documentation' branch: remove comments and apply black formatting
1 parent 6008066 commit cd354ef

12 files changed

+245
-122
lines changed

adb/adb_commands.py

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,22 @@
77
from adb import common
88
from adb import filesync_protocol
99

10+
try:
11+
file_types = (file, io.IOBase)
12+
except NameError:
13+
file_types = (io.IOBase,)
14+
1015

1116
CLASS = 0xFF
17+
18+
1219
SUBCLASS = 0x42
13-
PROTOCOL = 0x01
1420

15-
DeviceIsAvailable = common.InterfaceMatcher(CLASS, SUBCLASS, PROTOCOL)
1621

17-
try:
22+
PROTOCOL = 0x01
1823

19-
from adb.sign_cryptography import CryptographySigner
20-
except ImportError:
2124

22-
pass
25+
DeviceIsAvailable = common.InterfaceMatcher(CLASS, SUBCLASS, PROTOCOL)
2326

2427

2528
class AdbCommands(object):
@@ -28,16 +31,15 @@ class AdbCommands(object):
2831
filesync_handler = filesync_protocol.FilesyncProtocol
2932

3033
def __init__(self):
31-
32-
self.__reset()
33-
34-
def __reset(self):
3534
self.build_props = None
36-
self._handle = None
3735
self._device_state = None
38-
36+
self._handle = None
3937
self._service_connections = {}
4038

39+
def __reset(self):
40+
41+
self.__init__()
42+
4143
def _get_service_connection(
4244
self, service, service_command=None, create=True, timeout_ms=None
4345
):
@@ -89,6 +91,7 @@ def ConnectDevice(
8991
return self
9092

9193
def Close(self):
94+
9295
for conn in list(self._service_connections.values()):
9396
if conn:
9497
try:
@@ -121,6 +124,7 @@ def Devices(cls):
121124
return common.UsbHandle.FindDevices(DeviceIsAvailable)
122125

123126
def GetState(self):
127+
124128
return self._device_state
125129

126130
def Install(
@@ -154,7 +158,7 @@ def Install(
154158
ret = self.Shell(" ".join(cmd), timeout_ms=timeout_ms)
155159

156160
rm_cmd = ["rm", destination_path]
157-
rmret = self.Shell(" ".join(rm_cmd), timeout_ms=timeout_ms)
161+
self.Shell(" ".join(rm_cmd), timeout_ms=timeout_ms)
158162

159163
return ret
160164

@@ -214,10 +218,10 @@ def Pull(
214218
dest_file = io.BytesIO()
215219
elif isinstance(dest_file, str):
216220
dest_file = open(dest_file, "wb")
217-
elif isinstance(dest_file, file):
221+
elif isinstance(dest_file, file_types):
218222
pass
219223
else:
220-
raise ValueError("destfile is of unknown type")
224+
raise ValueError("dest_file is of unknown type")
221225

222226
conn = self.protocol_handler.Open(
223227
self._handle, destination=b"sync:", timeout_ms=timeout_ms
@@ -228,12 +232,12 @@ def Pull(
228232
conn.Close()
229233
if isinstance(dest_file, io.BytesIO):
230234
return dest_file.getvalue()
231-
else:
232-
dest_file.close()
233-
if hasattr(dest_file, "name"):
234-
return os.path.exists(dest_file.name)
235235

236-
return True
236+
dest_file.close()
237+
if hasattr(dest_file, "name"):
238+
return os.path.exists(dest_file.name)
239+
240+
return True
237241

238242
def Stat(self, device_filename):
239243

adb/adb_debug.py

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def List(device, device_path):
6060
+ ("x" if f.mode & stat.S_IXOTH else "-")
6161
)
6262
t = time.gmtime(f.mtime)
63+
6364
yield "%s %*d %04d-%02d-%02d %02d:%02d:%02d %-*s\n" % (
6465
mode,
6566
maxsize,
@@ -77,37 +78,38 @@ def List(device, device_path):
7778

7879
@functools.wraps(adb_commands.AdbCommands.Logcat)
7980
def Logcat(device, *options):
81+
8082
return device.Logcat(device, " ".join(options), timeout_ms=0)
8183

8284

8385
def Shell(device, *command):
8486

8587
if command:
8688
return device.StreamingShell(" ".join(command))
87-
else:
8889

89-
terminal_prompt = device.InteractiveShell()
90-
print(terminal_prompt.decode("utf-8"))
90+
terminal_prompt = device.InteractiveShell()
91+
print(terminal_prompt.decode("utf-8"))
9192

92-
while True:
93-
cmd = input("> ")
94-
if not cmd:
95-
continue
96-
elif cmd == "exit":
97-
break
98-
else:
99-
stdout = device.InteractiveShell(
100-
cmd, strip_cmd=True, delim=terminal_prompt, strip_delim=True
101-
)
102-
if stdout:
103-
if isinstance(stdout, bytes):
104-
stdout = stdout.decode("utf-8")
105-
print(stdout)
93+
while True:
94+
cmd = input("> ")
95+
if not cmd:
96+
continue
97+
elif cmd == "exit":
98+
break
99+
else:
100+
stdout = device.InteractiveShell(
101+
cmd, strip_cmd=True, delim=terminal_prompt, strip_delim=True
102+
)
103+
if stdout:
104+
if isinstance(stdout, bytes):
105+
stdout = stdout.decode("utf-8")
106+
print(stdout)
106107

107-
device.Close()
108+
device.Close()
108109

109110

110111
def main():
112+
111113
common = common_cli.GetCommonArguments()
112114
common.add_argument(
113115
"--rsa_key_path",
@@ -121,9 +123,9 @@ def main():
121123
default=60.0,
122124
metavar="60",
123125
type=int,
124-
help="Seconds to wait for the dialog to be accepted when using "
125-
"authenticated ADB.",
126+
help="Seconds to wait for the dialog to be accepted when using authenticated ADB.",
126127
)
128+
127129
device = common_cli.GetDeviceArguments()
128130
parents = [common, device]
129131

@@ -136,6 +138,7 @@ def main():
136138
subparser = subparsers.add_parser(
137139
name="devices", help="Lists the available devices", parents=[common]
138140
)
141+
139142
subparser.add_argument(
140143
"--output_port_path",
141144
action="store_true",
@@ -157,8 +160,7 @@ def main():
157160
parents,
158161
adb_commands.AdbCommands.Pull,
159162
{
160-
"dest_file": "Filename to write to on the host, if not specified, "
161-
"prints the content to stdout."
163+
"dest_file": "Filename to write to on the host, if not specified, prints the content to stdout."
162164
},
163165
)
164166
common_cli.MakeSubparser(subparsers, parents, adb_commands.AdbCommands.Reboot)
@@ -180,18 +182,22 @@ def main():
180182
args = parser.parse_args()
181183
if args.verbose:
182184
logging.basicConfig(level=logging.DEBUG)
185+
183186
if not args.rsa_key_path:
184187
default = os.path.expanduser("~/.android/adbkey")
185188
if os.path.isfile(default):
186189
args.rsa_key_path = [default]
190+
187191
if args.rsa_key_path and not rsa_signer:
188192
parser.error("Please install either cryptography, python-rsa, or PycryptoDome")
189193

190194
if args.command_name == "devices":
191195
return Devices(args)
196+
192197
if args.command_name == "help":
193198
parser.print_help()
194199
return 0
200+
195201
if args.command_name == "logcat":
196202
args.positional = args.options
197203
elif args.command_name == "shell":

0 commit comments

Comments
 (0)