def write_file(filename, table_settings, prefix): """write_file writes the specified file""" file_dir = os.path.dirname(filename) if not os.path.exists(file_dir): os.makedirs(file_dir) file = open(filename, "w+") file.write("#!/bin/sh") file.write("\n\n") file.write("## Auto Generated\n") file.write("## DO NOT EDIT. Changes will be overwritten.\n") file.write("\n\n") file.write(nftables_util.table_all_cmds(table_settings) + "\n") file.write("\n") file.flush() file.close() os.chmod(filename, os.stat(filename).st_mode | stat.S_IEXEC) print("TableManager: Wrote %s" % filename) return