Beacon Item
Items are returned by beacon queries and represent one result
entry. You should not create an Item yourself. Beacon provides two
query functions. The first one is kaa.beacon.query which returns a
Query object and the second one is kaa.beacon.get to get the item
for a specific filename.
There are currently two kinds of Items. The generic Item class and a
File class inheriting from Item.
-
beacon.get(filename)
- Get object for the given filename. This function will raise an
exception if the client is not connected and the server is not
running for a connect. The function returns an InProgress object
with a File object as result.
Methods
An Item uses a dict-like interface to get and set values. If the key
starts with tmp: the value is stored temporary in the Item and is
not stored in the database. A second Item for the same database entry
does not have this attribute and it is lost when the Item is
destroyed. See Database Attributes for a list of attributes in the
database.
-
Item.get(key, default=None)
- Access attributes of the item. If the attribute is not found
the default value (None) will be returned.
-
Item.__getitem__(key)
- Access attributes of the item. This function will never raise
an exception. If the attribute is not found, None will be
returned.
-
Item.has_key(key)
- Check if the item has a specific attribute set
-
Item.keys()
- List item attributes
-
Item.__setitem__(key, value)
- Set the value of a given attribute. If the key starts with
‘tmp:’, the data will only be valid in this item and not
stored in the db.
An Item also provides an interface to access children like files in a
directory, delete an Item from the database and initiate an Item to be
scanned.
-
Item.list()
- Return a Query object with all subitems of this item. If the
client is not connected to the server an empty list will be
returned instead.
-
File.list(recursive=False)
- Return a Query object for a query with all files in the
directory. If the Item is no directory all subitems will
returned similar to the Item list function. This can happen
for DVD iso files on hard-disc. If the client is not connected
to the server an empty list will be returned instead.
-
Item.delete()
- Delete item from the database (does not work on files)
-
Item.scan()
- Request the item to be scanned.
Attributes
Besides the attributes in the database an Item also has some Python
attributes. These attributes are always set no matter of the file
behind it is already scanned or not.
-
beacon.Item.url
- URL for the Item. This includes a prefix like file://, dvd:// or
http://
-
beacon.Item.filename
- Full path of the file if the Item represents a file or
directory. For Item that are no File this attribute is an empty
string.
-
Item.isdir
- True if the item is a directory.
-
Item.isfile
- True if the item is a regular file.
-
Item.thumbnail
- Return a Thumbnail for the Item. See Thumbnails for
details about thumbnailing works in beacon.
-
Item.scanned
- True if the item is in the database and fully scanned.
-
Item.ancestors
- Return an iterator to walk through the parents.