2017-05-21 20:02:34 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
# Script by gfyoung
|
|
|
|
# https://github.com/gfyoung
|
|
|
|
#
|
|
|
|
# This Python script will generate hosts files and update the readme file.
|
|
|
|
|
|
|
|
from __future__ import print_function
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import argparse
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
|
|
|
|
def print_failure(msg):
|
|
|
|
"""
|
|
|
|
Print a failure message.
|
|
|
|
|
|
|
|
Parameters
|
|
|
|
----------
|
|
|
|
msg : str
|
|
|
|
The failure message to print.
|
|
|
|
"""
|
|
|
|
|
|
|
|
print("\033[91m" + msg + "\033[0m")
|
|
|
|
|
|
|
|
|
|
|
|
def update_hosts_file(*flags):
|
|
|
|
"""
|
|
|
|
Wrapper around running updateHostsFile.py
|
|
|
|
|
|
|
|
Parameters
|
|
|
|
----------
|
|
|
|
flags : varargs
|
|
|
|
Commandline flags to pass into updateHostsFile.py. For more info, run
|
|
|
|
the following command in the terminal or command prompt:
|
|
|
|
|
|
|
|
```
|
|
|
|
python updateHostsFile.py -h
|
|
|
|
```
|
|
|
|
"""
|
|
|
|
|
|
|
|
if subprocess.call([sys.executable, "updateHostsFile.py"] + list(flags)):
|
|
|
|
print_failure("Failed to update hosts file")
|
|
|
|
|
|
|
|
|
|
|
|
def update_readme_file():
|
|
|
|
"""
|
|
|
|
Wrapper around running updateReadme.py
|
|
|
|
"""
|
|
|
|
|
|
|
|
if subprocess.call([sys.executable, "updateReadme.py"]):
|
|
|
|
print_failure("Failed to update readme file")
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
parser = argparse.ArgumentParser(description="Creates custom hosts "
|
|
|
|
"file from hosts stored in "
|
|
|
|
"data subfolders.")
|
|
|
|
parser.parse_args()
|
|
|
|
|
2017-08-20 18:00:19 +02:00
|
|
|
update_hosts_file("-a", "-o",
|
2017-05-21 20:02:34 +02:00
|
|
|
"alternates/gambling",
|
|
|
|
"-e", "gambling")
|
2017-08-20 18:00:19 +02:00
|
|
|
update_hosts_file("-a", "-n", "-o",
|
2017-05-21 20:02:34 +02:00
|
|
|
"alternates/porn",
|
|
|
|
"-e", "porn")
|
2017-08-20 18:00:19 +02:00
|
|
|
update_hosts_file("-a", "-n", "-o",
|
2017-05-21 20:02:34 +02:00
|
|
|
"alternates/social",
|
|
|
|
"-e", "social")
|
2017-08-20 18:00:19 +02:00
|
|
|
update_hosts_file("-a", "-n", "-o",
|
2017-05-21 20:02:34 +02:00
|
|
|
"alternates/fakenews",
|
|
|
|
"-e", "fakenews")
|
|
|
|
|
2017-08-20 18:00:19 +02:00
|
|
|
update_hosts_file("-a", "-n", "-o",
|
2017-05-21 20:02:34 +02:00
|
|
|
"alternates/fakenews-gambling",
|
|
|
|
"-e", "fakenews", "gambling")
|
2017-08-20 18:00:19 +02:00
|
|
|
update_hosts_file("-a", "-n", "-o",
|
2017-05-21 20:02:34 +02:00
|
|
|
"alternates/fakenews-porn",
|
|
|
|
"-e", "fakenews", "porn")
|
2017-08-20 18:00:19 +02:00
|
|
|
update_hosts_file("-a", "-n", "-o",
|
2017-05-21 20:02:34 +02:00
|
|
|
"alternates/fakenews-social",
|
|
|
|
"-e", "fakenews", "social")
|
2017-08-20 18:00:19 +02:00
|
|
|
update_hosts_file("-a", "-n", "-o",
|
2017-05-21 20:02:34 +02:00
|
|
|
"alternates/gambling-porn",
|
|
|
|
"-e", "gambling", "porn")
|
2017-08-20 18:00:19 +02:00
|
|
|
update_hosts_file("-a", "-n", "-o",
|
2017-05-21 20:02:34 +02:00
|
|
|
"alternates/gambling-social",
|
|
|
|
"-e", "gambling", "social")
|
2017-08-20 18:00:19 +02:00
|
|
|
update_hosts_file("-a", "-n", "-o",
|
2017-05-21 20:02:34 +02:00
|
|
|
"alternates/porn-social",
|
|
|
|
"-e", "porn", "social")
|
|
|
|
|
2017-08-20 18:00:19 +02:00
|
|
|
update_hosts_file("-a", "-n", "-o",
|
2017-05-21 20:02:34 +02:00
|
|
|
"alternates/fakenews-gambling-porn",
|
|
|
|
"-e", "fakenews", "gambling", "porn")
|
2017-08-20 18:00:19 +02:00
|
|
|
update_hosts_file("-a", "-n", "-o",
|
2017-05-21 20:02:34 +02:00
|
|
|
"alternates/fakenews-gambling-social",
|
|
|
|
"-e", "fakenews", "gambling", "social")
|
2017-08-20 18:00:19 +02:00
|
|
|
update_hosts_file("-a", "-n", "-o",
|
2017-05-21 20:02:34 +02:00
|
|
|
"alternates/fakenews-porn-social",
|
|
|
|
"-e", "fakenews", "porn", "social")
|
2017-08-20 18:00:19 +02:00
|
|
|
update_hosts_file("-a", "-n", "-o",
|
2017-05-21 20:02:34 +02:00
|
|
|
"alternates/gambling-porn-social",
|
|
|
|
"-e", "gambling", "porn", "social")
|
|
|
|
|
2017-08-20 18:00:19 +02:00
|
|
|
update_hosts_file("-a", "-n", "-o",
|
2017-05-21 20:02:34 +02:00
|
|
|
"alternates/fakenews-gambling-porn-social",
|
|
|
|
"-e", "fakenews", "gambling", "porn", "social")
|
|
|
|
|
2017-08-20 18:00:19 +02:00
|
|
|
update_hosts_file("-a", "-n")
|
2017-05-21 20:02:34 +02:00
|
|
|
|
|
|
|
# Update the readme files.
|
|
|
|
update_readme_file()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|