fftools.shell

fftools.shell.extract_archive(archive: Path) None[source]

extract an archive file.

supportet are: tar, zip, gzip, bzip2 and xz.

Parameters:

archive (Path) – path of the archive to extract.

Return type:

None

fftools.shell.extract_file(atype: Literal['gzip', 'bzip', 'xz'], infile: Path, outfile: Path) None[source]

extract file.

Parameters:
  • atype (Literal['gzip', 'bzip', 'xz']) – archive type.

  • infile (Path) – compressed input file

  • outfile (Path) – decompressed output file.

Raises:

ValueError – on invalid atype.

Return type:

None

fftools.shell.run_command(command: str | list[str] | tuple[str] | set[str], timeout: int = 10, check_ecode: bool = True, **kwargs) tuple[int, str, str][source]

run local shell command.

Parameters:
  • command (str | list[str] | tuple[str] | set[str]) – command to run.

  • timeout (int) – timeout in seconds. Defaults to 10.

  • check_ecode (bool) – if exception should be raised on non-zero exit codes. Defaults to True.

  • kwargs – other kwargs directly supplied to subprocess.run

Raises:
  • ValueError – if command is not either a str, list, tuple or set.

  • exc – if check_ecode is True and the exit code is not 0.

Returns:

tuple of (exit code, stdout, stderr).

Return type:

tuple[int, str, str]

fftools.shell.run_ssh_command(command: str | list[str] | tuple[str] | set[str], hostname: str, username: str = 'root', port: int = 22, timeout: int = 10, check_ecode: bool = True, password: str | None = None, **kwargs) tuple[int, str, str][source]

run command on remote machine via ssh.

Parameters:
  • command (str | list[str] | tuple[str] | set[str]) – command to run.

  • hostname (str) – hostname of remote device.

  • username (str) – ssh username. Defaults to “root”.

  • port (int) – ssh port. Defaults to 22.

  • timeout (int) – command timeout. Defaults to 10.

  • check_ecode (bool) – if exception should be raised on non-zero exit codes. Defaults to True.

  • password (str | None) – ssh user password if not authenticated via ssh keys. Defaults to None.

  • kwargs – other kwargs directly supplied to fabric.Connection.run

Raises:
  • ValueError – if command is not either a str, list, tuple or set.

  • exc – if check_ecode is True and the exit code is not 0.

Returns:

tuple of (exit code, stdout, stderr)

Return type:

tuple[int, str, str]