def render_to_file(self, template_file, data_file, output_file): template = self.jj2_environment.get_template(template_file) data = self.context.get_data(data_file) reporter.report_templating(template_file, output_file) rendered_content = template.render(**data) utils.write_file_out(output_file, rendered_content) self._file_permissions_copy(template_file, output_file)
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 test_write_file_out(): content = """ helloworld """ test_file = "testout" write_file_out(test_file, content) with open(test_file, "r") as f: content = f.read() eq_(content, "\n helloworld\n")
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 apply_template(self, template_abs_path, template, data, output_file): rendered_content = self.engine.apply_template(template, data, output_file) if PY3_ABOVE: if not isinstance(rendered_content, bytes): rendered_content = rendered_content.encode("utf-8") try: flag = HASH_STORE.is_file_changed(output_file, rendered_content, template_abs_path) if flag: utils.write_file_out(output_file, rendered_content) utils.file_permissions_copy(template_abs_path, output_file) return flag except exceptions.FileNotFound: utils.write_file_out(output_file, rendered_content) return True