From 47ff8363b7961188084f05c55558a166b06decb4 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Fri, 18 Apr 2014 00:16:12 -0400 Subject: Move templatized file creation to tools Signed-off-by: Simo Sorce --- ipsilon/tools/files.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'ipsilon/tools/files.py') diff --git a/ipsilon/tools/files.py b/ipsilon/tools/files.py index 7f3bf7f..a18384c 100755 --- a/ipsilon/tools/files.py +++ b/ipsilon/tools/files.py @@ -19,6 +19,7 @@ import os import pwd +from string import Template def fix_user_dirs(path, user=None, mode=0700): @@ -35,3 +36,11 @@ def fix_user_dirs(path, user=None, mode=0700): if pw: os.chown(root, pw.pw_uid, pw.pw_gid) os.chmod(root, mode) + + +def write_from_template(destfile, template, opts): + with open(template) as f: + t = Template(f.read()) + text = t.substitute(**opts) # pylint: disable=star-args + with open(destfile, 'w+') as f: + f.write(text) -- cgit