Skip to content

clabe.data_transfer

DataTransfer

Bases: Service, ABC, Generic[TSettings]

Abstract base class for data transfer services.

Defines the interface that all data transfer services must implement, providing a consistent API for different transfer mechanisms such as file copying, cloud uploads, or network transfers.

TSettings is the type of the service's settings.

Properties

settings: The service settings

Methods:

Name Description
transfer

Executes the data transfer process

validate

Validates the data transfer service

settings property

settings: TSettings

Returns the settings for the data transfer service.

Returns:

Name Type Description
TSettings TSettings

The service settings

transfer abstractmethod

transfer() -> None

Executes the data transfer process. Must be implemented by subclasses.

This method should contain the core logic for transferring data from source to destination according to the service's specific implementation.

Source code in src/clabe/data_transfer/_base.py
@abc.abstractmethod
def transfer(self) -> None:
    """
    Executes the data transfer process. Must be implemented by subclasses.

    This method should contain the core logic for transferring data from
    source to destination according to the service's specific implementation.
    """

validate abstractmethod

validate() -> bool

Validates the data transfer service. Must be implemented by subclasses.

This method should verify that the service is properly configured and ready to perform data transfers, checking for required dependencies, connectivity, permissions, etc.

Returns:

Type Description
bool

True if the service is valid and ready for use, False otherwise

Source code in src/clabe/data_transfer/_base.py
@abc.abstractmethod
def validate(self) -> bool:
    """
    Validates the data transfer service. Must be implemented by subclasses.

    This method should verify that the service is properly configured and
    ready to perform data transfers, checking for required dependencies,
    connectivity, permissions, etc.

    Returns:
        True if the service is valid and ready for use, False otherwise
    """

RobocopyService

RobocopyService(
    source: PathLike, settings: RobocopySettings
)

Bases: DataTransfer[RobocopySettings], _DefaultExecutorMixin, ExecutableApp

A data transfer service that uses Robocopy to copy files between directories.

Provides a wrapper around the Windows Robocopy utility with configurable options for file copying, logging, and directory management.

Attributes:

Name Type Description
command Command[CommandResult]

The robocopy command to be executed

Methods:

Name Description
transfer

Executes the Robocopy file transfer

validate

Validates the Robocopy service configuration

Initializes the RobocopyService.

Parameters:

Name Type Description Default
source PathLike

The source root directory to copy from

required
settings RobocopySettings

RobocopySettings containing destination and options

required
Example
settings = RobocopySettings(
    destination="D:/destination",
    exclude_dirs=["__pycache__", ".git"],
    exclude_files=["*.pyc"],
)
service = RobocopyService("C:/source", settings)
Source code in src/clabe/data_transfer/robocopy.py
def __init__(
    self,
    source: PathLike,
    settings: RobocopySettings,
):
    """
    Initializes the RobocopyService.

    Args:
        source: The source root directory to copy from
        settings: RobocopySettings containing destination and options

    Example:
        ```python
        settings = RobocopySettings(
            destination="D:/destination",
            exclude_dirs=["__pycache__", ".git"],
            exclude_files=["*.pyc"],
        )
        service = RobocopyService("C:/source", settings)
        ```
    """
    self.source = source
    self._settings = settings
    self._command = self._build_command()

settings property

settings: TSettings

Returns the settings for the data transfer service.

Returns:

Name Type Description
TSettings TSettings

The service settings

command property

Returns the robocopy command to be executed.

run

run(
    executor_kwargs: dict[str, Any] | None = None,
    *,
    executor: Executor | None = None,
) -> CommandResult

Execute the command and return the result.

Parameters:

Name Type Description Default
executor_kwargs dict[str, Any] | None

Keyword arguments forwarded to the local executor.

None
executor Executor | None

Executor to run the command with, e.g. a RemoteRepository to run it on another machine. Defaults to a local executor built from executor_kwargs.

None
Source code in src/clabe/apps/_executors.py
@runnable
def run(self, executor_kwargs: dict[str, Any] | None = None, *, executor: Executor | None = None) -> CommandResult:
    """Execute the command and return the result.

    Args:
        executor_kwargs: Keyword arguments forwarded to the local executor.
        executor: Executor to run the command with, e.g. a ``RemoteRepository`` to run it on
            another machine. Defaults to a local executor built from ``executor_kwargs``.
    """
    if executor is not None and executor_kwargs is not None:
        raise ValueError("Pass either executor or executor_kwargs, not both.")
    return self.command.execute(executor or LocalExecutor(**(executor_kwargs or {})))

run_async async

run_async(
    executor_kwargs: dict[str, Any] | None = None,
    *,
    executor: AsyncExecutor | None = None,
) -> CommandResult

Execute the command asynchronously and return the result.

Parameters:

Name Type Description Default
executor_kwargs dict[str, Any] | None

Keyword arguments forwarded to the local executor.

None
executor AsyncExecutor | None

Executor to run the command with, e.g. a RemoteRepository to run it on another machine. Defaults to a local executor built from executor_kwargs.

None
Source code in src/clabe/apps/_executors.py
@runnable
async def run_async(
    self, executor_kwargs: dict[str, Any] | None = None, *, executor: AsyncExecutor | None = None
) -> CommandResult:
    """Execute the command asynchronously and return the result.

    Args:
        executor_kwargs: Keyword arguments forwarded to the local executor.
        executor: Executor to run the command with, e.g. a ``RemoteRepository`` to run it on
            another machine. Defaults to a local executor built from ``executor_kwargs``.
    """
    if executor is not None and executor_kwargs is not None:
        raise ValueError("Pass either executor or executor_kwargs, not both.")
    return await self.command.execute_async(executor or AsyncLocalExecutor(**(executor_kwargs or {})))

transfer

transfer() -> None

Executes the data transfer using Robocopy.

Uses the command executor pattern to run robocopy with configured settings.

Example
settings = RobocopySettings(destination="D:/backup")
service = RobocopyService("C:/data", settings)
service.transfer()
Source code in src/clabe/data_transfer/robocopy.py
@runnable(name="Transfer (robocopy)", notify="Transferring data (robocopy)…")
def transfer(self) -> None:
    """
    Executes the data transfer using Robocopy.

    Uses the command executor pattern to run robocopy with configured settings.

    Example:
        ```python
        settings = RobocopySettings(destination="D:/backup")
        service = RobocopyService("C:/data", settings)
        service.transfer()
        ```
    """
    self.run()

validate

validate() -> bool

Validates whether the Robocopy command is available on the system.

Returns:

Type Description
bool

True if Robocopy is available, False otherwise

Source code in src/clabe/data_transfer/robocopy.py
def validate(self) -> bool:
    """
    Validates whether the Robocopy command is available on the system.

    Returns:
        True if Robocopy is available, False otherwise
    """
    if not _HAS_ROBOCOPY:
        logger.warning("Robocopy command is not available on this system.")
        return False
    return True