You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
swarms/scripts/cleanup/json_log_cleanup.py

57 lines
1.8 KiB

8 months ago
import os
import shutil
7 months ago
from loguru import logger
7 months ago
def cleanup_json_logs(name: str = None):
8 months ago
# Define the root directory and the target directory
root_dir = os.getcwd()
target_dir = os.path.join(root_dir, name)
8 months ago
# Create the target directory if it doesn't exist
if not os.path.exists(target_dir):
os.makedirs(target_dir)
# Walk through the root directory
for dirpath, dirnames, filenames in os.walk(root_dir):
for filename in filenames:
# If the file is a JSON log file, .log file or .txt file
if (
filename.endswith(".json")
or filename.endswith(".log")
# or filename.endswith(".txt")
):
8 months ago
# Construct the full file paths
file_path = os.path.join(dirpath, filename)
target_path = os.path.join(target_dir, filename)
# Move the file to the target directory
shutil.move(file_path, target_path)
7 months ago
logger.info(f"Moved file {file_path} to {target_path}")
# Delete Chroma and Ruff cache
chroma_cache = os.path.join(root_dir, ".chroma_cache")
ruff_cache = os.path.join(root_dir, ".ruff_cache")
if os.path.exists(chroma_cache):
shutil.rmtree(chroma_cache)
logger.info(f"Deleted Chroma cache at {chroma_cache}")
if os.path.exists(ruff_cache):
shutil.rmtree(ruff_cache)
logger.info(f"Deleted Ruff cache at {ruff_cache}")
# Delete the "chroma" folder
chroma_folder = os.path.join(root_dir, "chroma")
if os.path.exists(chroma_folder):
shutil.rmtree(chroma_folder)
logger.info(f"Deleted Chroma folder at {chroma_folder}")
8 months ago
7 months ago
logger.info(
f"All JSON, LOG and TXT files have been moved to {target_dir}"
)
8 months ago
8 months ago
# Call the function
7 months ago
cleanup_json_logs("heinz_swarm")