Skip to content

bmctools.misc.utils

DirectoryError

Custom exception to throw directoryerror

is_command

def is_command(cmd: str) -> bool

Check whether a command is available on the current system PATH.

Args: cmd: Command name to look up (e.g. 'racadm').

Returns: True if the command is found on PATH.

Raises: FileNotFoundError: If the command is not found.

Parameters:

NameTypeDefaultDescription
cmdstr

Returns: bool

is_dir_writeable

def is_dir_writeable(dir: str) -> bool

Test whether a directory exists and is writeable.

Args: dir: Absolute or relative path to the directory.

Returns: True if the directory exists and is writeable.

Raises: DirectoryError: If the directory does not exist or is not writeable.

Parameters:

NameTypeDefaultDescription
dirstr

Returns: bool

is_older_than_unit

def is_older_than_unit(given_time: str, age: int, unit: str) -> bool

Check whether a timestamp is older than the given duration.

Args: given_time: Datetime string in '%Y-%m-%d %H:%M:%S' format. age: Numeric age threshold. unit: Time unit character — 'd' (days), 'h' (hours), 'm' (minutes), or 's' (seconds).

Returns: True if given_time is older than age unit\s ago, False otherwise.

Parameters:

NameTypeDefaultDescription
given_timestr
ageint
unitstr

Returns: bool