MCPcopy Create free account
hub / github.com/bvcyber/RedWizard / write_template

Function write_template

step-2-create-inventory.py:104–119  ·  view source on GitHub ↗

Writes the completed template to the designated outfile

(out_file, output)

Source from the content-addressed store, hash-verified

102
103
104def write_template(out_file, output):
105 """ Writes the completed template to the designated outfile """
106 confirmation = input(f"\n{BOLD_RED}Saving inventory to {out_file}, are you sure? y/n{RESET}\n")
107 if not(confirmation == 'Y' or confirmation == 'y'):
108 return
109 try:
110 with open(out_file, 'w') as file_handler:
111 file_handler.truncate() # Clear the files before we start
112 file_handler.write(output)
113 print(f'{BOLD_RED}Saved{RESET}')
114 except FileNotFoundError:
115 print("Unable to write to %s" % str(out_file))
116 raise
117 except OSError as os_error:
118 print(f"Error opening file: {os_error:}")
119 raise
120
121def create_hosts_template(out_file, all_hosts):
122 """ Sets all the neccesary variables to print the jinja2 template """

Callers 1

create_hosts_templateFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected