def GetObjectHandles(self, storageId=0xffffffff, objectFormatId=None, associationId=None): """Get the object handles. Returns: Tuple of object handles.""" params = (storageId, ) if objectFormatId != None: params += (objectFormatId, ) if associationId != None: if objectFormatId == None: params += (0, ) params += (associationId, ) ptp_request = PtpRequest( PtpValues.StandardOperations.GET_OBJECT_HANDLES, self.sessionid, self.NewTransaction(), params) (ptp_response, rx) = self.transport.ptp_simple_transaction(ptp_request, receiving=True) if ptp_response.respcode != PtpValues.StandardResponses.OK: raise PtpException(ptp_response.respcode) unpacker = PtpUnpacker(rx[1]) return unpacker.unpack_array("I")
def CloseSession(self): """Close the PTP session.""" ptp_request = PtpRequest(PtpValues.StandardOperations.CLOSE_SESSION, self.sessionid, self.NewTransaction()) (ptp_response, rx) = self.transport.ptp_simple_transaction(ptp_request) if ptp_response.respcode != PtpValues.StandardResponses.OK: raise PtpException(ptp_response.respcode)
def OpenSession(self): """Open a new session to a PTP device.""" self.sessionid = self.transport.NewSession() self.__transactionid = 0 ptp_request = PtpRequest(PtpValues.StandardOperations.OPEN_SESSION, 0, 0, (self.sessionid, )) (ptp_response, rx) = self.transport.ptp_simple_transaction(ptp_request) if ptp_response.respcode != PtpValues.StandardResponses.OK: raise PtpException(ptp_response.respcode)
def GetObjectInfo(self, objectHandle): """Get information about an object on a PTP device. Returns: A PtpObjectInfo instance.""" ptp_request = PtpRequest(PtpValues.StandardOperations.GET_OBJECT_INFO, self.sessionid, self.NewTransaction(), (objectHandle, )) (ptp_response, rx) = self.transport.ptp_simple_transaction(ptp_request, receiving=True) if ptp_response.respcode != PtpValues.StandardResponses.OK: raise PtpException(ptp_response.respcode) return PtpObjectInfo(rx[1])
def GetDevicePropInfo(self, propertyId): """Get the description of a device property. Returns: A string of bytes.""" ptp_request = PtpRequest(PtpValues.StandardOperations.GET_DEVICE_PROP_DESC, self.sessionid, self.NewTransaction(), (propertyId,)) (ptp_response, rx) = self.transport.ptp_simple_transaction(ptp_request, receiving=True) if ptp_response.respcode != PtpValues.StandardResponses.OK: raise PtpException(ptp_response.respcode) return PtpDevicePropertyInfo(rx[1])
def GetStorageInfo(self, storageId): """Get information about a storage on a PTP device. Returns: A PtpStorageInfo instance.""" ptp_request = PtpRequest(PtpValues.StandardOperations.GET_STORAGE_INFO, self.sessionid, self.NewTransaction(), (storageId, )) (ptp_response, rx) = self.transport.ptp_simple_transaction(ptp_request, receiving=True) if ptp_response.respcode != PtpValues.StandardResponses.OK: raise PtpException(ptp_response.respcode) return PtpStorageInfo(rx[1])
def GetDeviceInfo(self): """Get Device info from a PTP device. Returns: A PtpDeviceInfo instance.""" ptp_request = PtpRequest(PtpValues.StandardOperations.GET_DEVICE_INFO, self.sessionid, self.NewTransaction()) (ptp_response, rx) = self.transport.ptp_simple_transaction(ptp_request, receiving=True) if ptp_response.respcode != PtpValues.StandardResponses.OK: raise PtpException(ptp_response.respcode) return PtpDeviceInfo(rx[1])
def GetPartialObject(self, objectHandle, offset=0, count=0xffffffff, stream=None): """Get a partial object on a PTP device. Returns: A tuple of (object length, and object data (or None if stream was not None)).""" ptp_request = PtpRequest(PtpValues.StandardOperations.GET_PARTIAL_OBJECT, self.sessionid, self.NewTransaction(), (objectHandle, offset, count)) self.transport.send_ptp_request(ptp_request) rx_data = self.transport.get_ptp_data(ptp_request, stream) ptp_response = self.transport.get_ptp_response(ptp_request) if ptp_response.respcode != PtpValues.StandardResponses.OK: raise PtpException(ptp_response.respcode) return rx_data
def GetThumb(self, objectHandle, stream=None): """Get a thumbnail on a PTP device. Returns: A tuple of (object length, and object data (or None if stream was not None)).""" ptp_request = PtpRequest(PtpValues.StandardOperations.GET_THUMB, self.sessionid, self.NewTransaction(), (objectHandle, )) self.transport.send_ptp_request(ptp_request) rx_data = self.transport.get_ptp_data(ptp_request, stream) ptp_response = self.transport.get_ptp_response(ptp_request) if ptp_response.respcode != PtpValues.StandardResponses.OK: raise PtpException(ptp_response.respcode) return rx_data
def SetDevicePropValue(self, propertyId, is_array, fmt, value): """Set the value of a device property. Returns:""" packer = PtpPacker() packer.pack_simpletype(is_array, fmt, value) ptp_request = PtpRequest(PtpValues.StandardOperations.SET_DEVICE_PROP_VALUE, self.sessionid, self.NewTransaction(), (propertyId,)) (ptp_response, rx) = self.transport.ptp_simple_transaction(ptp_request, tx_data = packer.raw) if ptp_response.respcode != PtpValues.StandardResponses.OK: raise PtpException(ptp_response.respcode)
def GetDevicePropValue(self, propertyId, is_array, fmt): """Get the value of a device property. Returns: The value .""" ptp_request = PtpRequest(PtpValues.StandardOperations.GET_DEVICE_PROP_VALUE, self.sessionid, self.NewTransaction(), (propertyId,)) (ptp_response, rx) = self.transport.ptp_simple_transaction(ptp_request, receiving=True) if ptp_response.respcode != PtpValues.StandardResponses.OK: raise PtpException(ptp_response.respcode) unpacker = PtpUnpacker(rx[1]) return unpacker.unpack_simpletype(is_array, fmt)
def GetStorageIDs(self): """Get list of storages a PTP device. Returns: A tuple of IDs.""" ptp_request = PtpRequest(PtpValues.StandardOperations.GET_STORAGE_IDS, self.sessionid, self.NewTransaction()) (ptp_response, rx) = self.transport.ptp_simple_transaction(ptp_request, receiving=True) if ptp_response.respcode != PtpValues.StandardResponses.OK: raise PtpException(ptp_response.respcode) unpacker = PtpUnpacker(rx[1]) return unpacker.unpack_array("I")
def DeleteObject(self, objectHandle, objectFormatId=None): """Delete an object from a PTP device. Returns:""" params = (objectHandle, ) if objectFormatId != None: params += (objectFormatId, ) ptp_request = PtpRequest(PtpValues.StandardOperations.DELETE_OBJECT, self.sessionid, self.NewTransaction(), params) (ptp_response, rx) = self.transport.ptp_simple_transaction(ptp_request, receiving=False) if ptp_response.respcode != PtpValues.StandardResponses.OK: raise PtpException(ptp_response.respcode)
def FormatStore(self, storageId, fsType=None): """Format a store on a PTP device. Returns:""" params = (storageId, ) if fsType != None: params += (fsType, ) ptp_request = PtpRequest(PtpValues.StandardOperations.FORMAT_STORE, self.sessionid, self.NewTransaction(), params) (ptp_response, rx) = self.transport.ptp_simple_transaction(ptp_request, receiving=False) if ptp_response.respcode != PtpValues.StandardResponses.OK: raise PtpException(ptp_response.respcode)
def InitiateCapture(self, storageId=None, objectFormatId=None): """Trigger an image capture. Returns:""" params = () if storageId != None: params += (storageId, ) if objectFormatId != None: if len(params) == 0: params += (0, ) params += (objectFormatId, ) ptp_request = PtpRequest(PtpValues.StandardOperations.INITIATE_CAPTURE, self.sessionid, self.NewTransaction(), params) (ptp_response, rx) = self.transport.ptp_simple_transaction(ptp_request, receiving=False) if ptp_response.respcode != PtpValues.StandardResponses.OK: raise PtpException(ptp_response.respcode)
def GetNumObjects(self, storageId=0xffffffff, objectFormatId=None, associationId=None): """Get the number of objects. Returns: The number of objects.""" params = (storageId, ) if objectFormatId != None: params += (objectFormatId, ) if associationId != None: if objectFormatId == None: params += (0, ) params += (associationId, ) ptp_request = PtpRequest(PtpValues.StandardOperations.GET_NUM_OBJECTS, self.sessionid, self.NewTransaction(), params) (ptp_response, rx) = self.transport.ptp_simple_transaction(ptp_request, receiving=False) if ptp_response.respcode != PtpValues.StandardResponses.OK: raise PtpException(ptp_response.respcode) return ptp_response.params[0]