Create makeHosts file in Python
authorgfyoung <redacted>
Sun, 21 May 2017 18:02:34 +0000 (14:02 -0400)
committergfyoung <redacted>
Mon, 22 May 2017 02:30:36 +0000 (22:30 -0400)
Closes gh-316.

makeHosts [deleted file]
makeHosts.py [new file with mode: 0644]
makeHostsWindows.bat [deleted file]

diff --git a/makeHosts b/makeHosts
deleted file mode 100755 (executable)
index 35a937d..0000000
--- a/makeHosts
+++ /dev/null
@@ -1,26 +0,0 @@
-#!/bin/sh
-
-# These create various alternate hosts files by combining and adding the gambling, porn, and social media extensions.
-python updateHostsFile.py -a -z    -o alternates/gambling -e gambling
-python updateHostsFile.py -a -z -n -o alternates/porn -e porn
-python updateHostsFile.py -a -z -n -o alternates/social -e social
-python updateHostsFile.py -a -z -n -o alternates/fakenews -e fakenews
-
-python updateHostsFile.py -a -z -n -o alternates/fakenews-gambling -e fakenews gambling
-python updateHostsFile.py -a -z -n -o alternates/fakenews-porn -e fakenews porn
-python updateHostsFile.py -a -z -n -o alternates/fakenews-social -e fakenews social
-python updateHostsFile.py -a -z -n -o alternates/gambling-porn -e gambling porn
-python updateHostsFile.py -a -z -n -o alternates/gambling-social -e gambling social
-python updateHostsFile.py -a -z -n -o alternates/porn-social -e porn social
-
-python updateHostsFile.py -a -z -n -o alternates/fakenews-gambling-porn -e fakenews gambling porn
-python updateHostsFile.py -a -z -n -o alternates/fakenews-gambling-social -e fakenews gambling social
-python updateHostsFile.py -a -z -n -o alternates/fakenews-porn-social -e fakenews porn social
-python updateHostsFile.py -a -z -n -o alternates/gambling-porn-social -e gambling porn social
-
-python updateHostsFile.py -a -z -n -o alternates/fakenews-gambling-porn-social -e fakenews gambling porn social
-
-python updateHostsFile.py -a -z -n
-
-# Update the README's.
-python updateReadme.py
diff --git a/makeHosts.py b/makeHosts.py
new file mode 100644 (file)
index 0000000..5b44b24
--- /dev/null
@@ -0,0 +1,118 @@
+#!/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()
+
+    update_hosts_file("-a", "-z", "-o",
+                      "alternates/gambling",
+                      "-e", "gambling")
+    update_hosts_file("-a", "-z", "-n", "-o",
+                      "alternates/porn",
+                      "-e", "porn")
+    update_hosts_file("-a", "-z", "-n", "-o",
+                      "alternates/social",
+                      "-e", "social")
+    update_hosts_file("-a", "-z", "-n", "-o",
+                      "alternates/fakenews",
+                      "-e", "fakenews")
+
+    update_hosts_file("-a", "-z", "-n", "-o",
+                      "alternates/fakenews-gambling",
+                      "-e", "fakenews", "gambling")
+    update_hosts_file("-a", "-z", "-n", "-o",
+                      "alternates/fakenews-porn",
+                      "-e", "fakenews", "porn")
+    update_hosts_file("-a", "-z", "-n", "-o",
+                      "alternates/fakenews-social",
+                      "-e", "fakenews", "social")
+    update_hosts_file("-a", "-z", "-n", "-o",
+                      "alternates/gambling-porn",
+                      "-e", "gambling", "porn")
+    update_hosts_file("-a", "-z", "-n", "-o",
+                      "alternates/gambling-social",
+                      "-e", "gambling", "social")
+    update_hosts_file("-a", "-z", "-n", "-o",
+                      "alternates/porn-social",
+                      "-e", "porn", "social")
+
+    update_hosts_file("-a", "-z", "-n", "-o",
+                      "alternates/fakenews-gambling-porn",
+                      "-e", "fakenews", "gambling", "porn")
+    update_hosts_file("-a", "-z", "-n", "-o",
+                      "alternates/fakenews-gambling-social",
+                      "-e", "fakenews", "gambling", "social")
+    update_hosts_file("-a", "-z", "-n", "-o",
+                      "alternates/fakenews-porn-social",
+                      "-e", "fakenews", "porn", "social")
+    update_hosts_file("-a", "-z", "-n", "-o",
+                      "alternates/gambling-porn-social",
+                      "-e", "gambling", "porn", "social")
+
+    update_hosts_file("-a", "-z", "-n", "-o",
+                      "alternates/fakenews-gambling-porn-social",
+                      "-e", "fakenews", "gambling", "porn", "social")
+
+    update_hosts_file("-a", "-z", "-n")
+
+    # Update the readme files.
+    update_readme_file()
+
+
+if __name__ == "__main__":
+    main()
diff --git a/makeHostsWindows.bat b/makeHostsWindows.bat
deleted file mode 100644 (file)
index 85d51f3..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-@ECHO OFF
-TITLE Make Hosts
-
-:: These create various alternate hosts files by combining and adding the gambling, porn, and social media extensions.
-python updateHostsFile.py -a -z    -o alternates/gambling -e gambling
-python updateHostsFile.py -a -z -n -o alternates/porn -e porn
-python updateHostsFile.py -a -z -n -o alternates/social -e social
-python updateHostsFile.py -a -z -n -o alternates/fakenews -e fakenews
-
-python updateHostsFile.py -a -z -n -o alternates/fakenews-gambling -e fakenews gambling
-python updateHostsFile.py -a -z -n -o alternates/fakenews-porn -e fakenews porn
-python updateHostsFile.py -a -z -n -o alternates/fakenews-social -e fakenews social
-python updateHostsFile.py -a -z -n -o alternates/gambling-porn -e gambling porn
-python updateHostsFile.py -a -z -n -o alternates/gambling-social -e gambling social
-python updateHostsFile.py -a -z -n -o alternates/porn-social -e porn social
-
-python updateHostsFile.py -a -z -n -o alternates/fakenews-gambling-porn -e fakenews gambling porn
-python updateHostsFile.py -a -z -n -o alternates/fakenews-gambling-social -e fakenews gambling social
-python updateHostsFile.py -a -z -n -o alternates/fakenews-porn-social -e fakenews porn social
-python updateHostsFile.py -a -z -n -o alternates/gambling-porn-social -e gambling porn social
-
-python updateHostsFile.py -a -z -n -o alternates/fakenews-gambling-porn-social -e fakenews gambling porn social
-
-python updateHostsFile.py -a -z -n
-
-::Update the README's.
-python updateReadme.py
git clone https://git.99rst.org/PROJECT