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

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

Open

Description

@flandia

Like that:

with open("something", "wb") as file:
    device.Pull("filepath", file)

Activity

  1. vBlackOut commented on Sep 20, 2018

    @vBlackOut

    use

    is not necessary open your file after
    just write:

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

  2. flandia commented on Sep 22, 2018

    @flandia
    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.

  3. vBlackOut commented on Sep 26, 2018

    @vBlackOut

    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 join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions