From 75af023c864d1b6c4e48788b1b4cf7aad5eb2204 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Mon, 9 Jul 2012 16:41:45 -0400 Subject: Revert back to using cheetah + adjust resultant code + templates At this point there is a mixture of "double hash" cheetah comments and '#*' cheetah comments. --- cloudinit/config/cc_final_message.py | 17 +++++++---------- cloudinit/config/cc_update_etc_hosts.py | 6 +++--- cloudinit/templater.py | 11 +++++------ 3 files changed, 15 insertions(+), 19 deletions(-) (limited to 'cloudinit') diff --git a/cloudinit/config/cc_final_message.py b/cloudinit/config/cc_final_message.py index b1caca47..3865332f 100644 --- a/cloudinit/config/cc_final_message.py +++ b/cloudinit/config/cc_final_message.py @@ -26,23 +26,20 @@ from cloudinit.settings import PER_ALWAYS frequency = PER_ALWAYS -FINAL_MESSAGE_DEF = ("Cloud-init v. {{version}} finished at {{timestamp}}." - " Up {{uptime}} seconds.") +# Cheetah formated default message +FINAL_MESSAGE_DEF = ("Cloud-init v. ${version} finished at ${timestamp}." + " Up ${uptime} seconds.") def handle(_name, cfg, cloud, log, args): - msg_in = None + msg_in = '' if len(args) != 0: - msg_in = args[0] + msg_in = str(args[0]) else: - msg_in = util.get_cfg_option_str(cfg, "final_message") - - if not msg_in: - template_fn = cloud.get_template_filename('final_message') - if template_fn: - msg_in = util.load_file(template_fn) + msg_in = util.get_cfg_option_str(cfg, "final_message". msg_in) + msg_in = msg_in.strip() if not msg_in: msg_in = FINAL_MESSAGE_DEF diff --git a/cloudinit/config/cc_update_etc_hosts.py b/cloudinit/config/cc_update_etc_hosts.py index c148b12e..38108da7 100644 --- a/cloudinit/config/cc_update_etc_hosts.py +++ b/cloudinit/config/cc_update_etc_hosts.py @@ -36,11 +36,11 @@ def handle(name, cfg, cloud, log, _args): return # Render from a template file - distro_n = cloud.distro.name - tpl_fn_name = cloud.get_template_filename("hosts.%s" % (distro_n)) + tpl_fn_name = cloud.get_template_filename("hosts.%s" % + (cloud.distro.name)) if not tpl_fn_name: raise RuntimeError(("No hosts template could be" - " found for distro %s") % (distro_n)) + " found for distro %s") % (cloud.distro.name)) out_fn = cloud.paths.join(False, '/etc/hosts') templater.render_to_file(tpl_fn_name, out_fn, diff --git a/cloudinit/templater.py b/cloudinit/templater.py index c4259fa0..77af1270 100644 --- a/cloudinit/templater.py +++ b/cloudinit/templater.py @@ -20,13 +20,13 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from tempita import Template +from Cheetah.Template import Template from cloudinit import util def render_from_file(fn, params): - return render_string(util.load_file(fn), params, name=fn) + return render_string(util.load_file(fn), params) def render_to_file(fn, outfn, params, mode=0644): @@ -34,8 +34,7 @@ def render_to_file(fn, outfn, params, mode=0644): util.write_file(outfn, contents, mode=mode) -def render_string(content, params, name=None): - tpl = Template(content, name=name) +def render_string(content, params): if not params: - params = dict() - return tpl.substitute(params) + params = {} + return Template(content, searchList=[params]).respond() -- cgit v1.2.3