wip
This commit is contained in:
parent
f939933a7c
commit
be6f7cfcbb
35 changed files with 1897 additions and 733 deletions
63
scripts/cleanup.py
Executable file
63
scripts/cleanup.py
Executable file
|
@ -0,0 +1,63 @@
|
|||
#!/usr/bin/env python3
|
||||
"""
|
||||
Cleanup script for Flask applications
|
||||
Removes __pycache__ directories, .pyc files, and database files
|
||||
"""
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import argparse
|
||||
|
||||
def cleanup(directory, verbose=False):
|
||||
"""Clean up cache files and database files"""
|
||||
cleaned_dirs = 0
|
||||
cleaned_files = 0
|
||||
|
||||
# Files to clean
|
||||
file_patterns = ['.pyc', '.pyo', '.~', '.swp', '.swo']
|
||||
db_patterns = ['.db', '.sqlite', '.sqlite3', '-journal']
|
||||
|
||||
# Directories to clean
|
||||
dir_patterns = ['__pycache__', '.pytest_cache', '.coverage', 'htmlcov']
|
||||
|
||||
# Clean main directory
|
||||
for root, dirs, files in os.walk(directory):
|
||||
# Clean directories
|
||||
for dir_name in list(dirs):
|
||||
if dir_name in dir_patterns:
|
||||
dir_path = os.path.join(root, dir_name)
|
||||
if verbose:
|
||||
print(f"Removing directory: {dir_path}")
|
||||
shutil.rmtree(dir_path)
|
||||
cleaned_dirs += 1
|
||||
dirs.remove(dir_name)
|
||||
|
||||
# Clean files
|
||||
for file in files:
|
||||
if any(file.endswith(pattern) for pattern in file_patterns + db_patterns):
|
||||
file_path = os.path.join(root, file)
|
||||
if verbose:
|
||||
print(f"Removing file: {file_path}")
|
||||
os.remove(file_path)
|
||||
cleaned_files += 1
|
||||
|
||||
# Clean instance directory
|
||||
instance_dir = os.path.join(directory, 'instance')
|
||||
if os.path.exists(instance_dir):
|
||||
for file in os.listdir(instance_dir):
|
||||
if any(file.endswith(pattern) for pattern in db_patterns):
|
||||
file_path = os.path.join(instance_dir, file)
|
||||
if verbose:
|
||||
print(f"Removing database file: {file_path}")
|
||||
os.remove(file_path)
|
||||
cleaned_files += 1
|
||||
|
||||
print(f"Cleanup completed! Removed {cleaned_dirs} directories and {cleaned_files} files.")
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description="Clean up Flask application cache and database files")
|
||||
parser.add_argument("-v", "--verbose", action="store_true", help="Show detailed output")
|
||||
parser.add_argument("-d", "--directory", default=".", help="Directory to clean (default: current directory)")
|
||||
|
||||
args = parser.parse_args()
|
||||
cleanup(args.directory, args.verbose)
|
Loading…
Add table
Add a link
Reference in a new issue