How to use the pymtp.models.IterableModel function in PyMTP

To help you get started, we’ve selected a few PyMTP examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github emdete / python-mtp / pymtp / models.py View on Github external
def _get_filetype(self):
		"""
			The filetype of the file
			@return: Filetype as an integer
			@rtype: int
		"""
		# TODO: Maybe this should return a MTPFileType object (when they exist)
		return int(self.base_structure.filetype)

	def _set_filetype(self, value):
		# TODO: This should accept an integer AND a MTPFileType!
		self.base_structure.filetype = ctypes.c_int(int(value))

	filetype = property(_get_filetype, _set_filetype)

class MTPFiles(IterableModel):
	"""
		MTPFiles

		An object representing a list of L{MTPFile} objects
	"""
	def __getitem__(self, key):
		"""
			Returns the L{MTPFile} object at the index specified
			@param key: The index of the object to retrieve
			@type key: int
			@return: The object requested
			@rtype: L{MTPFile}
		"""
		return MTPFile(self._get_item(key))

# ----------
github emdete / python-mtp / pymtp / models.py View on Github external
			@rtype: int
		"""
		return int(self.base_structure.default_album_folder)

	@property
	def default_text_folder(self):
		"""
			The ID of the default text folder

			@return: The default text folder ID
			@rtype: int
		"""
		return int(self.base_structure.default_text_folder)


class MTPDevices(IterableModel):
	"""
		MTPDevices

		An object of a list of MTP devices
	"""
	def __getitem__(self, key):
		"""
			Returns a MTPDevice from the list of devices

			@return: The MTP device with the index specified
			@rtype: L{MTPDevice}
		"""
		return MTPDevice(self._get_item(key))

# --------
# Beginning LibMTP_File, MTPFile and MTPFiles
github emdete / python-mtp / pymtp / models.py View on Github external
filesize = property(_get_filesize, _set_filesize)

	def _get_filetype(self):
		"""
			The filetype as an integer
			@rtype: int
			@return: File type
		"""
		return int(self.base_structure.filetype)

	def _set_filetype(self, value):
		self.base_structure.filetype = ctypes.c_int(int(value))

	filetype = property(_get_filetype, _set_filetype)

class MTPTracks(IterableModel):
	"""
		MTPTracks

		An object representing a list of L{MTPTrack} objects.
	"""
	def __getitem__(self, key):
		"""
			Returns the L{MTPTrack} at the index specified
			@type key: int
			@param key: The index to retrieve
			@rtype: L{MTPTrack}
			@return: The track specified
		"""
		return MTPTrack(self._get_item(key))

# --------
github emdete / python-mtp / pymtp / models.py View on Github external
			@rtype: int
		"""
		# A quick sanity check to return 0 when base_structure
		# is null
		if not self.base_structure:
			return 0
		level = 0
		current = self.base_structure
		while True:
			if current.next:
				level += 1
				current = current.next.contents
			else:
				return level

class MutableIterableModel(IterableModel):
	"""
		MutableIterableModel

		Extends the L{IterableModel} model for mutable objects.

		As with L{IterableModel}, you still have to provide the data type
		functions (i.e., __getitem__, __setitem__, __delitem__, etc), but you
		can use the functions in this model to perform the underlying
		operations.
	"""
	pass

class FixedArray(object):
	"""
		FixedArray
github emdete / python-mtp / pymtp / models.py View on Github external
			@return: LibMTP error number
			@rtype: int
		"""
		return int(self.base_structure.errornumber)

	@property
	def error_text(self):
		"""
			Returns the error text

			@return: LibMTP error text
			@rtype: str
		"""
		return str(self.base_structure.error_text)

class MTPErrors(IterableModel):
	"""
		MTPErrors

		An object representing a list of MTPError objects.
	"""

	def __getitem__(self, key):
		"""
			Returns the key from the list of errors

			@type key: int
			@param key: The index of the object to retrieve
			@return: A MTPError object
			@rtype: L{MTPError}
		"""
		return MTPError(self._get_item(key))
github emdete / python-mtp / pymtp / models.py View on Github external
return str(self.base_structure.name)

	def _set_name(self, value):
		self.base_structure.name = ctypes.c_char_p(str(value))

	@property
	def tracks(self):
		"""
			List of tracks in the playlist
			@rtype: L{FixedArray}
			@return: A L{FixedArray} containing the tracks
		"""
		return FixedArray(self.base_structure.tracks,
			self.base_structure.no_tracks)

class MTPPlaylists(IterableModel):
	"""
		An object representing a group of MTPPlaylists
	"""
	def __getitem__(self, key):
		"""
			Returns a L{MTPPlaylist} for the object specified
			@type key: int
			@param key: Index of the object to retrieve
			@rtype: L{MTPPlaylist}
			@return: The L{MTPPlaylist} at the index specified
		"""
		return MTPPlaylist(self._get_item(key))

# -------
# Beginning LIBMTP_Folder, MTPFolder, and MTPFolders
# -------
github emdete / python-mtp / pymtp / models.py View on Github external
return str(self.base_structure.genre)

	def _set_genre(self, value):
		self.base_structure.genre = ctypes.c_char_p(str(value))

	genre = property(_get_genre, _set_genre)

	@property
	def tracks(self):
		"""
			A list of tracks in the album
		"""
		return FixedArray(self.base_structure.tracks,
			self.base_structure.no_tracks)

class MTPAlbums(IterableModel):
	"""
		MTPAlbums

		An object representing a list of L{MTPAlbum} objects.
	"""
	def __getitem__(self, key):
		"""
			Returns the L{MTPAlbum} object at the index specified

			@type key: int
			@param key: Index of object to return
			@rtype: L{MTPAlbum}
			@return: The L{MTPAlbum} object at the key/index specified
		"""
		return MTPAlbum(self._get_item(key))
github emdete / python-mtp / pymtp / models.py View on Github external
	@property
	def storage_description(self):
		"""
			A description of the storage
		"""
		return str(self.base_structure.storage_description)

	@property
	def volume_id(self):
		"""
			The volume ID of the storage.
		"""
		return str(self.base_structure.volume_id)

class MTPDeviceStorages(IterableModel):
	"""
		MTPDeviceStorages

		An object representing a group of L{MTPDeviceStorage} objects.
	"""
	def __init__(self, base_structure):
		IterableModel.__init__(self, base_structure)
		# Make sure that our base_structure refers to the "lowest" object
		# in the tree
		while True:
			if self.base_structure.prev:
				self.base_structure = self.base_structure.prev.contents
			else:
				break

	def __getitem__(self, key):