pyinfra.api.util¶
-
pyinfra.api.util.
exec_file
(filename)¶ Python 2
execfile
implementation for Python 2/3 that returns any locals from the file.I encountered a strange issue with doing this, for example:
hello = 'world' def test(): return hello thing = test()
Will raise a
NameError
claiming thehello
_global_ is undefined. To fix/hack around this the exec call is executed twice - the first collects “top level” items and the second is passed these as globals, so the function statements evaluate.GitHub issue: https://github.com/Fizzadar/pyinfra/issues/26
-
pyinfra.api.util.
get_arg_name
(arg)¶ Returns the name or value of an argument as passed into an operation. Will use pyinfra attr key where available, and function names instead of references. See attrs.py for a more in-depth description.
-
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_file_sha1
(filename)¶ 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.
make_command
(command, env=None, sudo=False, sudo_user=None)¶ 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.
read_buffer
(buff, 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.