def Read(self, expected_ids, read_data=True):
        """Read ADB messages and return FileSync packets."""
        if self.send_buffer:
            self._Flush()

        # Read one filesync packet off the recv buffer.
        header_data = self._ReadBuffered(self.recv_header_len)
        header = struct.unpack(self.recv_header_format, header_data)
        # Header is (ID, ...).
        command_id = self.wire_to_id[header[0]]

        if command_id not in expected_ids:
            if command_id == 'FAIL':
                raise usb_exceptions.AdbCommandFailureException(
                    'Command failed.')
            raise adb_protocol.InvalidResponseError(
                'Expected one of %s, got %s' % (expected_ids, command_id))

        if not read_data:
            return command_id, header[1:]

        # Header is (ID, ..., size).
        size = header[-1]
        data = self._ReadBuffered(size)
        return command_id, header[1:-1], data
    def Stat(connection, filename):
        cnxn = FileSyncConnection(connection, '<4I')
        cnxn.Send('STAT', filename)
        command, (mode, size, mtime) = cnxn.Read(('STAT', ), read_data=False)

        if command != 'STAT':
            raise adb_protocol.InvalidResponseError(
                'Expected STAT response to STAT, got %s' % command)
        return mode, size, mtime
Beispiel #3
0
    def Stat(connection, filename):
        if isinstance(filename, unicode):
            filename = filename.encode('utf-8')
        cnxn = FileSyncConnection(connection, '<4I')
        cnxn.Send('STAT', filename)
        command, (mode, size, mtime) = cnxn.ReadNoData(('STAT', ))

        if command != 'STAT':
            raise adb_protocol.InvalidResponseError(
                'Expected STAT response to STAT, got %s' % command)
        return mode, size, mtime
Beispiel #4
0
 def _VerifyReplyCommand(cls, header, expected_ids):
     # Header is (ID, ...).
     command_id = adb_protocol.Wire2ID(header[0])
     if command_id not in cls._VALID_IDS:
         raise usb_exceptions.AdbCommandFailureException(
             'Command failed; incorrect header: %s' % header)
     if command_id not in expected_ids:
         if command_id == 'FAIL':
             raise usb_exceptions.AdbCommandFailureException(
                 'Command failed.')
         raise adb_protocol.InvalidResponseError(
             'Expected one of %s, got %s' % (expected_ids, command_id))
     return command_id