mirror of
https://github.com/StevenBlack/hosts.git
synced 2024-07-06 20:42:22 +02:00
First code alterations for extensions.
This is still WIP.
This commit is contained in:
parent
cdd5d9aebe
commit
40eb85a797
@ -76,6 +76,7 @@ def listdir_nohidden(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')
|
||||||
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)
|
||||||
@ -94,18 +95,25 @@ exclusionRegexs = []
|
|||||||
numberOfRules = 0
|
numberOfRules = 0
|
||||||
auto = False
|
auto = False
|
||||||
targetIP = "0.0.0.0"
|
targetIP = "0.0.0.0"
|
||||||
|
extensions = []
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description="Creates an amalgamated hosts file from hosts stored in data subfolders.")
|
parser = argparse.ArgumentParser(description="Creates an amalgamated hosts file from hosts stored in data subfolders.")
|
||||||
parser.add_argument("--auto", "-a", dest="auto", default=False, action='store_true', help="Run without prompting.")
|
parser.add_argument("--auto", "-a", dest="auto", default=False, action='store_true', help="Run without prompting.")
|
||||||
parser.add_argument("--ip", "-i", dest="targetIP", default="0.0.0.0", help="Target IP address. Default is 0.0.0.0")
|
parser.add_argument("--ip", "-i", dest="targetIP", default="0.0.0.0", help="Target IP address. Default is 0.0.0.0.")
|
||||||
|
parser.add_argument("--extensions", "-e", dest="extensions", default=[], nargs='*', help="Host extensions to include in the final hosts file.")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
global auto, targetIP
|
global auto, targetIP, extensions
|
||||||
auto = args.auto
|
auto = args.auto
|
||||||
targetIP = args.targetIP
|
targetIP = args.targetIP
|
||||||
|
|
||||||
|
# All our extensions folders...
|
||||||
|
extensions = [os.path.basename(item) for item in listdir_nohidden(EXTENSIONS_PATH)]
|
||||||
|
# ... intersected with the extensions passed-in as arguments
|
||||||
|
extensions = list(set(args.extensions).intersection(extensions))
|
||||||
|
|
||||||
promptForUpdate()
|
promptForUpdate()
|
||||||
promptForExclusions()
|
promptForExclusions()
|
||||||
mergeFile = createInitialFile()
|
mergeFile = createInitialFile()
|
||||||
@ -211,7 +219,6 @@ def updateAllSources():
|
|||||||
except:
|
except:
|
||||||
print ("Skipping.")
|
print ("Skipping.")
|
||||||
|
|
||||||
|
|
||||||
def getUpdateURLFromFile(source):
|
def getUpdateURLFromFile(source):
|
||||||
pathToUpdateFile = os.path.join(DATA_PATH, source, UPDATE_URL_FILENAME)
|
pathToUpdateFile = os.path.join(DATA_PATH, source, UPDATE_URL_FILENAME)
|
||||||
if os.path.exists(pathToUpdateFile):
|
if os.path.exists(pathToUpdateFile):
|
||||||
|
Loading…
Reference in New Issue
Block a user