def write_file_out(filename, content): if not file_system.is_zip_alike_url(filename): dest_folder = os.path.dirname(filename) if dest_folder: file_system.mkdir_p(dest_folder) file_system.write_bytes(filename, content)
def write_file_out(self, filename, content): if filename == "-": print(content.decode()) elif file_system.is_zip_alike_url(filename): self.write_file_out_to_zip(filename, content) else: write_file_out(filename, content)
def apply_template(self, template_abs_path, template, data, output_file): # render the content rendered_content = self.engine.apply_template(template, data, output_file) # convert to utf8 if not already if not isinstance(rendered_content, bytes): rendered_content = rendered_content.encode("utf-8") # attempt to output to the file and printing to stdout instead # if not found try: # check if any of the files have changed flag = HASH_STORE.is_file_changed(output_file, rendered_content, template_abs_path) # if they have re-render things if flag: # write the content to the output file self.buffered_writer.write_file_out(output_file, rendered_content) # attempt to copy the file permissions of the template # file to the output file # if it isn't an archive proceed or stdout if (not file_system.is_zip_alike_url(output_file) and output_file != "-"): try: file_system.file_permissions_copy( template_abs_path, output_file) except exceptions.NoPermissionsNeeded: # HttpFs does not have getsyspath # zip, tar have no permission # win32 does not work pass return flag except exceptions.FileNotFound: # the template is a string from command line LOG.info(f"{template_abs_path} is not a file") self.buffered_writer.write_file_out(output_file, rendered_content) return True
def apply_template(self, template_abs_path, template, data, output_file): rendered_content = self.engine.apply_template(template, data, output_file) 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: self.buffered_writer.write_file_out(output_file, rendered_content) if not file_system.is_zip_alike_url(output_file): file_system.file_permissions_copy(template_abs_path, output_file) return flag except exceptions.FileNotFound: # the template is a string from command line LOG.info(f"{template_abs_path} is not a file") self.buffered_writer.write_file_out(output_file, rendered_content) return True
def write_file_out(self, filename, content): if file_system.is_zip_alike_url(filename): self.write_file_out_to_zip(filename, content) else: write_file_out(filename, content)