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

Function sort_sources

updateHostsFile.py:495–520  ·  view source on GitHub ↗

Sorts the sources. The idea is that all Steven Black's list, file or entries get on top and the rest sorted alphabetically. Parameters ---------- sources: list The sources to sort.

(sources)

Source from the content-addressed store, hash-verified

493
494
495def sort_sources(sources):
496 """
497 Sorts the sources.
498 The idea is that all Steven Black's list, file or entries
499 get on top and the rest sorted alphabetically.
500
501 Parameters
502 ----------
503 sources: list
504 The sources to sort.
505 """
506
507 result = sorted(
508 sources.copy(),
509 key=lambda x: x.lower().replace("-", "").replace("_", "").replace(" ", ""),
510 )
511
512 # Steven Black's repositories/files/lists should be on top!
513 stevenblackpositions = [
514 x for x, y in enumerate(result) if "stevenblack" in y.lower()
515 ]
516
517 for index in stevenblackpositions:
518 result.insert(0, result.pop(index))
519
520 return result
521
522
523# Exclusion logic

Callers 5

test_live_dataMethod · 0.90
update_sources_dataFunction · 0.85
update_all_sourcesFunction · 0.85
create_initial_fileFunction · 0.85

Calls

no outgoing calls

Tested by 2

test_live_dataMethod · 0.72