MCPcopy
hub / github.com/StevenBlack/hosts / create_initial_file

Function create_initial_file

updateHostsFile.py:800–843  ·  view source on GitHub ↗

Initialize the file in which we merge all host files for later pruning. Parameters ---------- headerparams : kwargs Dictionary providing additional parameters for populating the initial file information. Currently, those fields are: 1) nounifiedhosts

(**initial_file_params)

Source from the content-addressed store, hash-verified

798
799# File Logic
800def create_initial_file(**initial_file_params):
801 """
802 Initialize the file in which we merge all host files for later pruning.
803
804 Parameters
805 ----------
806 headerparams : kwargs
807 Dictionary providing additional parameters for populating the initial file
808 information. Currently, those fields are:
809
810 1) nounifiedhosts
811 """
812
813 mergefile = tempfile.NamedTemporaryFile()
814
815 if not initial_file_params["nounifiedhosts"]:
816 # spin the sources for the base file
817 for source in sort_sources(
818 recursive_glob(settings["datapath"], settings["hostfilename"])
819 ):
820 start = "# Start {}\n\n".format(os.path.basename(os.path.dirname(source)))
821 end = "\n# End {}\n\n".format(os.path.basename(os.path.dirname(source)))
822
823 with open(source, "r", encoding="UTF-8") as curFile:
824 write_data(mergefile, start + curFile.read() + end)
825
826 # spin the sources for extensions to the base file
827 for source in settings["extensions"]:
828 for filename in sort_sources(
829 recursive_glob(
830 path_join_robust(settings["extensionspath"], source),
831 settings["hostfilename"],
832 )
833 ):
834 with open(filename, "r") as curFile:
835 write_data(mergefile, curFile.read())
836
837 maybe_copy_example_file(settings["blacklistfile"])
838
839 if os.path.isfile(settings["blacklistfile"]):
840 with open(settings["blacklistfile"], "r") as curFile:
841 write_data(mergefile, curFile.read())
842
843 return mergefile
844
845
846def compress_file(inputfile, targetip, outputfile):

Callers 1

mainFunction · 0.85

Calls 5

sort_sourcesFunction · 0.85
recursive_globFunction · 0.85
write_dataFunction · 0.85
path_join_robustFunction · 0.85
maybe_copy_example_fileFunction · 0.85

Tested by

no test coverage detected