Resolves infinite loop error introduced in 997606b.
authorBen Limmer <redacted>
Sun, 17 Feb 2013 21:39:40 +0000 (14:39 -0700)
committerBen Limmer <redacted>
Sun, 17 Feb 2013 21:39:40 +0000 (14:39 -0700)
Whether you entered yes or no to the "more entries" dialog, you'd still be in the loop. Also, we now check to see if the custom domain is blank

updateHostsFile.py

index 7e8226b256c03357cf1e02e61f54803d55fad288..eb39a15085f9d0f9b6a4d3a9518f824762e0ddce 100644 (file)
@@ -54,6 +54,13 @@ def promptForExclusions():
                displayExclusionOptions()
        else:
                print 'OK, we won\'t exclude any domains.'
+
+def promptForMoreCustomExclusions():
+       response = query_yes_no("Do you have more domains you want to enter?")
+       if (response == "yes"):
+               return True
+       else:
+               return False
 # End Prompt the User
 
 # Exclusion logic
@@ -69,14 +76,12 @@ def displayExclusionOptions():
                gatherCustomExclusions()
 
 def gatherCustomExclusions():
-       moreEntries = True;
-       while (moreEntries):
+       while True:
                domainFromUser = raw_input("Enter the domain you want to exclude (e.g. facebook.com): ")
                if (isValidDomainFormat(domainFromUser)):
                        excludeDomain(domainFromUser)
-               response = query_yes_no("Do you have more domains you want to enter?")
-        if (response == "no"):
-               moreEntries = False
+               if (promptForMoreCustomExclusions() == False):
+                       return
 
 def excludeDomain(domain):
        exclusionRegexs.append(re.compile(EXCLUSION_PATTERN + domain))
@@ -219,6 +224,9 @@ def query_yes_no(question, default="yes"):
 ## end of http://code.activestate.com/recipes/577058/ }}}
 
 def isValidDomainFormat(domain):
+       if (domain == ''):
+               print "You didn\'t enter a domain. Try again."
+               return False
        domainRegex = re.compile("www\d{0,3}[.]|https?")
        if (domainRegex.match(domain)):
                print "The domain " + domain + " is not valid. Do not include www.domain.com or http(s)://domain.com. Try again."
git clone https://git.99rst.org/PROJECT