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

Function write_opening_header

updateHostsFile.py:1207–1354  ·  view source on GitHub ↗

Write the header information into the newly-created hosts file. Parameters ---------- finalfile : file The file object that points to the newly-created hosts file. headerparams : kwargs Dictionary providing additional parameters for populating the header

(finalfile, **headerparams)

Source from the content-addressed store, hash-verified

1205
1206
1207def write_opening_header(finalfile, **headerparams):
1208 """
1209 Write the header information into the newly-created hosts file.
1210
1211 Parameters
1212 ----------
1213 finalfile : file
1214 The file object that points to the newly-created hosts file.
1215 headerparams : kwargs
1216 Dictionary providing additional parameters for populating the header
1217 information. Currently, those fields are:
1218
1219 1) extensions
1220 2) numberofrules
1221 3) outputsubfolder
1222 4) skipstatichosts
1223 5) nounifiedhosts
1224 """
1225
1226 finalfile.seek(0) # Reset file pointer.
1227 file_contents = finalfile.read() # Save content.
1228
1229 finalfile.seek(0) # Write at the top.
1230
1231 nounifiedhosts = headerparams["nounifiedhosts"]
1232
1233 if headerparams["extensions"]:
1234 if nounifiedhosts:
1235 if len(headerparams["extensions"]) > 1:
1236 write_data(
1237 finalfile,
1238 "# Title: StevenBlack/hosts extensions {0} and {1} \n#\n".format(
1239 ", ".join(headerparams["extensions"][:-1]),
1240 headerparams["extensions"][-1],
1241 ),
1242 )
1243 else:
1244 write_data(
1245 finalfile,
1246 "# Title: StevenBlack/hosts extension {0}\n#\n".format(
1247 ", ".join(headerparams["extensions"])
1248 ),
1249 )
1250 else:
1251 if len(headerparams["extensions"]) > 1:
1252 write_data(
1253 finalfile,
1254 "# Title: StevenBlack/hosts with the {0} and {1} extensions\n#\n".format(
1255 ", ".join(headerparams["extensions"][:-1]),
1256 headerparams["extensions"][-1],
1257 ),
1258 )
1259 else:
1260 write_data(
1261 finalfile,
1262 "# Title: StevenBlack/hosts with the {0} extension\n#\n".format(
1263 ", ".join(headerparams["extensions"])
1264 ),

Callers 7

test_basicMethod · 0.90
test_extensionsMethod · 0.90
test_no_unified_hostsMethod · 0.90
_check_preambleMethod · 0.90
mainFunction · 0.85

Calls 3

write_dataFunction · 0.85
path_join_robustFunction · 0.85
maybe_copy_example_fileFunction · 0.85

Tested by 6

test_basicMethod · 0.72
test_extensionsMethod · 0.72
test_no_unified_hostsMethod · 0.72
_check_preambleMethod · 0.72