Skip to content

Index

adapters

AXM Adapters package.

FileSystemAdapter

Adapter for atomic filesystem operations.

Supports both single operations and transactions for multi-file atomic operations with rollback on failure.

Source code in packages/axm-init/src/axm_init/adapters/filesystem.py
class FileSystemAdapter:
    """Adapter for atomic filesystem operations.

    Supports both single operations and transactions for multi-file
    atomic operations with rollback on failure.
    """

    def write_file(self, path: Path, content: str) -> bool:
        """Write content to a file, creating parent directories.

        Args:
            path: Target file path.
            content: File content to write.

        Returns:
            True if successful.
        """
        path.parent.mkdir(parents=True, exist_ok=True)
        path.write_text(content)
        return True

    def create_dir(self, path: Path) -> bool:
        """Create a directory (and parents).

        Args:
            path: Directory path to create.

        Returns:
            True if successful.
        """
        path.mkdir(parents=True, exist_ok=True)
        return True

    @contextmanager
    def transaction(self) -> Generator[Transaction, None, None]:
        """Context manager for atomic multi-file operations.

        On success: files are kept.
        On exception: all created files are rolled back.

        Yields:
            Transaction object for tracked operations.
        """
        tx = Transaction()
        try:
            yield tx
            tx.commit()
        except Exception:
            tx.rollback()
            raise
create_dir(path)

Create a directory (and parents).

Parameters:

Name Type Description Default
path Path

Directory path to create.

required

Returns:

Type Description
bool

True if successful.

Source code in packages/axm-init/src/axm_init/adapters/filesystem.py
def create_dir(self, path: Path) -> bool:
    """Create a directory (and parents).

    Args:
        path: Directory path to create.

    Returns:
        True if successful.
    """
    path.mkdir(parents=True, exist_ok=True)
    return True
transaction()

Context manager for atomic multi-file operations.

On success: files are kept. On exception: all created files are rolled back.

Yields:

Type Description
Transaction

Transaction object for tracked operations.

Source code in packages/axm-init/src/axm_init/adapters/filesystem.py
@contextmanager
def transaction(self) -> Generator[Transaction, None, None]:
    """Context manager for atomic multi-file operations.

    On success: files are kept.
    On exception: all created files are rolled back.

    Yields:
        Transaction object for tracked operations.
    """
    tx = Transaction()
    try:
        yield tx
        tx.commit()
    except Exception:
        tx.rollback()
        raise
write_file(path, content)

Write content to a file, creating parent directories.

Parameters:

Name Type Description Default
path Path

Target file path.

required
content str

File content to write.

required

Returns:

Type Description
bool

True if successful.

Source code in packages/axm-init/src/axm_init/adapters/filesystem.py
def write_file(self, path: Path, content: str) -> bool:
    """Write content to a file, creating parent directories.

    Args:
        path: Target file path.
        content: File content to write.

    Returns:
        True if successful.
    """
    path.parent.mkdir(parents=True, exist_ok=True)
    path.write_text(content)
    return True