Removed more superfluous parens.

This commit is contained in:
Steven Black 2016-02-07 19:32:00 -05:00
parent eb00a6ca08
commit 708d5a9dad

View File

@ -248,7 +248,7 @@ def removeDupsAndExcl(mergeFile):
continue continue
hostname, normalizedRule = normalizeRule(strippedRule) # normalize rule hostname, normalizedRule = normalizeRule(strippedRule) # normalize rule
for exclude in EXCLUSIONS: for exclude in EXCLUSIONS:
if (exclude in line): if exclude in line:
write = 'false' write = 'false'
break break
if normalizedRule and (hostname not in hostnames) and (write == 'true'): if normalizedRule and (hostname not in hostnames) and (write == 'true'):
@ -281,7 +281,7 @@ def finalizeFile(finalFile):
# the comments are preserved in the output hosts file # the comments are preserved in the output hosts file
def stripRule(line): def stripRule(line):
splitLine = line.split() splitLine = line.split()
if (len(splitLine) < 2) : if len(splitLine) < 2 :
# just return blank # just return blank
return '' return ''
else: else:
@ -314,22 +314,22 @@ def updateReadme(numberOfRules):
out.write(line.replace('@NUM_ENTRIES@', "{:,}".format(numberOfRules))) out.write(line.replace('@NUM_ENTRIES@', "{:,}".format(numberOfRules)))
def moveHostsFileIntoPlace(finalFile): def moveHostsFileIntoPlace(finalFile):
if (os.name == 'posix'): if os.name == 'posix':
print ('Moving the file requires administrative privileges. You might need to enter your password.') print ('Moving the file requires administrative privileges. You might need to enter your password.')
if(subprocess.call(["/usr/bin/sudo", "cp", os.path.abspath(finalFile.name), "/etc/hosts"])): if subprocess.call(["/usr/bin/sudo", "cp", os.path.abspath(finalFile.name), "/etc/hosts"]):
printFailure("Moving the file failed.") printFailure("Moving the file failed.")
print ('Flushing the DNS Cache to utilize new hosts file...') print ('Flushing the DNS Cache to utilize new hosts file...')
if (platform.system() == 'Darwin'): if platform.system() == 'Darwin':
if(subprocess.call(["/usr/bin/sudo", "killall", "-HUP", "mDNSResponder"])): if subprocess.call(["/usr/bin/sudo", "killall", "-HUP", "mDNSResponder"]):
printFailure("Flushing the DNS Cache failed.") printFailure("Flushing the DNS Cache failed.")
else: else:
if os.path.isfile("/etc/rc.d/init.d/nscd"): if os.path.isfile("/etc/rc.d/init.d/nscd"):
if(subprocess.call(["/usr/bin/sudo", "/etc/rc.d/init.d/nscd", "restart"])): if subprocess.call(["/usr/bin/sudo", "/etc/rc.d/init.d/nscd", "restart"]):
printFailure("Flushing the DNS Cache failed.") printFailure("Flushing the DNS Cache failed.")
if os.path.isfile("/usr/lib/systemd/system/NetworkManager.service"): if os.path.isfile("/usr/lib/systemd/system/NetworkManager.service"):
if(subprocess.call(["/usr/bin/sudo", "/usr/bin/systemctl", "restart", "NetworkManager.service"])): if subprocess.call(["/usr/bin/sudo", "/usr/bin/systemctl", "restart", "NetworkManager.service"]):
printFailure("Flushing the DNS Cache failed.") printFailure("Flushing the DNS Cache failed.")
elif (os.name == 'nt'): elif os.name == 'nt':
print ('Automatically moving the hosts file in place is not yet supported.') print ('Automatically moving the hosts file in place is not yet supported.')
print ('Please move the generated file to %SystemRoot%\system32\drivers\etc\hosts') print ('Please move the generated file to %SystemRoot%\system32\drivers\etc\hosts')
@ -378,11 +378,11 @@ def query_yes_no(question, default = "yes"):
## end of http://code.activestate.com/recipes/577058/ }}} ## end of http://code.activestate.com/recipes/577058/ }}}
def isValidDomainFormat(domain): def isValidDomainFormat(domain):
if (domain == ''): if domain == '':
print ("You didn\'t enter a domain. Try again.") print ("You didn\'t enter a domain. Try again.")
return False return False
domainRegex = re.compile("www\d{0,3}[.]|https?") domainRegex = re.compile("www\d{0,3}[.]|https?")
if (domainRegex.match(domain)): if domainRegex.match(domain):
print ("The domain " + domain + " is not valid. Do not include www.domain.com or http(s)://domain.com. Try again.") print ("The domain " + domain + " is not valid. Do not include www.domain.com or http(s)://domain.com. Try again.")
return False return False
else: else: