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
=== modified file 'charmhelpers/core/host.py'
--- charmhelpers/core/host.py 2013-05-30 11:20:54 +0000
+++ charmhelpers/core/host.py 2013-05-30 11:20:54 +0000
@@ -106,9 +106,10 @@
106 os.chown(realpath, uid, gid)106 os.chown(realpath, uid, gid)
107107
108108
109def write_file(path, fmtstr, owner='root', group='root', perms=0444):109def write_file(path, fmtstr, owner='root', group='root', perms=0444, **kwargs):
110 """Create or overwrite a file with the contents of a string"""110 """Create or overwrite a file with the contents of a string"""
111 context = execution_environment()111 context = execution_environment()
112 context.update(kwargs)
112 log("Writing file {} {}:{} {:o}".format(path, owner, group,113 log("Writing file {} {}:{} {:o}".format(path, owner, group,
113 perms))114 perms))
114 uid = pwd.getpwnam(owner.format(**context)).pw_uid115 uid = pwd.getpwnam(owner.format(**context)).pw_uid

Subscribers

People subscribed via source and target branches