Skip to content

Udevadm

udevadm helpers for settling device events, triggering rules, and querying device properties from the udev database.

sts.udevadm

Wrappers for udevadm subcommands (settle, info, trigger, etc.).

UdevadmCommand

Bases: ABC

Base class for udevadm subcommands.

Source code in sts_libs/src/sts/udevadm.py
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
class UdevadmCommand(ABC):
    """Base class for udevadm subcommands."""

    # Subcommand name (must be set by subclasses)
    SUBCOMMAND: ClassVar[str]

    @staticmethod
    def _build_command(subcommand: str, target: str | Path | None = None, **options: CommandOption) -> str:
        """Build udevadm command string with subcommand and options."""
        command_parts = ['udevadm', subcommand]

        # Add target if provided
        if target:
            command_parts.append(str(target))

        # Add options
        for option_key, value in options.items():
            if value is not None:
                key = option_key.replace('_', '-')
                if isinstance(value, bool) and value:
                    command_parts.append(f'--{key}')
                else:
                    command_parts.append(f'--{key}={value!s}')

        return ' '.join(command_parts)

    @classmethod
    def run(cls, target: str | Path | None = None, **options: CommandOption) -> CommandResult:
        """Run the udevadm subcommand with specified options."""
        cmd = cls._build_command(cls.SUBCOMMAND, target, **options)
        return run(cmd)

    @classmethod
    def help(cls) -> CommandResult:
        """Get help information for the subcommand."""
        return run(f'udevadm {cls.SUBCOMMAND} --help')

help() classmethod

Get help information for the subcommand.

Source code in sts_libs/src/sts/udevadm.py
51
52
53
54
@classmethod
def help(cls) -> CommandResult:
    """Get help information for the subcommand."""
    return run(f'udevadm {cls.SUBCOMMAND} --help')

run(target=None, **options) classmethod

Run the udevadm subcommand with specified options.

Source code in sts_libs/src/sts/udevadm.py
45
46
47
48
49
@classmethod
def run(cls, target: str | Path | None = None, **options: CommandOption) -> CommandResult:
    """Run the udevadm subcommand with specified options."""
    cmd = cls._build_command(cls.SUBCOMMAND, target, **options)
    return run(cmd)

UdevadmSettle

Bases: UdevadmCommand

Wait for pending udev events to complete.

Source code in sts_libs/src/sts/udevadm.py
57
58
59
60
class UdevadmSettle(UdevadmCommand):
    """Wait for pending udev events to complete."""

    SUBCOMMAND = 'settle'

udevadm_settle(**options)

Wait for pending udev events.

Parameters:

Name Type Description Default
**options CommandOption

Options such as timeout (int), exit_if_exists (str), quiet (bool)

{}
Source code in sts_libs/src/sts/udevadm.py
66
67
68
69
70
71
72
def udevadm_settle(**options: CommandOption) -> CommandResult:
    """Wait for pending udev events.

    Args:
        **options: Options such as timeout (int), exit_if_exists (str), quiet (bool)
    """
    return UdevadmSettle.run(target=None, **options)