ahvn.utils.basic.cmd_utils module

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

Run a command and return requested items.

参数:
  • 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".

返回类型:

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

返回:

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()[源代码]

Return whether the current platform is macOS.

返回类型:

bool

ahvn.utils.basic.cmd_utils.is_windows()[源代码]

Return whether the current platform is Windows.

返回类型:

bool

ahvn.utils.basic.cmd_utils.is_linux()[源代码]

Return whether the current platform is Linux.

返回类型:

bool

ahvn.utils.basic.cmd_utils.browse(path)[源代码]

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

参数:

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