Merge lp:~nick-moffitt/charm-helpers/pass-more-data-to-context-dict-for-templates into lp:charm-helpers

Proposed by Nick Moffitt
Status: Merged
Merged at revision: 15
Proposed branch: lp:~nick-moffitt/charm-helpers/pass-more-data-to-context-dict-for-templates
Merge into: lp:charm-helpers
Prerequisite: lp:~nick-moffitt/charm-helpers/fix-rsync-output-munging
Diff against target: 15 lines (+2/-1)
1 file modified
charmhelpers/core/host.py (+2/-1)
To merge this branch: bzr merge lp:~nick-moffitt/charm-helpers/pass-more-data-to-context-dict-for-templates
Reviewer Review Type Date Requested Status
Matthew Wedgwood Pending
Review via email: mp+166485@code.launchpad.net

This proposal supersedes a proposal from 2013-05-30.

Description of the change

Right now the only way to add data to the context dictionary that is used in write_file is to poke strings into os.environ (because that's only made once when os is imported). This change will allow you to push your own keyword args into render_template_file and write_file that will appear alongside "conf" and "rel" and "env" etc in the context dictionary.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmhelpers/core/host.py'
2--- charmhelpers/core/host.py 2013-05-30 11:20:54 +0000
3+++ charmhelpers/core/host.py 2013-05-30 11:20:54 +0000
4@@ -106,9 +106,10 @@
5 os.chown(realpath, uid, gid)
6
7
8-def write_file(path, fmtstr, owner='root', group='root', perms=0444):
9+def write_file(path, fmtstr, owner='root', group='root', perms=0444, **kwargs):
10 """Create or overwrite a file with the contents of a string"""
11 context = execution_environment()
12+ context.update(kwargs)
13 log("Writing file {} {}:{} {:o}".format(path, owner, group,
14 perms))
15 uid = pwd.getpwnam(owner.format(**context)).pw_uid

Subscribers

People subscribed via source and target branches