CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-cgroupspy

Python library for managing Linux control groups (cgroups) with pythonic interface to filesystem operations

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

utilities.mddocs/

Utilities

Utility functions and helper classes for cgroup tree traversal, path manipulation, and content type handling.

Capabilities

Tree Traversal Utilities

Core traversal functions for walking through node hierarchies with different ordering strategies.

def walk_tree(root):
    """
    Pre-order depth-first traversal of a node tree.
    
    Parameters:
    - root: Node or NodeControlGroup, starting node for traversal
    
    Yields:
    Node objects in pre-order (parent before children)
    """

def walk_up_tree(root):
    """
    Post-order depth-first traversal of a node tree.
    
    Parameters:
    - root: Node or NodeControlGroup, starting node for traversal
    
    Yields:
    Node objects in post-order (children before parent)
    """

Usage example:

from cgroupspy.trees import Tree
from cgroupspy.utils import walk_tree, walk_up_tree

# Create tree
t = Tree()

# Walk entire tree pre-order
for node in walk_tree(t.root):
    print(f"Pre-order: {node.path}")

# Walk entire tree post-order  
for node in walk_up_tree(t.root):
    print(f"Post-order: {node.path}")

# Walk from specific node
cpuset = t.get_node_by_path('/cpuset/')
for node in walk_tree(cpuset):
    print(f"Cpuset subtree: {node.path}")

Path Manipulation

Path parsing and component extraction utilities for cgroup path handling.

def split_path_components(path):
    """
    Split a filesystem path into individual components.
    
    Parameters:
    - path: str or bytes, filesystem path to split
    
    Returns:
    List of path components (directories/files)
    
    Handles both absolute and relative paths, normalizing
    separators and removing empty components.
    """

Usage example:

from cgroupspy.utils import split_path_components

# Split absolute path
components = split_path_components('/sys/fs/cgroup/memory/docker')
print(components)  # ['sys', 'fs', 'cgroup', 'memory', 'docker']

# Split relative path
components = split_path_components('docker/container-id')
print(components)  # ['docker', 'container-id']

# Handle various path formats
components = split_path_components('//memory//test//')
print(components)  # ['memory', 'test']

Content Type System

Base classes and utilities for handling cgroup file content with automatic type conversion.

class BaseContentType:
    """Abstract base class for cgroup content type conversion."""
    
    def __str__(self) -> str:
        """Convert content to cgroup-compatible string format."""
    
    def __repr__(self) -> str:
        """Developer-friendly representation."""
    
    @classmethod
    def from_string(cls, value: str):
        """
        Parse content from cgroup file string format.
        
        Parameters:
        - value: str, raw string from cgroup file
        
        Returns:
        Instance of the content type
        """

Usage example:

from cgroupspy.contenttypes import DeviceAccess

# Create device access object
access = DeviceAccess(
    dev_type=DeviceAccess.TYPE_CHAR,
    major=1, minor=5,
    access=DeviceAccess.ACCESS_READ | DeviceAccess.ACCESS_WRITE
)

# Convert to cgroup format
print(str(access))  # "c 1:5 rw"

# Parse from cgroup format
parsed = DeviceAccess.from_string("c 1:5 rw")
print(parsed.dev_type)  # "c"
print(parsed.major)     # 1
print(parsed.minor)     # 5
print(parsed.can_read)  # True
print(parsed.can_write) # True

Types

# Tree traversal function signatures
WalkFunction = Callable[[Any], Generator[Any, None, None]]

# Path component handling
PathComponents = List[str]

Install with Tessl CLI

npx tessl i tessl/pypi-cgroupspy

docs

index.md

node-operations.md

resource-controllers.md

tree-management.md

utilities.md

tile.json