From: Ben Limmer Date: Sun, 17 Feb 2013 21:39:40 +0000 (-0700) Subject: Resolves infinite loop error introduced in 997606b. X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=0f942662cf22c39978aec833670d41652340d00b;p=stevenblack-hosts.git Resolves infinite loop error introduced in 997606b. 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 --- diff --git a/updateHostsFile.py b/updateHostsFile.py index 7e8226b25..eb39a1508 100644 --- a/updateHostsFile.py +++ b/updateHostsFile.py @@ -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."