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

Proposed by Nick Moffitt
Status: Superseded
Proposed branch: lp:~nick-moffitt/charm-helpers/pass-more-data-to-context-dict-for-templates
Merge into: lp:charm-helpers
Diff against target: 24 lines (+3/-2)
1 file modified
charmhelpers/core/host.py (+3/-2)
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+166484@code.launchpad.net

This proposal has been superseded by 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.

Unmerged revisions

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-22 21:11:01 +0000
3+++ charmhelpers/core/host.py 2013-05-30 11:18:27 +0000
4@@ -73,7 +73,7 @@
5 cmd.append(from_path.format(**context))
6 cmd.append(to_path.format(**context))
7 log(" ".join(cmd))
8- return subprocess.check_output(cmd).output.strip()
9+ return subprocess.check_output(cmd).strip()
10
11
12 def symlink(source, destination):
13@@ -106,9 +106,10 @@
14 os.chown(realpath, uid, gid)
15
16
17-def write_file(path, fmtstr, owner='root', group='root', perms=0444):
18+def write_file(path, fmtstr, owner='root', group='root', perms=0444, **kwargs):
19 """Create or overwrite a file with the contents of a string"""
20 context = execution_environment()
21+ context.update(kwargs)
22 log("Writing file {} {}:{} {:o}".format(path, owner, group,
23 perms))
24 uid = pwd.getpwnam(owner.format(**context)).pw_uid

Subscribers

People subscribed via source and target branches