diff options
Diffstat (limited to 'ipapython/ipautil.py')
-rw-r--r-- | ipapython/ipautil.py | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/ipapython/ipautil.py b/ipapython/ipautil.py index 11433b4be..0b519c295 100644 --- a/ipapython/ipautil.py +++ b/ipapython/ipautil.py @@ -223,8 +223,17 @@ def template_str(txt, vars): return val def template_file(infilename, vars): - txt = open(infilename).read() - return template_str(txt, vars) + """Read a file and perform template substitutions""" + with open(infilename) as f: + return template_str(f.read(), vars) + + +def copy_template_file(infilename, outfilename, vars): + """Copy a file, performing template substitutions""" + txt = template_file(infilename, vars) + with open(outfilename, 'w') as file: + file.write(txt) + def write_tmp_file(txt): fd = tempfile.NamedTemporaryFile() @@ -237,7 +246,7 @@ def shell_quote(string): return "'" + string.replace("'", "'\\''") + "'" def run(args, stdin=None, raiseonerr=True, - nolog=(), env=None, capture_output=True): + nolog=(), env=None, capture_output=True, cwd=None): """ Execute a command and return stdin, stdout and the process return code. @@ -285,7 +294,7 @@ def run(args, stdin=None, raiseonerr=True, try: p = subprocess.Popen(args, stdin=p_in, stdout=p_out, stderr=p_err, - close_fds=True, env=env) + close_fds=True, env=env, cwd=cwd) stdout,stderr = p.communicate(stdin) stdout,stderr = str(stdout), str(stderr) # Make pylint happy except KeyboardInterrupt: |