mirror of
https://github.com/StevenBlack/hosts.git
synced 2024-07-04 03:26:12 +02:00
Nor update the readmeData.json file for each build.
This commit is contained in:
parent
f20db8c410
commit
97fba05f22
|
@ -24,6 +24,7 @@ import time
|
||||||
import glob
|
import glob
|
||||||
import argparse
|
import argparse
|
||||||
import socket
|
import socket
|
||||||
|
import json
|
||||||
# zip files are not used actually, support deleted
|
# zip files are not used actually, support deleted
|
||||||
# StringIO is not needed in Python 3
|
# StringIO is not needed in Python 3
|
||||||
# Python 3 works differently with urlopen
|
# Python 3 works differently with urlopen
|
||||||
|
@ -71,16 +72,17 @@ def listdir_nohidden(path):
|
||||||
return glob.glob(os.path.join(path, '*'))
|
return glob.glob(os.path.join(path, '*'))
|
||||||
|
|
||||||
# Project Settings
|
# Project Settings
|
||||||
BASEDIR_PATH = os.path.dirname(os.path.realpath(__file__))
|
BASEDIR_PATH = os.path.dirname(os.path.realpath(__file__))
|
||||||
DATA_PATH = os.path.join(BASEDIR_PATH, 'data')
|
DATA_PATH = os.path.join(BASEDIR_PATH, 'data')
|
||||||
EXTENSIONS_PATH = os.path.join(BASEDIR_PATH, 'extensions')
|
EXTENSIONS_PATH = os.path.join(BASEDIR_PATH, 'extensions')
|
||||||
DATA_FILENAMES = 'hosts'
|
DATA_FILENAMES = 'hosts'
|
||||||
UPDATE_URL_FILENAME = 'update.info'
|
UPDATE_URL_FILENAME = 'update.info'
|
||||||
SOURCES = listdir_nohidden(DATA_PATH)
|
SOURCES = listdir_nohidden(DATA_PATH)
|
||||||
EXTENSIONS = listdir_nohidden(EXTENSIONS_PATH)
|
EXTENSIONS = listdir_nohidden(EXTENSIONS_PATH)
|
||||||
README_TEMPLATE = os.path.join(BASEDIR_PATH, 'readme_template.md')
|
README_TEMPLATE = os.path.join(BASEDIR_PATH, 'readme_template.md')
|
||||||
README_FILENAME = 'readme.md'
|
README_FILENAME = 'readme.md'
|
||||||
WHITELIST_FILE = os.path.join(BASEDIR_PATH, 'whitelist')
|
WHITELIST_FILE = os.path.join(BASEDIR_PATH, 'whitelist')
|
||||||
|
README_DATA_FILENAME = "readmeData.json"
|
||||||
|
|
||||||
# Exclusions
|
# Exclusions
|
||||||
EXCLUSION_PATTERN = '([a-zA-Z\d-]+\.){0,}' #append domain the end
|
EXCLUSION_PATTERN = '([a-zA-Z\d-]+\.){0,}' #append domain the end
|
||||||
|
@ -108,10 +110,9 @@ def main():
|
||||||
parser.add_argument("--output", "-o", dest="outputSubFolder", default="", help="Output subfolder for generated hosts file.")
|
parser.add_argument("--output", "-o", dest="outputSubFolder", default="", help="Output subfolder for generated hosts file.")
|
||||||
parser.add_argument("--noupdate", "-n", dest="noUpdate", default=False, action='store_true', help="Don't update from host data sources.")
|
parser.add_argument("--noupdate", "-n", dest="noUpdate", default=False, action='store_true', help="Don't update from host data sources.")
|
||||||
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
global auto, update, replace, targetIP, replace, extensions, outputPath
|
global auto, update, replace, targetIP, replace, extensions, outputPath, readmeData
|
||||||
auto = args.auto
|
auto = args.auto
|
||||||
replace = args.replace
|
replace = args.replace
|
||||||
targetIP = args.targetIP
|
targetIP = args.targetIP
|
||||||
|
@ -123,13 +124,17 @@ def main():
|
||||||
# ... intersected with the extensions passed-in as arguments, then sorted.
|
# ... intersected with the extensions passed-in as arguments, then sorted.
|
||||||
extensions = sorted( list(set(args.extensions).intersection(extensions)) )
|
extensions = sorted( list(set(args.extensions).intersection(extensions)) )
|
||||||
|
|
||||||
|
with open(README_DATA_FILENAME, 'r') as f:
|
||||||
|
readmeData = json.load(f)
|
||||||
|
|
||||||
promptForUpdate()
|
promptForUpdate()
|
||||||
promptForExclusions()
|
promptForExclusions()
|
||||||
mergeFile = createInitialFile()
|
mergeFile = createInitialFile()
|
||||||
removeOldHostsFile()
|
removeOldHostsFile()
|
||||||
finalFile = removeDupsAndExcl(mergeFile)
|
finalFile = removeDupsAndExcl(mergeFile)
|
||||||
finalizeFile(finalFile)
|
finalizeFile(finalFile)
|
||||||
updateReadme(numberOfRules)
|
# updateReadme(numberOfRules)
|
||||||
|
updateReadmeData(numberOfRules)
|
||||||
printSuccess('Success! The hosts file has been saved in folder\n' + outputPath + '\nIt contains ' +
|
printSuccess('Success! The hosts file has been saved in folder\n' + outputPath + '\nIt contains ' +
|
||||||
"{:,}".format(numberOfRules) + ' unique entries.')
|
"{:,}".format(numberOfRules) + ' unique entries.')
|
||||||
|
|
||||||
|
@ -379,7 +384,7 @@ def writeOpeningHeader(finalFile):
|
||||||
writeData(finalFile, '\n')
|
writeData(finalFile, '\n')
|
||||||
writeData(finalFile, '127.0.0.1 localhost\n')
|
writeData(finalFile, '127.0.0.1 localhost\n')
|
||||||
writeData(finalFile, '127.0.0.1 localhost.localdomain\n')
|
writeData(finalFile, '127.0.0.1 localhost.localdomain\n')
|
||||||
writeData(finalFile, '127.0.0.1 local\n')
|
writeData(finalFile, '127.a0.0.1 local\n')
|
||||||
writeData(finalFile, '255.255.255.255 broadcasthost\n')
|
writeData(finalFile, '255.255.255.255 broadcasthost\n')
|
||||||
writeData(finalFile, '::1 localhost\n')
|
writeData(finalFile, '::1 localhost\n')
|
||||||
writeData(finalFile, 'fe80::1%lo0 localhost\n')
|
writeData(finalFile, 'fe80::1%lo0 localhost\n')
|
||||||
|
@ -394,12 +399,26 @@ def writeOpeningHeader(finalFile):
|
||||||
|
|
||||||
finalFile.write(fileContents)
|
finalFile.write(fileContents)
|
||||||
|
|
||||||
|
def updateReadmeData(numberOfRules):
|
||||||
|
extensionsKey = "base"
|
||||||
|
hostsLocation = ""
|
||||||
|
if extensions:
|
||||||
|
extensionsKey = "-".join(extensions)
|
||||||
|
|
||||||
|
generationData = {}
|
||||||
|
generationData["location"] = outputPath
|
||||||
|
generationData["entries"] = numberOfRules
|
||||||
|
|
||||||
|
readmeData[extensionsKey] = generationData
|
||||||
|
with open(README_DATA_FILENAME, 'w') as f:
|
||||||
|
json.dump(readmeData, f)
|
||||||
|
|
||||||
def updateReadme(numberOfRules):
|
def updateReadme(numberOfRules):
|
||||||
extensionsStr = "* Extensions: **none**."
|
extensionsStr = "* Extensions: **none**."
|
||||||
extensionsHeader = ""
|
extensionsHeader = ""
|
||||||
if extensions:
|
if extensions:
|
||||||
extensionsStr = "* Extensions: **" + ", ".join(extensions) + "**."
|
extensionsStr = "* Extensions: **" + ", ".join(extensions) + "**."
|
||||||
extensionsHeader = "with "+ ", ".join(extensions) + " extensions"
|
extensionsHeader = "with "+ ", ".join(extensions) + " extensions"
|
||||||
|
|
||||||
with open(os.path.join(outputPath,README_FILENAME), "wt") as out:
|
with open(os.path.join(outputPath,README_FILENAME), "wt") as out:
|
||||||
for line in open(README_TEMPLATE):
|
for line in open(README_TEMPLATE):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user