fix: bonehead on lowercase and list to use

master
pegasust 2024-10-04 01:44:43 -07:00
parent 62794fcf07
commit 16a527180b
1 changed files with 6 additions and 3 deletions

View File

@ -3,6 +3,7 @@
import pathlib import pathlib
import os import os
import time import time
import sys
def in_content(needle: str, pathlike: str): def in_content(needle: str, pathlike: str):
content = "" content = ""
@ -17,13 +18,14 @@ def in_content(needle: str, pathlike: str):
def gitignore_patterns(gitignore_f: str | None = None): def gitignore_patterns(gitignore_f: str | None = None):
with open(gitignore_f, 'r') as f: with open(gitignore_f, 'r') as f:
return [line for line in (line.strip() for line in f) if not line.startswith('#') and line] return {line for line in (line.strip() for line in f) if not line.startswith('#') and line}
def main(): def main():
begin_stopwatch_s = time.perf_counter() begin_stopwatch_s = time.perf_counter()
# if OSError, too bad, user probably knows why, so just throw xD # if OSError, too bad, user probably knows why, so just throw xD
username = os.getlogin() username = os.getlogin()
ignore_patterns = gitignore_patterns(os.getenv("IGNORE_FILE", ".gitignore")) ignore_patterns = gitignore_patterns(os.getenv("IGNORE_FILE", ".gitignore"))
ignore_patterns.add(".git")
print(f"{ignore_patterns=}") print(f"{ignore_patterns=}")
# NB: impure pattern due to walk being costly # NB: impure pattern due to walk being costly
@ -51,15 +53,16 @@ def main():
username_in_content.extend( username_in_content.extend(
absfname absfname
for absfname, _ in files for absfname, _ in files
if in_content(username, absfname) if in_content(user_lower, absfname)
) )
print(f"Checked batch {[rel for _, rel in files + absdirs]} in {root}", file=sys.stderr)
nl = "\n" nl = "\n"
if username_in_file != []: if username_in_file != []:
print(f"Doxxed by username in file path:\n{nl.join(f'- {e}' for e in username_in_file)}") print(f"Doxxed by username in file path:\n{nl.join(f'- {e}' for e in username_in_file)}")
if username_in_content != []: if username_in_content != []:
print(f"Doxxed by username in file content:\n{nl.join(f'- {e}' for e in username_in_file)}") print(f"Doxxed by username in file content:\n{nl.join(f'- {e}' for e in username_in_content)}")
stop_stopwatch_s = time.perf_counter() stop_stopwatch_s = time.perf_counter()
print(f"done analyzing in {(stop_stopwatch_s - begin_stopwatch_s):.04}s") print(f"done analyzing in {(stop_stopwatch_s - begin_stopwatch_s):.04}s")