Path: blob/master/tests/sherlock_interactives.py
761 views
import os1import platform2import re3import subprocess45class Interactives:6def run_cli(args:str = "") -> str:7"""Pass arguments to Sherlock as a normal user on the command line"""8# Adapt for platform differences (Windows likes to be special)9if platform.system() == "Windows":10command:str = f"py -m sherlock_project {args}"11else:12command:str = f"sherlock {args}"1314proc_out:str = ""15try:16proc_out = subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT)17return proc_out.decode()18except subprocess.CalledProcessError as e:19raise InteractivesSubprocessError(e.output.decode())202122def walk_sherlock_for_files_with(pattern: str) -> list[str]:23"""Check all files within the Sherlock package for matching patterns"""24pattern:re.Pattern = re.compile(pattern)25matching_files:list[str] = []26for root, dirs, files in os.walk("sherlock_project"):27for file in files:28file_path = os.path.join(root,file)29if "__pycache__" in file_path:30continue31with open(file_path, 'r', errors='ignore') as f:32if pattern.search(f.read()):33matching_files.append(file_path)34return matching_files3536class InteractivesSubprocessError(Exception):37pass383940