alab_management.device_view.dbattributes module#

class DictInDatabase(device_collection, device_name, attribute_name, default_value=None)[source]#

Bases: object

Class that emulates a dict, but stores the dict in the device database. Useful for working with Device attributes that are dict, so values persist across alabos sessions. This should be instantiated using alab_management.device_view.device.BaseDevice.dict_in_database.

apply_default_value()[source]#

This is called within alab_management.scripts.setup_lab() to ensure that all devices have the correct default values for their attributes. This should not be called manually.

Raises —— ValueError: Device is not found in the database. This should only occur if this function is called out of order (i.e. before the device is created in the db).

as_normal_dict()[source]#

Return a normal dict representation of the DictInDatabase. This will not update the database.

Return type:

dict

clear()[source]#

Clear the dict. This will update the database with the new value.

copy()[source]#

Return a copy of the dict. This will not update the database.

property db_filter#

The filter used to retrieve the attribute from the database. This is used internally by the class.

property db_projection#

The projection used to retrieve the attribute from the database. This is used internally by the class.

fromkeys()[source]#

Return a copy of the dict. This will not update the database.

get(key, default=None)[source]#

Return a copy of the dict. This will not update the database.

items()[source]#

Return a copy of the dict. This will not update the database.

keys()[source]#

Return a copy of the dict. This will not update the database.

pop(key, default='be8b61ee-48b1-4624-bf7a-2ca31f7c5ef4')[source]#

Return a copy of the dict. This will not update the database.

popitem()[source]#

Return a copy of the dict. This will not update the database.

setdefault(key, default=None)[source]#

Return a copy of the dict. This will not update the database.

update(*args, **kwargs)[source]#

Return a copy of the dict. This will not update the database.

values()[source]#

Return a copy of the dict. This will not update the database.

class ListInDatabase(device_collection, device_name, attribute_name, default_value=None)[source]#

Bases: object

Class that emulates a list, but stores the list in the device database. Useful for working with Device attributes that are lists, so values persist across alabos sessions. This should be instantiated using alab_management.device_view.device.BaseDevice.list_in_database.

append(x)[source]#

Append an element to the list. This will update the database with the new value.

apply_default_value()[source]#

This is called within alab_management.scripts.setup_lab() to ensure that all devices have the correct default values for their attributes. This should not be called manually.

Raises —— ValueError: Device is not found in the database. This should only occur if this function is called out of order (i.e. before the device is created in the db).

clear()[source]#

Clear the list. This will update the database with the new value.

copy()[source]#

Return a copy of the list. This will not update the database.

count()[source]#

Return the number of occurrences of x in the list. This will not update the database.

property db_filter#

The filter used to retrieve the attribute from the database. This is used internally by the class.

property db_projection#

The projection used to retrieve the attribute from the database. This is used internally by the class.

extend(x)[source]#

Extend the list with another iterable. This will update the database with the new value.

index(x, start=None, stop=None)[source]#

Return the index of the first occurrence of x in the list. This will not update the database.

insert(i, x)[source]#

Insert an element at a given position. This will update the database with the new value.

pop(i=-1)[source]#

Remove the element at a given position. This will update the database with the new value.

remove(x)[source]#

Remove the first item from the list whose value is equal to x. This will update the database with the new.

reverse()[source]#

Reverse the elements of the list in place. This will update the database with the new value.

sort(key=None, reverse=False)[source]#

Sort the items of the list in place. This will update the database with the new value.

value_in_database(name, default_value)[source]#

Property factory to mirror a Device attribute in the ALab database. This must be declared as a Class Variable under a Device subclass of BaseDevice!.

Args: name (str): attribute name default_value (Any): default value for the attribute. Note that this value is not used until the first time a property is queried; at this time, if the attribute is not found in the database, it is set to this value.

Return type:

property

Returns:

property: class property that handles getting/setting values from the database.

Example usage when defining a new Device:

from alab_management.device_view import BaseDevice, value_in_database

class MyDevice(BaseDevice):
    my_attribute = value_in_database("my_attribute", 0)

    def __init__(self, name: str, **kwargs):
        super().__init__(name, **kwargs)
        self.name = name
        self.my_attribute #initial call to the property, which sets the default value in the database

....
#first instantiation

mydevice = MyDevice(name = "mydevice_1")
mydevice.my_attribute = 5 #sets the value in the database

....
#future instantiation
mydevice = MyDevice(name = "mydevice_1")
mydevice.my_attribute #retrieves value from db and returns 5