Module pipettin-piper.piper.datatools.nodb
Functions
def load_datatools(controller: Controller)-
Expand source code
def load_datatools(controller: Controller): if controller.database_tools: raise DataError("Database tools already set in controller to: " + str(controller.database_tools)) # Set the databse_tools property to an instance of JsonObjects. controller.database_tools = NoObjects(controller=controller) return controller.database_tools def load_from_config(**db_config: dict)-
Expand source code
def load_from_config(**db_config : dict): return NoObjects(**db_config)
Classes
class NoObjects (controller=None,
database_url=None,
database_name=None,
data_dict=None,
verbose=True)-
Expand source code
class NoObjects(JsonObjects): """A class holding data about the machine, objects on it, and its configuration. Does not require a backend. Empty by default. It will provide any tools to configure. """ data_dict: dict def __init__(self, controller=None, database_url=None, database_name=None, data_dict=None, verbose=True): # Defaults. self.data_dict = {} self.database_name = "pipettin" self.verbose = False # Update connection details from controller. if controller is not None: self.controller = controller self.verbose = controller.verbose self.data_dict = controller.config["database"].get("data_dict", self.data_dict) self.database_name = controller.config["database"].get("database_name", self.database_name) # Override connection details with arguments. if data_dict is not None: self.data_dict = data_dict if database_name is not None: self.database_name = database_name self.setup_db(self.data_dict, self.database_name) # DATABASE SETUP ############ def setup_db(self, data_dict: dict, database_name: str): """Initialize a database from a Python dictionary object. This method sets up an in-memory database from the provided Python dictionary `data_dict`. The dictionary must contain the required database, ina key matching `database_name`. The database must in turn contain collections such as 'protocols', 'workspaces', 'platforms', 'containers', 'tools', and 'settings'. Args: data_dict (dict): A dictionary containing the databases' data, where each key corresponds to a database, and each key in the database to a collection (e.g., 'protocols', 'workspaces'). Raises: KeyError: Raised if any of the required collections (e.g., protocols, workspaces) are missing from the dictionary. TypeError: Raised if `data_dict` is not a dictionary. """ if not isinstance(data_dict, dict): raise TypeError("setup_db: The provided data must be a dictionary of databases.") # Set the database object from the data_dict self.db = data_dict.get(database_name, {}) if not self.db and data_dict: logging.warning(f"Database '{database_name}' is empty or was not found in the provided data.") logging.info("Database setup complete.") # Main data properties #### @JsonObjects.protocols.setter def protocols(self, value: list): self.db['protocols'] = value @JsonObjects.workspaces.setter def workspaces(self, value: list): self.db['workspaces'] = value @JsonObjects.platforms.setter def platforms(self, value: list): self.db['platforms'] = value @JsonObjects.containers.setter def containers(self, value: list): self.db['containers'] = value @JsonObjects.tools.setter def tools(self, value: list): self.db['tools'] = value @JsonObjects.settings.setter def settings(self, value: list): self.db['settings'] = valueA class holding data about the machine, objects on it, and its configuration. Does not require a backend. Empty by default. It will provide any tools to configure.
Ancestors
Class variables
var data_dict : dict
Methods
def setup_db(self, data_dict: dict, database_name: str)-
Expand source code
def setup_db(self, data_dict: dict, database_name: str): """Initialize a database from a Python dictionary object. This method sets up an in-memory database from the provided Python dictionary `data_dict`. The dictionary must contain the required database, ina key matching `database_name`. The database must in turn contain collections such as 'protocols', 'workspaces', 'platforms', 'containers', 'tools', and 'settings'. Args: data_dict (dict): A dictionary containing the databases' data, where each key corresponds to a database, and each key in the database to a collection (e.g., 'protocols', 'workspaces'). Raises: KeyError: Raised if any of the required collections (e.g., protocols, workspaces) are missing from the dictionary. TypeError: Raised if `data_dict` is not a dictionary. """ if not isinstance(data_dict, dict): raise TypeError("setup_db: The provided data must be a dictionary of databases.") # Set the database object from the data_dict self.db = data_dict.get(database_name, {}) if not self.db and data_dict: logging.warning(f"Database '{database_name}' is empty or was not found in the provided data.") logging.info("Database setup complete.")Initialize a database from a Python dictionary object.
This method sets up an in-memory database from the provided Python dictionary
data_dict. The dictionary must contain the required database, ina key matchingdatabase_name. The database must in turn contain collections such as 'protocols', 'workspaces', 'platforms', 'containers', 'tools', and 'settings'.Args
data_dict:dict- A dictionary containing the databases' data, where each key corresponds to a database, and each key in the database to a collection (e.g., 'protocols', 'workspaces').
Raises
KeyError- Raised if any of the required collections (e.g., protocols, workspaces) are missing from the dictionary.
TypeError- Raised if
data_dictis not a dictionary.
Inherited members
JsonObjects:containersenv_filefilterContentByfilterContentByTypefindfind_matchfind_matchesfind_onegetActionDataBygetContainerByNamegetContentByNamegetNextContentgetNextContentByNamegetPlatformByNamegetProtocolByNamegetProtocolObjectsgetToolByNamegetWorkspaceByNamegetWorkspaceItemByNameget_dbhl_protocolsis_subsetlistContainerslistHlProtocolslistPlatformslistProtocolslistSettingslistToolslistWorkspacesplatformspop_content_by_idxprotocolssettingstoolsupdateActionByupdate_from_env_fileupdate_nestedworkspaces