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

Function update_sources_data

updateHostsFile.py:669–718  ·  view source on GitHub ↗

Update the sources data and information for each source. Parameters ---------- sourcesdata : list The list of sources data that we are to update. sourcesparams : kwargs Dictionary providing additional parameters for updating the sources data. Currently,

(sourcesdata, **sourcesparams)

Source from the content-addressed store, hash-verified

667
668# Update Logic
669def update_sources_data(sourcesdata, **sourcesparams):
670 """
671 Update the sources data and information for each source.
672
673 Parameters
674 ----------
675 sourcesdata : list
676 The list of sources data that we are to update.
677 sourcesparams : kwargs
678 Dictionary providing additional parameters for updating the
679 sources data. Currently, those fields are:
680
681 1) datapath
682 2) extensions
683 3) extensionspath
684 4) sourcedatafilename
685 5) nounifiedhosts
686
687 Returns
688 -------
689 update_sources_data : list
690 The original source data list with new source data appended.
691 """
692
693 sourcedatafilename = sourcesparams["sourcedatafilename"]
694
695 if not sourcesparams["nounifiedhosts"]:
696 for source in sort_sources(
697 recursive_glob(sourcesparams["datapath"], sourcedatafilename)
698 ):
699 updatefile = open(source, "r", encoding="UTF-8")
700 try:
701 updatedata = json.load(updatefile)
702 sourcesdata.append(updatedata)
703 finally:
704 updatefile.close()
705
706 for source in sourcesparams["extensions"]:
707 sourcedir = path_join_robust(sourcesparams["extensionspath"], source)
708 for updatefile_path in sort_sources(
709 recursive_glob(sourcedir, sourcedatafilename)
710 ):
711 updatefile = open(updatefile_path, "r")
712 try:
713 updatedata = json.load(updatefile)
714 sourcesdata.append(updatedata)
715 finally:
716 updatefile.close()
717
718 return sourcesdata
719
720
721def jsonarray(json_array_string):

Callers 2

update_sources_dataMethod · 0.90
mainFunction · 0.85

Calls 3

sort_sourcesFunction · 0.85
recursive_globFunction · 0.85
path_join_robustFunction · 0.85

Tested by 1

update_sources_dataMethod · 0.72