Loading README.rst +1 −0 Original line number Diff line number Diff line Loading @@ -117,6 +117,7 @@ Jinja functions - :code:`run`: Runs a command and returns the stdout, stderr and returncode using run_. This function replaces the :code:`run` filter. - :code:`readfile`: Returns the contents of a file. Example usage can be seen in :code:`tests` and for specific filters in the docstrings in :code:`template/functions.py`. Loading template/functions.py +18 −0 Original line number Diff line number Diff line Loading @@ -39,3 +39,21 @@ def run(*argv, **kwargs): proc["stdout"] = proc["stdout"].decode() proc["stderr"] = proc["stderr"].decode() return proc def readfile(path): """ Opens a file, returns the contents. >>> readfile("/dev/null") '' >>> foo = "foo" >>> with open("/tmp/foo", "w") as f: ... f.write(foo) 3 >>> foo == readfile("/tmp/foo") True """ with open(path, "r") as f: # pylint: disable=invalid-name return f.read() Loading
README.rst +1 −0 Original line number Diff line number Diff line Loading @@ -117,6 +117,7 @@ Jinja functions - :code:`run`: Runs a command and returns the stdout, stderr and returncode using run_. This function replaces the :code:`run` filter. - :code:`readfile`: Returns the contents of a file. Example usage can be seen in :code:`tests` and for specific filters in the docstrings in :code:`template/functions.py`. Loading
template/functions.py +18 −0 Original line number Diff line number Diff line Loading @@ -39,3 +39,21 @@ def run(*argv, **kwargs): proc["stdout"] = proc["stdout"].decode() proc["stderr"] = proc["stderr"].decode() return proc def readfile(path): """ Opens a file, returns the contents. >>> readfile("/dev/null") '' >>> foo = "foo" >>> with open("/tmp/foo", "w") as f: ... f.write(foo) 3 >>> foo == readfile("/tmp/foo") True """ with open(path, "r") as f: # pylint: disable=invalid-name return f.read()