Skip to content
This repository was archived by the owner on Jan 10, 2023. It is now read-only.
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 36 additions & 13 deletions adb/adb_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import cStringIO
import os
import socket
import stat

from M2Crypto import RSA

Expand Down Expand Up @@ -171,19 +172,41 @@ def Pull(self, device_filename, dest_file=None, timeout_ms=None):
Returns:
The file data if dest_file is not set.
"""
if isinstance(dest_file, basestring):
dest_file = open(dest_file, 'w')
elif not dest_file:
dest_file = cStringIO.StringIO()
connection = self.protocol_handler.Open(
self.handle, destination='sync:',
timeout_ms=timeout_ms)
self.filesync_handler.Pull(connection, device_filename, dest_file)
connection.Close()
# An empty call to cStringIO.StringIO returns an instance of
# cStringIO.OutputType.
if isinstance(dest_file, cStringIO.OutputType):
return dest_file.getvalue()

if dest_file:
print("pull: %s -> %s" % (device_filename, dest_file))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No printing, please. Also, instead of an assert on 182, raise a custom error or something like ValueError that can be caught more specifically than the generic AssertionError.


filemode, _, _= self.Stat(device_filename)

if stat.S_ISDIR(filemode):
assert dest_file, "Must specify out dir when pulling a directory"
file_list = self.List(device_filename)
if not os.path.exists(dest_file):
os.makedirs(dest_file)

for device_file in file_list:
if device_file.filename not in (".", ".."):
self.Pull(
os.path.join(device_filename, device_file.filename),
os.path.join(dest_file, device_file.filename) if dest_file else None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dest_file can't be None, so are you expecting it to be an empty string? If so, os.path.join('', filename) == filename, so it shouldn't matter. The only other case is if dest_file is False or something falsey but not a string, which should be caught in the check above (by it failing or os.path.exists failing)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So from where I'm sitting, this really only means that the conditional at L189 should be removed. Is that correct?

)

else:
if stat.S_ISLNK(filemode) or stat.S_ISSOCK(filemode):
return
if isinstance(dest_file, basestring):
dest_file = open(dest_file, 'w')
elif not dest_file:
dest_file = cStringIO.StringIO()
connection = self.protocol_handler.Open(
self.handle, destination='sync:',
timeout_ms=timeout_ms)
self.filesync_handler.Pull(connection, device_filename, dest_file)
connection.Close()
# An empty call to cStringIO.StringIO returns an instance of
# cStringIO.OutputType.
if isinstance(dest_file, cStringIO.OutputType):
return dest_file.getvalue()

def Stat(self, device_filename):
"""Get a file's stat() information."""
Expand Down