mirror of
https://github.com/StevenBlack/hosts.git
synced 2026-07-01 02:36:52 +00:00
@@ -36,7 +36,7 @@ def main():
|
|||||||
mergeFile = createInitialFile()
|
mergeFile = createInitialFile()
|
||||||
finalFile = removeDups(mergeFile)
|
finalFile = removeDups(mergeFile)
|
||||||
finalizeFile(finalFile)
|
finalizeFile(finalFile)
|
||||||
print 'Success! Your shiny new hosts file has been prepared.'
|
printSuccess('Success! Your shiny new hosts file has been prepared.')
|
||||||
|
|
||||||
# Prompt the User
|
# Prompt the User
|
||||||
def promptForUpdate():
|
def promptForUpdate():
|
||||||
@@ -117,8 +117,8 @@ def getUpdateURLFromFile(source):
|
|||||||
updateFile.close()
|
updateFile.close()
|
||||||
else:
|
else:
|
||||||
retURL = None
|
retURL = None
|
||||||
print 'Warning: Can\'t find the update file for source ' + source
|
printFailure('Warning: Can\'t find the update file for source ' + source + '\n' +
|
||||||
print 'Make sure that there\'s a file at ' + pathToUpdateFile
|
'Make sure that there\'s a file at ' + pathToUpdateFile)
|
||||||
return retURL
|
return retURL
|
||||||
# End Update Logic
|
# End Update Logic
|
||||||
|
|
||||||
@@ -153,7 +153,7 @@ def removeDups(mergeFile):
|
|||||||
|
|
||||||
mergeFile.close()
|
mergeFile.close()
|
||||||
|
|
||||||
print 'Removed ' + str(duplicatesRemoved) + ' duplicates from the merged file'
|
printSuccess('Removed ' + str(duplicatesRemoved) + ' duplicates from the merged file')
|
||||||
return finalFile
|
return finalFile
|
||||||
|
|
||||||
def finalizeFile(finalFile):
|
def finalizeFile(finalFile):
|
||||||
@@ -165,8 +165,8 @@ def finalizeFile(finalFile):
|
|||||||
def stripRule(line):
|
def stripRule(line):
|
||||||
splitLine = line.split()
|
splitLine = line.split()
|
||||||
if (len(splitLine) < 2) :
|
if (len(splitLine) < 2) :
|
||||||
print 'A line in the hostfile is going to cause problems because it is nonstandard'
|
printFailure('A line in the hostfile is going to cause problems because it is nonstandard\n' +
|
||||||
print 'The line reads ' + line + ' please check your data files. Maybe you have a comment without a #?'
|
'The line reads ' + line + ' please check your data files. Maybe you have a comment without a #?')
|
||||||
sys.exit()
|
sys.exit()
|
||||||
return splitLine[0] + ' ' + splitLine[1]
|
return splitLine[0] + ' ' + splitLine[1]
|
||||||
|
|
||||||
@@ -212,14 +212,14 @@ def query_yes_no(question, default="yes"):
|
|||||||
raise ValueError("invalid default answer: '%s'" % default)
|
raise ValueError("invalid default answer: '%s'" % default)
|
||||||
|
|
||||||
while 1:
|
while 1:
|
||||||
sys.stdout.write(question + prompt)
|
sys.stdout.write(colorize(question, colors.PROMPT) + prompt)
|
||||||
choice = raw_input().lower()
|
choice = raw_input().lower()
|
||||||
if default is not None and choice == '':
|
if default is not None and choice == '':
|
||||||
return default
|
return default
|
||||||
elif choice in valid.keys():
|
elif choice in valid.keys():
|
||||||
return valid[choice]
|
return valid[choice]
|
||||||
else:
|
else:
|
||||||
sys.stdout.write("Please respond with 'yes' or 'no' "\
|
printFailure("Please respond with 'yes' or 'no' "\
|
||||||
"(or 'y' or 'n').\n")
|
"(or 'y' or 'n').\n")
|
||||||
## end of http://code.activestate.com/recipes/577058/ }}}
|
## end of http://code.activestate.com/recipes/577058/ }}}
|
||||||
|
|
||||||
@@ -233,6 +233,22 @@ def isValidDomainFormat(domain):
|
|||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
# Colors
|
||||||
|
class colors:
|
||||||
|
PROMPT = '\033[94m'
|
||||||
|
SUCCESS = '\033[92m'
|
||||||
|
FAIL = '\033[91m'
|
||||||
|
ENDC = '\033[0m'
|
||||||
|
|
||||||
|
def colorize(text, color):
|
||||||
|
return color + text + colors.ENDC
|
||||||
|
|
||||||
|
def printSuccess(text):
|
||||||
|
print colorize(text, colors.SUCCESS)
|
||||||
|
|
||||||
|
def printFailure(text):
|
||||||
|
print colorize(text, colors.FAIL)
|
||||||
# End Helper Functions
|
# End Helper Functions
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user