Skip to content

clabe.utils

get_computer_name

get_computer_name() -> str

Returns this machine's name.

Returns:

Name Type Description
str str

The machine name.

Source code in src/clabe/utils/__init__.py
def get_computer_name() -> str:
    """
    Returns this machine's name.

    Returns:
        str: The machine name.
    """
    return os.environ.get("COMPUTERNAME") or os.environ.get("HOSTNAME") or socket.gethostname()

is_this_computer

is_this_computer(name: str) -> bool

Returns whether a computer name, e.g. a rig's computer_name, names this machine.

The comparison ignores case and any domain suffix, so RIG-A and rig-a.corp.org both match rig-a.

Parameters:

Name Type Description Default
name str

The computer name to check.

required

Returns:

Name Type Description
bool bool

True if the name is this machine's.

Source code in src/clabe/utils/__init__.py
def is_this_computer(name: str) -> bool:
    """
    Returns whether a computer name, e.g. a rig's ``computer_name``, names this machine.

    The comparison ignores case and any domain suffix, so ``RIG-A`` and ``rig-a.corp.org`` both match ``rig-a``.

    Args:
        name: The computer name to check.

    Returns:
        bool: True if the name is this machine's.
    """
    names = {get_computer_name(), socket.gethostname(), "localhost"}
    return name.split(".")[0].lower() in {n.split(".")[0].lower() for n in names}

abspath

abspath(path: PathLike) -> Path

Helper method that converts a path to an absolute path.

Parameters:

Name Type Description Default
path PathLike

The path to convert

required

Returns:

Name Type Description
Path Path

The absolute path

Source code in src/clabe/utils/__init__.py
def abspath(path: os.PathLike) -> Path:
    """
    Helper method that converts a path to an absolute path.

    Args:
        path: The path to convert

    Returns:
        Path: The absolute path
    """
    return Path(path).resolve()