plox.tools.system¶
Utilities for interaction with local system binaries, executables, etc.
from plox.tools import system
Functions¶
|
Block execution (up to timeout_s) until (condition) returns True. |
|
Executed a system command. |
|
Execute a system command, threaded logging safe. |
|
Convert syscall function (returns int) to boolean with exception catch. |
Module Contents¶
- plox.tools.system.block_until(condition, effect, timeout_s=360, condition_fail_wait_s=10)¶
Block execution (up to timeout_s) until (condition) returns True.
When condition returns true, executes effect.
- Parameters:
condition (Callable[[], bool]) – Condition to wait for.
effect (Callable[[], int]) – Effect to trigger once condition is met.
timeout_s (int) – Max time in seconds to wait for condition. By default, is 6 minutes (360 seconds).
condition_fail_wait_s (int) – On condition fail, time to wait before attempting to check condition again. By default, is 10 seconds.
- Returns:
effect’s return code.
- Return type:
- plox.tools.system.sync_command(cmd, shell=False, exit_on_error=False)¶
Executed a system command.
- Parameters:
cmd (str) – Command to execute on host.
shell (bool) – Whether or not to execute the command as passed, or if should be tokenized and passed as list of values to subprocess. By default, passed command is split for safety.
exit_on_error (bool) – Whether or not hard exit should occur if process does not return successfully. By default, false.
- Returns:
The completed process.
- Return type:
- plox.tools.system.sys_exec(cwd, executable, exec_args, environment, stdout_file_dest=None, quiet_stderr=False, exec_timeout_mins=24)¶
Execute a system command, threaded logging safe.
- Parameters:
cwd (pathlib.Path) – Current directory that command is being invoked from.
executable (pathlib.Path) – Path to local binary that should be excecuted.
exec_args (list[str]) – List of args to pass to the executable.
environment (dict[Any, Any]) – Dictionary of k:v pairings to pass to the executable process’ environment.
stdout_file_dest (Optional[pathlib.Path]) – Optional file to log output text to. By default, does not log to file.
quiet_stderr (bool) – Whether or not stderr output should be silenced. By default, stderr is not silenced.
exec_timeout_mins (int) – Time in minutes before command is timed out. By default, is 24 minutes.
- Returns:
Return code of executed process.
- Return type:
- plox.tools.system.syscall_to_condition(call)¶
Convert syscall function (returns int) to boolean with exception catch.