storage :: Device :: Device :: Class Device
[hide private]
[frames] | no frames]

Class Device

com.Component --+
                |
               Device

Base class of all storage devices. Storage devices provide virtual file systems for use by MediaBox. New virtual file systems can be added by subclassing the Device base class.

Storage devices belong to one of the categories CATEGORY_CORE, CATEGORY_LOCAL, CATEGORY_LAN, CATEGORY_WAN, or CATEGORY_OTHER. The category determines the position where the device will appear in the user interface. The list of devices is sorted first by category, then alphabetically.

Storage devices are of type TYPE_GENERIC, TYPE_AUDIO, TYPE_VIDEO, or TYPE_IMAGE. Viewers list devices of certain types. The video viewer e.g. only lists devices of type TYPE_VIDEO, while the devices of type TYPE_GENERIC are listed by the folder viewer.

Instance Methods [hide private]
 
__init__(self)
 
get_device_id(self)
Returns the unique device identifier.
 
get_prefix(self)
Returns the device prefix for addressing this storage device.
 
get_name(self)
Returns the human readable name of this storage device.
 
get_icon(self)
Returns the icon for representing this storage device in a user interface.
 
get_root(self)
Returns the File object representing the root path of the device.
 
get_file(self, path)
Returns the File object representing the given path.
 
new_file(self, path)
Can be implemented by devices to support creating new files.
 
delete(self, f)
Can be implemented by devices to support deleting files.
 
keep(self, f)
Keeps the given file.
 
ls(self, path)
Returns a list of File objects representing the contents of the given path.
 
ls_async(self, path, cb, *args)
Lists the given path asynchronously by calling the given callback on each item.
 
load(self, f, maxlen, cb, *args)
Retrieves the given amount of bytes of the file asynchronously.
 
get_resource(self, f)
Returns the resource URI to access the given resource.
Class Variables [hide private]
  CATEGORY_CORE = 0
  CATEGORY_LOCAL = 1
  CATEGORY_LAN = 2
  CATEGORY_WAN = 3
  CATEGORY_OTHER = 4
  TYPE_GENERIC = 0
  TYPE_AUDIO = 1
  TYPE_VIDEO = 2
  TYPE_IMAGE = 3
  CATEGORY = 4
category of this device
  TYPE = 0
type of this device
Method Details [hide private]

get_device_id(self)

 

Returns the unique device identifier.

Returns:
device identifier

get_prefix(self)

 

Returns the device prefix for addressing this storage device. This is a unique string forming the first part of URIs and is used for identifying the appropriate storage device implementation for a particular path.

E.g. in case of UPnP AV content directories, this would be the protocol together with the UDN:

 upnp://uuid:898f9738-d930-4db4-a3cf-0015af8f11f6

Every prefix MUST contain '://' to separate the protocol name from the device identifier. The protocol name must not be empty. The device identifier may be empty where appropriate.

Returns:
prefix

get_name(self)

 

Returns the human readable name of this storage device.

Returns:
name

get_icon(self)

 

Returns the icon for representing this storage device in a user interface. Returns None if no icon is available.

Returns:
icon pixbuf

get_root(self)

 

Returns the File object representing the root path of the device. The returned path does not contain the device prefix.

Returns:
root file object

get_file(self, path)

 

Returns the File object representing the given path. The specified path does not contain the device prefix.

Parameters:
  • path - path string
Returns:
file object

new_file(self, path)

 

Can be implemented by devices to support creating new files.

Parameters:
  • path - file object of the parent folder

delete(self, f)

 

Can be implemented by devices to support deleting files.

Parameters:
  • f - file object to delete

keep(self, f)

 

Keeps the given file. Storage device can implement this method to let the user keep remote stuff locally.

Parameters:
  • f - file object to keep

ls(self, path)

 

Returns a list of File objects representing the contents of the given path.

Parameters:
  • path - file object to list
Returns:
list of file objects

Deprecated: ls_async should be used instead

ls_async(self, path, cb, *args)

 

Lists the given path asynchronously by calling the given callback on each item. After processing every item, the implementation is expected to return None to signalize the end.

Parameters:
  • path - file object to list
  • cb - callback handler
  • args - variable list of arguments to the callback handler

load(self, f, maxlen, cb, *args)

 

Retrieves the given amount of bytes of the file asynchronously.

May raise an IOError if retrieving is not supported.

Parameters:
  • maxlen - number of bytes to retrieve or -1 for retrieving the whole file
  • cb - callback handler for accepting the data chunks
  • args - variable list of arguments to the callback handler

get_resource(self, f)

 

Returns the resource URI to access the given resource. Usually this method just returns the given resource. But sometimes (e.g. YouTube), this URI has to be specially determined.