wip
This commit is contained in:
parent
3b2f1db4ce
commit
5c16964b76
47 changed files with 2080 additions and 1053 deletions
|
@ -8,18 +8,19 @@ 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']
|
||||
|
||||
file_patterns = [".pyc", ".pyo", ".~", ".swp", ".swo"]
|
||||
db_patterns = [".db", ".sqlite", ".sqlite3", "-journal"]
|
||||
|
||||
# Directories to clean
|
||||
dir_patterns = ['__pycache__', '.pytest_cache', '.coverage', 'htmlcov']
|
||||
|
||||
dir_patterns = ["__pycache__", ".pytest_cache", ".coverage", "htmlcov"]
|
||||
|
||||
# Clean main directory
|
||||
for root, dirs, files in os.walk(directory):
|
||||
# Clean directories
|
||||
|
@ -31,7 +32,7 @@ def cleanup(directory, verbose=False):
|
|||
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):
|
||||
|
@ -40,9 +41,9 @@ def cleanup(directory, verbose=False):
|
|||
print(f"Removing file: {file_path}")
|
||||
os.remove(file_path)
|
||||
cleaned_files += 1
|
||||
|
||||
|
||||
# Clean instance directory
|
||||
instance_dir = os.path.join(directory, 'instance')
|
||||
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):
|
||||
|
@ -51,13 +52,25 @@ def cleanup(directory, verbose=False):
|
|||
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.")
|
||||
|
||||
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)")
|
||||
|
||||
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)
|
||||
cleanup(args.directory, args.verbose)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue