# pyinfra.api.util module

`pyinfra.api.util.``ensure_list`(items)

`pyinfra.api.util.``exec_file`(filename, return_locals=False)

  Execute a Python file and optionally return it’s attributes as a dict.

`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.

class `pyinfra.api.util.``get_file_io`(filename_or_io)

  Bases: `object`

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

  `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_command`(command, env=None, su_user=None, sudo=False, sudo_user=None, preserve_sudo_env=False)

  Builds a shell command with various kwargs.

`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.``pop_op_kwargs`(state, kwargs)

  Pop and return operation global keyword arguments.

`pyinfra.api.util.``read_buffer`(io, print_output=False, print_func=False)

  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.``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).