ahvn.utils.basic.cmd_utils module¶

ahvn.utils.basic.cmd_utils.cmd(command, wait=True, shell=True, sudo=False, include=None, **kwargs)[source]¶

Run a command and return requested items.

Parameters:
  • command (Union[List[str], str]) – command to run.

  • wait (bool) – whether to wait for the process to finish.

  • shell (bool) – pass to subprocess.Popen.

  • sudo (bool) – prepend sudo to the command.

  • include (Union[List[Literal['handle', 'stdout', 'stderr', 'returncode']], str, None]) – list of keys to return. Default [“handle”]. Supported keys: “handle” (the Popen object), “stdout”, “stderr”, “returncode”.

Return type:

Union[Popen, str, Dict[str, Any]]

Returns:

If include == [“handle”] (default) returns the Popen object. If len(include) > 1 returns a dict mapping requested keys to values. If stdout/stderr are requested, they are captured via PIPE (unless provided in kwargs). If wait is False and stdout/stderr/returncode are requested, their values will be None (caller can read from process.stdout / process.stderr or wait later).

ahvn.utils.basic.cmd_utils.is_macos()[source]¶

Return whether the current platform is macOS.

Return type:

bool

ahvn.utils.basic.cmd_utils.is_windows()[source]¶

Return whether the current platform is Windows.

Return type:

bool

ahvn.utils.basic.cmd_utils.is_linux()[source]¶

Return whether the current platform is Linux.

Return type:

bool

ahvn.utils.basic.cmd_utils.browse(path)[source]¶

Open the file with a text editor, or open the folder in the file explorer. Platform-agnostic.

Parameters:

path (str) – The path to the file or folder to open.