diff options
author | Simo Sorce <simo@redhat.com> | 2014-04-18 00:16:12 -0400 |
---|---|---|
committer | Simo Sorce <simo@redhat.com> | 2014-04-21 00:05:05 -0400 |
commit | 47ff8363b7961188084f05c55558a166b06decb4 (patch) | |
tree | 64b9f5b443b1a4182f17ca346a87b819cc3ae69e /ipsilon/tools | |
parent | a20178b055e783b4146925596e815a05d82b0ac6 (diff) | |
download | ipsilon-47ff8363b7961188084f05c55558a166b06decb4.tar.gz ipsilon-47ff8363b7961188084f05c55558a166b06decb4.tar.xz ipsilon-47ff8363b7961188084f05c55558a166b06decb4.zip |
Move templatized file creation to tools
Signed-off-by: Simo Sorce <simo@redhat.com>
Diffstat (limited to 'ipsilon/tools')
-rwxr-xr-x | ipsilon/tools/files.py | 9 |
1 files changed, 9 insertions, 0 deletions
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) |