waft.system.nodes.unix_node module

class waft.system.nodes.unix_node.UnixNode(client: ClientBase)

Bases: BaseNode

Node class for unix specific functionality

chmod(filepath: PurePath, permissions: int)

Change owner of file :param filepath: Path to file for which to change owner :param permissions: Integer representation of permissions to set for file

(ex. 777 for rwx permissions for all users and groups)

chown(filepath: PurePath, owner: str, recursive: bool = False)

Change owner of file

Parameters:
  • filepath – Path to file for which to change owner

  • owner – New owner for file in question

  • recursive – Operate on files and directories recursively

copy_file(path_from: PurePath, path_to: PurePath)

Copy a file

directory_exists(directory: PurePath) bool

Check if the given directory exists on the node and return boolean value

Parameters:

directory – Directory path to check exists

file_exists(path_from: PurePath) bool

Check to see if a file exists.

Parameters:

path_from – Path of the file

Returns: bool indicating if the file exists or not

get_domain_ips(domain: str) List[IPv4Address | IPv6Address]

Get IPv4 and IPv6 addresses for a domain and its www subdomain.

Parameters:

domain (str) – The domain to resolve.

Returns:

A list of IPs

Return type:

list

get_sha256_of_file(remote_file_path: PurePath) str | None

Get the sha256 of a file

getenv(key: str, default: Any = None) Any

Return an environment variable value.

Parameters:
  • key (str) – Environment variable name

  • default (Any, optional) – Value to return if variable is not set. Defaults to None.

Returns:

environment variable value

Return type:

Any

property home_dir: str

Return the full path to the home directory of the user on the current node

install_uv(version: str | None = None)

Install uv on the node

Parameters:

version (Optional[str]) – Specific uv version to install. Installs the latest by default.

is_process_running(pid: str) bool

Return boolean indicating if process with given PID is running

Parameters:

pid – Process ID to check if is running

Link file at given path

Parameters:
  • source_file – Path to file to link

  • target_file – Path to file to link to

  • sudo – Boolean indicating if command should be run using sudo

  • link_type – Link type

make_directory(directory: PurePath, recursive: bool = False, sudo: bool = False)

Creates directory at given location if not already present

Parameters:
  • directory – Full path to directory to be created

  • recursive – If set to True all parent directories will be created as well

  • sudo – If set to True the command will be run with sudo permissions

move_file(path_from: PurePath, path_to: PurePath)

Move a file from one place on a node to another

newest_file_in_dir(directory: PurePath, tstamp: Literal['atime', 'ctime', 'mtime']) PurePath

Return the most recently modified file

Parameters:
  • directory – PurePath object pointing to the directory in question

  • tstamp – Type of timestamp to sort by

norm_path

alias of PurePosixPath

property platform_is_unix: bool

Return boolean indicating whether system is a Unix-based platform

Returns:

True if node is a Unix-based platform, False otherwise

Return type:

bool

read_file(file_path: str | PurePath, sudo: bool = False) str

Read the contents of a remote file.

Parameters:
  • file_path (str | PurePath) – Path of the file on the remote system to read

  • sudo (bool) – If set to True the command will run with sudo permissions. Defaults to False.

Returns:

file contents

Return type:

str

remove_directory(directory: PurePath, recursive: bool = False)

Remove given directory

Parameters:
  • directory – Directory path to remove

  • recursive – If set to true all contained directories will be deleted as well, otherwise an exception will be raised if there are subdirectories

remove_file(filepath: PurePath, sudo: bool = False)

Remove file at given filepath

Parameters:
  • filepath – Path to file to be removed

  • sudo – Should sudo be used when removing the file

resolve_dns_name(domain_name: str | None = None, type: str | None = None, extract: ResolveDnsNameExtractionTypes | None = None, **kwargs: Any) str

Check dns resolution of a domain name.

Parameters:
  • domain_name – Domain name

  • type – Optionally specify a type to return e.g. TXT

  • extract – Unused in this case

  • **kwargs – Unused in this case

Returns: DNS resolution output from dig command.

restart_system(delay: int = 0, wait: bool = True)

Restart the node operating system.

Parameters:
  • delay (int, optional) – Time (in minutes) before the restart occurs. Defaults to 0.

  • wait (bool, optional) – True to wait for the system restart to complete (default) or False not to wait.

run_background_command(command: List[str], sudo: bool = False)

Run a command in the background as a context manager

Parameters:
  • command – List of strings to form the command to be run

  • sudo – Run command with sudo permissions. On Windows this will be run with the “System” account

run_dig(domain: str, dig_params: List[str] | None = None) Result

Generic method that will run a dig command from the node :param domain: domain to run query against e.g. example.com :param dig_params: valid dig parameters e.g. +short

property system_type: str

Return the type of underlying node system

touch_file(filepath: PurePath)

Touch file at given path

Parameters:

filepath – Path to file to touch