pyinfra.api.util module

pyinfra.api.util.format_exception(e: Exception) str
pyinfra.api.util.get_call_location(frame_offset: int = 1)
pyinfra.api.util.get_caller_frameinfo(frame_offset: int = 0)
class pyinfra.api.util.get_file_io(filename_or_io, mode='rb')

Bases: object

Given either a filename or an existing IO object, this context processor will open and close filenames, and leave IO objects alone.

property cache_key
filename_or_io: str | IO[Any]
mode: str
pyinfra.api.util.get_file_path(state: State, filename: str)

Calculates the SHA1 of a file or file object using a buffer to handle larger files.

pyinfra.api.util.get_kwargs_str(kwargs: Dict[Any, Any])
pyinfra.api.util.get_operation_order_from_stack(state: State)
pyinfra.api.util.get_path_permissions_mode(pathname: str)

Get the permissions (bits) of a path as an integer.

pyinfra.api.util.get_template(filename_or_io: str | IO)

Gets a jinja2 Template object for the input filename or string, with caching based on the filename of the template, or the SHA1 of the input string.

pyinfra.api.util.log_error_or_warning(host: Host, ignore_errors: bool, description: str = '', continue_on_error: bool = False) None
pyinfra.api.util.log_host_command_error(host: Host, e: Exception, timeout: int | None = 0) None
pyinfra.api.util.log_operation_start(op_meta: StateOperationMeta, op_types: List | None = None, prefix: str = '--> ') None

Make a hash from an arbitrary nested dictionary, list, tuple or set, used to generate ID’s for operations based on their name & arguments.

pyinfra.api.util.memoize(func: Callable[[...], Any])
pyinfra.api.util.print_host_combined_output(host: Host, output: CommandOutput) None
pyinfra.api.util.raise_if_bad_type(value: Any, type_: Type, exception: type[Exception], message_prefix: str)
pyinfra.api.util.sha1_hash(string: str) str

Return the SHA1 of the input string.