Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

ValueError while calling AdbCommands.Pull with a file object #124

Open
FlandiaYingman opened this issue Sep 16, 2018 · 3 comments
Open

ValueError while calling AdbCommands.Pull with a file object #124

FlandiaYingman opened this issue Sep 16, 2018 · 3 comments

Comments

@FlandiaYingman
Copy link

Like that:

with open("something", "wb") as file:
    device.Pull("filepath", file)
@vBlackOut
Copy link

vBlackOut commented Sep 20, 2018

use

is not necessary open your file after
just write:

device.Pull("path_file_into_device", "your_local_file")

@FlandiaYingman
Copy link
Author

use

is not necessary open your file after
just write:

device.Pull("path_file_into_device", "your_local_file")

The doc says it could accepts a opened file.
And, Pull opens file in text mode, always.

@vBlackOut
Copy link

vBlackOut commented Sep 26, 2018

look this function doesn't check if file is open or no...

def Pull(self, device_filename, dest_file=None, timeout_ms=None, progress_callback=None):
        """Pull a file from the device.
        Args:
          device_filename: Filename on the device to pull.
          dest_file: If set, a filename or writable file-like object.
          timeout_ms: Expected timeout for any part of the pull.
          progress_callback: callback method that accepts filename, bytes_written and total_bytes,
                             total_bytes will be -1 for file-like objects
        Returns:
          The file data if dest_file is not set. Otherwise, True if the destination file exists
        """
        if not dest_file:
            dest_file = io.BytesIO()
        elif isinstance(dest_file, str):
            dest_file = open(dest_file, 'wb')
        elif isinstance(dest_file, file):
            pass
        else:
            raise ValueError("destfile is of unknown type")

        conn = self.protocol_handler.Open(
            self._handle, destination=b'sync:', timeout_ms=timeout_ms)

        self.filesync_handler.Pull(conn, device_filename, dest_file, progress_callback)

        conn.Close()
        if isinstance(dest_file, io.BytesIO):
            return dest_file.getvalue()
        else:
            dest_file.close()
            if hasattr(dest_file, 'name'):
                return os.path.exists(dest_file.name)
            # We don't know what the path is, so we just assume it exists.
            return True

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants