def _apply_template(self, template, data, output): rendered_content = template.render(**data) rendered_content = utils.strip_off_trailing_new_lines(rendered_content) rendered_content = rendered_content.encode("utf-8") flag = HASH_STORE.is_file_changed(output, rendered_content, template.filename) if flag: utils.write_file_out(output, rendered_content, strip=False, encode=False) utils.file_permissions_copy(template.filename, output) return flag
def apply_template(self, template_abs_path, template, data, output_file): rendered_content = self.engine.apply_template(template, data, output_file) rendered_content = utils.strip_off_trailing_new_lines(rendered_content) rendered_content = rendered_content.encode("utf-8") flag = HASH_STORE.is_file_changed(output_file, rendered_content, template_abs_path) if flag: utils.write_file_out(output_file, rendered_content, strip=False, encode=False) utils.file_permissions_copy(template_abs_path, output_file) return flag
def test_strip_new_lines(): content = "test\n\n\n\n\n" actual = strip_off_trailing_new_lines(content) eq_(actual, "test\n")