From: Steven Black Date: Thu, 11 Feb 2016 03:35:09 +0000 (-0500) Subject: Import argparse, and add an --auto flag to run the update and merge with no prompts. X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=1eb1509e419ac5a9c5207769bb9136285dcc43a8;p=stevenblack-hosts.git Import argparse, and add an --auto flag to run the update and merge with no prompts. --- diff --git a/updateHostsFile.py b/updateHostsFile.py index 4c1ee84ae..776fafb55 100644 --- a/updateHostsFile.py +++ b/updateHostsFile.py @@ -20,6 +20,7 @@ import subprocess import sys import tempfile import glob +import argparse # zip files are not used actually, support deleted # StringIO is not needed in Python 3 # Python 3 works differently with urlopen @@ -91,7 +92,16 @@ COMMON_EXCLUSIONS = ['hulu.com'] exclusionRegexs = [] numberOfRules = 0 +auto = False + def main(): + parser = argparse.ArgumentParser(description="Creates an amalgamated hosts file from hosts stored in data subfolders.") + parser.add_argument("--auto", "-a", dest="auto", default=False, action='store_true', help="Run without prompting.") + args = parser.parse_args() + + global auto + auto = args.auto + promptForUpdate() promptForExclusions() mergeFile = createInitialFile() @@ -113,14 +123,14 @@ def promptForUpdate(): except: printFailure("ERROR: No 'hosts' file in the folder, try creating one manually") - response = query_yes_no("Do you want to update all data sources?") + response = "yes" if auto else query_yes_no("Do you want to update all data sources?") if response == "yes": updateAllSources() else: print ("OK, we\'ll stick with what we\'ve got locally.") def promptForExclusions(): - response = query_yes_no("Do you want to exclude any domains?\n" + + response = "no" if auto else query_yes_no("Do you want to exclude any domains?\n" + "For example, hulu.com video streaming must be able to access " + "its tracking and ad servers in order to play video.") if response == "yes": @@ -136,7 +146,7 @@ def promptForMoreCustomExclusions(): return False def promptForMove(finalFile): - response = query_yes_no("Do you want to replace your existing hosts file " + + response = "no" if auto else query_yes_no("Do you want to replace your existing hosts file " + "with the newly generated file?") if response == "yes": moveHostsFileIntoPlace(finalFile)