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

Function update_readme_data

updateHostsFile.py:1357–1403  ·  view source on GitHub ↗

Update the host and website information provided in the README JSON data. Parameters ---------- readme_file : str The name of the README file to update. readme_updates : kwargs Dictionary providing additional JSON fields to update before saving the data.

(readme_file, **readme_updates)

Source from the content-addressed store, hash-verified

1355
1356
1357def update_readme_data(readme_file, **readme_updates):
1358 """
1359 Update the host and website information provided in the README JSON data.
1360
1361 Parameters
1362 ----------
1363 readme_file : str
1364 The name of the README file to update.
1365 readme_updates : kwargs
1366 Dictionary providing additional JSON fields to update before
1367 saving the data. Currently, those fields are:
1368
1369 1) extensions
1370 2) sourcesdata
1371 3) numberofrules
1372 4) outputsubfolder
1373 5) nounifiedhosts
1374 """
1375
1376 extensions_key = "base"
1377 extensions = readme_updates["extensions"]
1378 nounifiedhosts = readme_updates["nounifiedhosts"]
1379
1380 if extensions:
1381 extensions_key = "-".join(extensions)
1382 if nounifiedhosts:
1383 extensions_key = extensions_key + "-only"
1384
1385 output_folder = readme_updates["outputsubfolder"]
1386 generation_data = {
1387 "location": path_join_robust(output_folder, ""),
1388 "nounifiedhosts": nounifiedhosts,
1389 "entries": readme_updates["numberofrules"],
1390 "sourcesdata": readme_updates["sourcesdata"],
1391 }
1392
1393 with open(readme_file, "r") as f:
1394 readme_data = json.load(f)
1395 readme_data[extensions_key] = generation_data
1396
1397 for denomination, data in readme_data.copy().items():
1398 if "location" in data and data["location"] and "\\" in data["location"]:
1399 # Windows compatibility: #1166
1400 readme_data[denomination]["location"] = data["location"].replace("\\", "/")
1401
1402 with open(readme_file, "w") as f:
1403 json.dump(readme_data, f)
1404
1405
1406def move_hosts_file_into_place(finalfile):

Callers 5

test_add_fieldsMethod · 0.90
test_modify_fieldsMethod · 0.90
test_set_extensionsMethod · 0.90
mainFunction · 0.85

Calls 1

path_join_robustFunction · 0.85

Tested by 4

test_add_fieldsMethod · 0.72
test_modify_fieldsMethod · 0.72
test_set_extensionsMethod · 0.72