mafw.examples.db_processors

The module provides some basic processors with DB interaction for demonstrating the basic functionalities.

Classes

CountStandardTables(*args, **kwargs)

A processor to count the number of standard tables

File(*args, **kwargs)

The Model class representing the table in the database

FillFileTableProcessor(*args, **kwargs)

Processor to fill a table with the content of a directory

Exceptions

FileDoesNotExist

Exception raised if the table corresponding to the File model does not exist.

exception mafw.examples.db_processors.FileDoesNotExist[source]

Bases: Exception

Exception raised if the table corresponding to the File model does not exist.

class mafw.examples.db_processors.CountStandardTables(*args: Any, **kwargs: Any)[source]

Bases: Processor

A processor to count the number of standard tables

Processor parameters

  • n_tables: The number of standard tables (default: -1)

Constructor parameters

Parameters:
  • name (str, Optional) – The name of the processor. If None is provided, the class name is used instead. Defaults to None.

  • description (str, Optional) – A short description of the processor task. Defaults to the processor name.

  • config (dict, Optional) – A configuration dictionary for this processor. Defaults to None.

  • looper (LoopType, Optional) – Enumerator to define the looping type. Defaults to LoopType.ForLoop

  • user_interface (UserInterfaceBase, Optional) – A user interface instance to be used by the processor to interact with the user.

  • timer (Timer, Optional) – A timer object to measure process duration.

  • timer_params (dict, Optional) – Parameters for the timer object.

  • database (Database, Optional) – A database instance. Defaults to None.

  • database_conf (dict, Optional) – Configuration for the database. Default to None.

  • remove_orphan_files (bool, Optional) – Boolean flag to remove files on disc without a reference to the database. See Standard tables and _remove_orphan_files(). Defaults to True

  • replica_id (str, Optional) – The replica identifier for the current processor.

  • create_standard_tables (bool, Optional) – Boolean flag to create std tables on disk. Defaults to True

  • kwargs – Keyword arguments that can be used to set processor parameters.

process()[source]

Processes the current item.

This is the core of the Processor, where the user has to define the calculations required.

start() None

Start method.

The user can overload this method, including all steps that should be performed at the beginning of the operation.

If the user decides to overload it, it should include a call to the super method.

class mafw.examples.db_processors.File(*args, **kwargs)[source]

Bases: MAFwBaseModel

The Model class representing the table in the database

DoesNotExist

alias of FileDoesNotExist

class mafw.examples.db_processors.FillFileTableProcessor(*args: Any, **kwargs: Any)[source]

Bases: Processor

Processor to fill a table with the content of a directory

Processor parameters

  • root_folder: The root folder for the file listing (default: PosixPath(‘/builds/kada/mafw’))

Constructor parameter:

Parameters:

root_folder (Path, Optional) – ActiveParameter corresponding to the directory from where to start the recursive search

finish()[source]

Transfers all the data to the File table via an atomic transaction.

format_progress_message()[source]

Customizes the progress message with information about the current item.

The user can overload this method in order to modify the message being displayed during the process loop with information about the current item.

The user can access the current value, its position in the looping cycle and the total number of items using Processor.item, Processor.i_item and Processor.n_item.

get_items() list[Path][source]

Retrieves the list of files.

Insert or update the files from the root folder to the database

Returns:

The list of full filename

Return type:

list[Path]

process()[source]

Add all information to the data list

start()[source]

Starts the execution.

Be sure that the table corresponding to the File model exists. It it does already exists, it is not a problem.