utils module

utils.change_file_path(input_file, new_directory, new_base_name)[source]

Change the input file path, keeping the original file extension unchanged and move the file.

Parameters: input_file (str): The original file path with the extension. new_directory (str): The new directory where the file should be moved. new_base_name (str): The new base name for the file (without extension).

Returns: str: The new file path with the original extension.

utils.get_channel(queue_name)[source]
utils.get_logger(__name__, __file__)[source]

Creates and configures a logger with colored output for different log levels.

This function sets up a logger that outputs log messages to the console with color-coded log levels to make it easier to distinguish between different severities. The logger’s configuration includes: - Log levels with distinct colors (DEBUG, INFO, WARNING, ERROR, CRITICAL). - Relative file path display from the directory where the script is executed. - Automatic color reset after each log message.

The function initializes the logger based on the module’s __name__ and __file__ parameters, sets the logging level from a global LOG.LEVEL variable, and uses colorama for colored console output.

Parameters:
  • __name__ (str) – The name of the current module, typically passed as __name__.

  • __file__ (str) – The path of the current file, typically passed as __file__.

Returns:

A configured logger instance with color-coded log level output.

Return type:

logging.Logger

Example

logger = get_logger(__name__, __file__) logger.info(“This is an info message”) logger.error(“This is an error message”)

Notes

The logger uses a StreamHandler to output to the console and a custom ColorFormatter to add colors to the log level based on the severity. It will only add a handler if no handlers are already configured to prevent duplicate log entries.

utils.now(tz=None)

Returns new datetime object representing current time local to tz.

tz

Timezone object.

If no tz is specified, uses local timezone.