pyinfra.api.util module

class pyinfra.api.util.FallbackDict(*datas)

Bases: object

Combines multiple AttrData’s to search for attributes.

dict()
override_datas = None
pyinfra.api.util.ensure_host_list(hosts, inventory)
pyinfra.api.util.extract_callable_datas(datas)
pyinfra.api.util.format_exception(e)
pyinfra.api.util.get_arg_value(state, host, arg)

Runs string arguments through the jinja2 templating system with a state and host. Used to avoid string formatting in deploy operations which result in one operation per host/variable. By parsing the commands after we generate the op_hash, multiple command variations can fall under one op.

pyinfra.api.util.get_caller_frameinfo(frame_offset=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
close = False
pyinfra.api.util.get_file_sha1(filename_or_io)

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

pyinfra.api.util.get_template(filename_or_string, is_string=False)

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_host_command_error(host, e, timeout=0)
pyinfra.api.util.make_hash(obj)

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)
pyinfra.api.util.pop_global_op_kwargs(state, kwargs)

Pop and return operation global keyword arguments.

pyinfra.api.util.read_buffer(type_, io, output_queue, print_output=False, print_func=None)

Reads a file-like buffer object into lines and optionally prints the output.

pyinfra.api.util.sha1_hash(string)

Return the SHA1 of the input string.

pyinfra.api.util.show_stdin_global_warning()
pyinfra.api.util.try_int(value)
pyinfra.api.util.underscore(name)

Transform CamelCase -> snake_case.

pyinfra.api.util.unroll_generators(generator)

Take a generator and unroll any sub-generators recursively. This is essentially a Python 2 way of doing yield from in Python 3 (given iterating the entire thing).