Duplicate hosts are now omitted

This commit is contained in:
slashtechno 2023-08-18 20:51:00 -04:00
parent 255994447a
commit 7e98125597
Signed by: slashtechno
GPG Key ID: 8EC1D9D9286C2B17
2 changed files with 6 additions and 5 deletions

View File

@ -95,7 +95,7 @@ def main():
logger.info("No credentials provided with flags") logger.info("No credentials provided with flags")
if Path(".env").is_file(): if Path(".env").is_file():
logger.debug("Loading .env") logger.debug("Loading .env")
dotenv.load_dotenv() dotenv.load_dotenv(Path(Path.cwd() / ".env"))
else: else:
logger.debug("No .env file found") logger.debug("No .env file found")
try: try:
@ -106,7 +106,8 @@ def main():
logger.error("No credentials provided") logger.error("No credentials provided")
argparser.print_help() argparser.print_help()
exit(1) exit(1)
# For debugging, print cwd
logger.debug(f"Current working directory: {Path.cwd()}")
try: try:
args.func(args) args.func(args)
except AttributeError: except AttributeError:

View File

@ -73,13 +73,13 @@ def convert_to_list(file: pathlib.Path) -> list:
re.search(r"^(?:127\.0\.0\.1|0\.0\.0\.0|::1)\s+(.+?)(?:\s+#.+)?$", line) re.search(r"^(?:127\.0\.0\.1|0\.0\.0\.0|::1)\s+(.+?)(?:\s+#.+)?$", line)
for line in f for line in f
] ]
hosts = [ hosts = {
match.group(1) match.group(1)
for match in matches for match in matches
if match and match.group(1) not in loopback if match and match.group(1) not in loopback
] }
# print(f"First 5 hosts: {hosts[:5]}") # print(f"First 5 hosts: {hosts[:5]}")
return hosts return list(hosts)
# General Utils # General Utils