INV / scripts /emergency_token_cleanup.py
Fred808's picture
Upload 256 files
7a0c684 verified
"""
Emergency token cleanup script - removes all instances of HF token from all files
"""
import os
from pathlib import Path
import re
def find_all_files(start_path: str) -> list[Path]:
"""Find all files in the directory tree."""
all_files = []
for root, _, files in os.walk(start_path):
if 'venv' in root or '__pycache__' in root or '.git' in root:
continue
for file in files:
all_files.append(Path(os.path.join(root, file)))
return all_files
def clean_token_from_file(file_path: Path, token: str) -> bool:
"""Remove token from a file."""
try:
with open(file_path, 'r', encoding='utf-8') as f:
content = f.read()
if token not in content:
return False
print(f"Cleaning {file_path}")
# Replace the token
content = content.replace(token, 'your_token_here')
with open(file_path, 'w', encoding='utf-8') as f:
f.write(content)
return True
except Exception as e:
print(f"Error processing {file_path}: {e}")
return False
def main():
"""Main cleanup function."""
# Token to remove
TOKEN = 'your_token_here'
# Get project root
root_dir = Path(__file__).parent.parent
# Find all files
all_files = find_all_files(root_dir)
# Clean files
cleaned = 0
for file_path in all_files:
if clean_token_from_file(file_path, TOKEN):
cleaned += 1
print(f"\nCleaned token from {cleaned} files")
print("\nNext steps:")
print("1. Update .env with your actual token")
print("2. Make sure .env is in .gitignore")
print("3. Commit the changes")
if __name__ == '__main__':
main()