Terarea  2
The automation project
Loading...
Searching...
No Matches
src.lib.actions.variables.Variables Class Reference
Collaboration diagram for src.lib.actions.variables.Variables:
Collaboration graph

Public Member Functions

 __init__ (self, int success=0, int error=84, bool debug=False)
 
None __del__ (self)
 
int create_scope (self, Any scope_name)
 
int add_variable (self, str name, Any variable_data, Type variable_type=str, Any scope="default_scope")
 
int update_variable (self, str name, Any variable_data, Type variable_type=str, Any scope="default_scope")
 
int insert_or_update (self, str name, Any variable_data, Type variable_type=str, Any scope="default_scope")
 
bool has_variable (self, str name, Any scope="default_scope")
 
Any get_variable (self, str name, Any scope="default_scope")
 
Dict[str, Any] get_variables (self, Any scope="default_scope")
 
Dict[str, Any] get_scope (self, Any scope="default_scope")
 
Union[int, Type] get_variable_type (self, str name, Any scope="default_scope")
 
int remove_variable (self, str name, Any scope="default_scope")
 
int clear_variables (self, Any scope="default_scope")
 
int clear_scopes (self)
 
int clear_scope_contents (self)
 
int remove_scope (self, Any scope)
 
Any sanitize_for_json (self, Any data_or_scope, bool use_scope=False)
 

Data Fields

int success = success
 
int error = error
 
bool debug = debug
 
dict variables = {}
 
Disp disp
 
str variables = f"Scope {scope} not found."
 

Detailed Description

_summary_

Definition at line 24 of file variables.py.

Constructor & Destructor Documentation

◆ __init__()

src.lib.actions.variables.Variables.__init__ ( self,
int success = 0,
int error = 84,
bool debug = False )
_summary_
    Class in charge of storing and restoring variables.

Args:
    success (int, optional): _description_. Defaults to 0.
    error (int, optional): _description_. Defaults to 84.
    debug (bool, optional): _description_. Defaults to False.

Definition at line 28 of file variables.py.

◆ __del__()

None src.lib.actions.variables.Variables.__del__ ( self)
_summary_
    Destructor for the class.

Definition at line 53 of file variables.py.

Member Function Documentation

◆ add_variable()

int src.lib.actions.variables.Variables.add_variable ( self,
str name,
Any variable_data,
Type variable_type = str,
Any scope = "default_scope" )
_summary_
    Add a variable to the current action.

Args:
    name (str): _description_: The name of the variable
    variable_data (Any): _description_: The data of the given variable
    variable_type (Type): _description_: The type of the data
    scope (str, optional): _description_: The scope of the variable, defaults to "default_scope"

Raises:
    TypeError: _description_: If the type of the variable is incorrect.

Returns:
    int: _description_: Returns self.success if it succeeds, self.error otherwise.

Definition at line 82 of file variables.py.

◆ clear_scope_contents()

int src.lib.actions.variables.Variables.clear_scope_contents ( self)
_summary_
    Clear all the scopes content from the current action.

Returns:
    int: _description_

Definition at line 401 of file variables.py.

◆ clear_scopes()

int src.lib.actions.variables.Variables.clear_scopes ( self)
_summary_
    Clear all the scopes from the current action.

Returns:
    int: _description_

Definition at line 388 of file variables.py.

◆ clear_variables()

int src.lib.actions.variables.Variables.clear_variables ( self,
Any scope = "default_scope" )
_summary_
    Clear all the variables from the current action.

Args:
    scope (str, optional): _description_: The scope in which to clear the variables. Enter '*' to clear the content of all the scopes. Defaults to "default_scope".

Returns:
    int: _description_: Returns self.success if it succeeds, self.error otherwise.

Definition at line 358 of file variables.py.

◆ create_scope()

int src.lib.actions.variables.Variables.create_scope ( self,
Any scope_name )
_summary_
    Create a new scope.

Args:
    scope_name (Any): _description_: The name of the scope.

Returns:
    int: _description_: Returns self.success if it succeeds, self.error otherwise.

Definition at line 62 of file variables.py.

◆ get_scope()

Dict[str, Any] src.lib.actions.variables.Variables.get_scope ( self,
Any scope = "default_scope" )
_summary_
    The function in charge of returning the content of a scope.
    This function is just there for program logic.
    This is function behaves the exact same way as the get_variables function.

Args:
    scope (str, optional): _description_: The scope in which to get the variables. User '*' to return all the vairables from all the scopes. Defaults to "default_scope".

Raises:
    ScopeError: _description_: If the scope is not found.

Returns:
    Dict[str, Any]: _description_: Returns all the variables.

Definition at line 280 of file variables.py.

◆ get_variable()

Any src.lib.actions.variables.Variables.get_variable ( self,
str name,
Any scope = "default_scope" )
_summary_
    Get the variable from the current action.

Args:
    name (str): _description_: The name of the variable
    scope (str, optional): _description_: The scope in which to get the variable. Defaults to "default_scope".

Raises:
    ScopeError: _description_: If the scope is not found.
    ValueError: _description_: If the variable does not exist.

Returns:
    Any: _description_: Returns the variable if it exists, self.error otherwise.

Definition at line 230 of file variables.py.

◆ get_variable_type()

Union[int, Type] src.lib.actions.variables.Variables.get_variable_type ( self,
str name,
Any scope = "default_scope" )
_summary_
    Get the type of the variable from the current action.

Args:
    name (str): _description_: The name of the variable
    scope (str, optional): _description_: The scope in which to get the variable. Defaults to "default_scope".

Raises:
    ScopeError: _description_: If the scope is not
    ValueError: _description_: If the variable does not exist.

Returns:
    Type: _description_: Returns the type of the variable if it exists, self.error otherwise.

Definition at line 297 of file variables.py.

◆ get_variables()

Dict[str, Any] src.lib.actions.variables.Variables.get_variables ( self,
Any scope = "default_scope" )
_summary_
    Get all the variables from the current action.

Args:
    scope (str, optional): _description_: The scope in which to get the variables. User '*' to return all the vairables from all the scopes. Defaults to "default_scope".

Raises:
    ScopeError: _description_: If the scope is not found.

Returns:
    Dict[str, Any]: _description_: Returns all the variables.

Definition at line 257 of file variables.py.

◆ has_variable()

bool src.lib.actions.variables.Variables.has_variable ( self,
str name,
Any scope = "default_scope" )
_summary_
    Check if the variable exists in the current action.

Args:
    name (str): _description_: The name of the variable
    scope (str, optional): _description_: The scope in which we wish to search for the variable. Enter '*' to search all the variable scopes. Defaults to "default_scope"

Raises:
    ScopeError: _description_: If the scope is not found.

Returns:
    bool: _description_: Returns True if the variable exists, False otherwise.

Definition at line 193 of file variables.py.

◆ insert_or_update()

int src.lib.actions.variables.Variables.insert_or_update ( self,
str name,
Any variable_data,
Type variable_type = str,
Any scope = "default_scope" )
_summary_
    Insert or update the variable from the current action.

Args:
    name (str): _description_: The name of the variable
    variable_data (Any): _description_: The data of the given variable
    variable_type (Type): _description_: The type of the data
    scope (str, optional): _description_: The scope in which the data is stored. Defaults to "default_scope"

Raises:
    ValueError: _description_: If the variable does not exist.
    TypeError: _description_: If the type of the variable is incorrect
    ScopeError: _description_: If the scope is not found.
    VariableNotFoundError: _description_: If the variable is not found.

Returns:
    int: _description_: Returns self.success if it succeeds, self.error otherwise.

Definition at line 158 of file variables.py.

◆ remove_scope()

int src.lib.actions.variables.Variables.remove_scope ( self,
Any scope )
_summary_
    Remove the scope from the current action.

Args:
    scope (str): _description_: The scope to remove.

Raises:
    ScopeError: _description_: If the scope is not found.

Returns:
    int: _description_: Returns self.success if it succeeds, self.error otherwise.

Definition at line 416 of file variables.py.

◆ remove_variable()

int src.lib.actions.variables.Variables.remove_variable ( self,
str name,
Any scope = "default_scope" )
_summary_
    Remove the variable from the current action.

Args:
    name (str): _description_: The name of the variable
    scope (str, optional): _description_:  The scope in which the variable is stored. Defaults to "default_scope".

Raises:
    ScopeError: _description_: If the scope is not found.
    VariableNotFoundError: _description_: If the variable is not found.

Returns:
    int: _description_: Returns self.success if it succeeds, self.error otherwise.

Definition at line 324 of file variables.py.

◆ sanitize_for_json()

Any src.lib.actions.variables.Variables.sanitize_for_json ( self,
Any data_or_scope,
bool use_scope = False )
_summary_
    Sanitize the data for json serialization.

Args:
    data (Any): _description_: The data to sanitize.
    use_scope (bool, optional): _description_: Specify if the data to process is to be queried in the variable scopes. Default: False

Raises:
    ScopeError: _description_: If the scope is not found.

Returns:
    Any: _description_: The sanitized data.

Definition at line 439 of file variables.py.

◆ update_variable()

int src.lib.actions.variables.Variables.update_variable ( self,
str name,
Any variable_data,
Type variable_type = str,
Any scope = "default_scope" )
_summary_
    Update the variable from the current action.

Args:
    name (str): _description_: The name of the variable
    variable_data (Any): _description_: The data of the given variable
    variable_type (Type): _description_: The type of the data
    scope (str, optional): _description_: The scope in which the data is stored. Defaults to "default_scope"

Raises:
    ScopeError: _description_: If the scope is not found.
    VariableNotFoundError: _description_: If the variable is not found.
    TypeError: _description_: If the type of the variable is incorrect

Returns:
    int: _description_: Returns self.success if it succeeds, self.error otherwise.

Definition at line 120 of file variables.py.

Field Documentation

◆ debug

bool src.lib.actions.variables.Variables.debug = debug

Definition at line 40 of file variables.py.

◆ disp

Disp src.lib.actions.variables.Variables.disp
Initial value:
= Disp(
TOML_CONF,
SAVE_TO_FILE,
FILE_NAME,
FILE_DESCRIPTOR,
debug=self.debug,
logger=self.__class__.__name__
)

Definition at line 44 of file variables.py.

◆ error

int src.lib.actions.variables.Variables.error = error

Definition at line 39 of file variables.py.

◆ success

int src.lib.actions.variables.Variables.success = success

Definition at line 38 of file variables.py.

◆ variables [1/2]

str src.lib.actions.variables.Variables.variables = {}

Definition at line 42 of file variables.py.

◆ variables [2/2]

str src.lib.actions.variables.Variables.variables = f"Scope {scope} not found."

Definition at line 139 of file variables.py.


The documentation for this class was generated from the following file: