Saved Property

A library provides a simple data based implementation for efficient archiving the last known values of a script. This is particularly important for python codes that are used run instruments and require certain information to be saved and available for the next run.

Start by importing UBCS LCP auxiliary package library.

first you can install the auxiliary library

pip3 install ubcs_auxiliary

you may need to upgrade the library if it was installed before

pip3 install --upgrade ubcs_auxiliary
>>> from ubcs_auxiliary.saved_property import DataBase, SavedProperty
>>> from  numpy import array
>>> class SomeClass():
        db = DataBase(root = tmpdir, name = 'simpledb')
        int_var = SavedProperty(db,'int_var',1).init()
        float_var = SavedProperty(db,'float_var',0.0).init()
        list_var = SavedProperty(db,'list_var',[0.0,5,6,7]).init()
        array_var = SavedProperty(db,'array_var',array([0.0,5,6,7])).init()
>>> object = SomeClass()
>>> object.int_var
  1
>>> object.int_var = 3
>>> object.float_var
  0.0
>>> object.float_var = 5.7
>>> del object
>>> object2 = SomeClass()
>>> print( object2.int_var, object2.float_var)
  (3,5.7)
class ubcs_auxiliary.saved_property.DataBase(root, name)[source]
__init__(root, name)[source]

initializes the connection to the database.

Parameters
root :: (string)

path or environment variable

name :: (string)

name of the database

Examples

>>> write()
get_filename(root, name)[source]

generates filename based on input root and name. There are few special keywords like TEMP, LOCAL that will obtain the locations of temporary and local directories. The function also ensures that the path is correct in different platforms.

Parameters
root :: (string)

path or environment variable

name :: (string)

name of the database

Returns
tuple :: (filename, root, name)

returns a tuple with 3 entries filename, root, name: (0) full filename (1) full path from the home directory; (2) the name of the file.

Examples

>>> filename, root, name = get_filename(root, 'name.db')
read()[source]

reads the database file

Returns
dictionary :: (dictionary)

returns a dictionary of all data in the database file.

Examples

>>> data = read()
sync()[source]

reads the database file and updates the self.database variable accordingly.

Examples

>>> sync()
write()[source]

writes current dictionary saved in memory to the database file

Examples

>>> write()
class ubcs_auxiliary.saved_property.SavedProperty(db, name, value)[source]
__init__(db, name, value)[source]
get(name)[source]

getter for SavedProperty. returns saved value if it exists in the database, otherwise returns default_value

Returns
value :: (object)

returns a value stored with the selected key in the database

Examples

>>>
init()[source]

wrapper that returns property object with get and set functions.

Examples

>>> from saved_property import DataBase, SavedProperty
>>> db = DataBase(root = '', name = 'simpledb')
>>> d = SavedProperty(db,'d',5.0).init()
set(name, value)[source]

setter for SavedProperty. sets value in the database

Parameters
value :: (object)

value saved to the database.

Examples

>>>