Files
YG_FT_Platform/request/cleanup.sh
DESKTOP-72TV0V4\caoxiaozhu bda8f13446 1. 增加了请求框架
2. 增加了删除虚拟环境的脚本
2026-01-12 14:20:44 +08:00

85 lines
2.2 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
set -euo pipefail
# 永远从脚本所在目录运行(避免在别的目录执行导致路径错误)
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
echo "🧹 X-Request 框架环境清理"
echo "=========================="
# 函数:加载 .env 文件中的变量
load_env_file() {
local env_file=".env"
if [ -f "$env_file" ]; then
while IFS='=' read -r key value; do
[[ "$key" =~ ^#.*$ ]] && continue
[[ -z "$key" ]] && continue
value=$(echo "$value" | sed 's/^["'\'']//' | sed 's/["'\'']$//')
export "$key=$value"
done < "$env_file"
fi
}
# 加载环境配置
load_env_file
# 检查虚拟环境是否存在
if [ ! -d "xrequest" ]; then
echo "⚠️ 虚拟环境不存在,无需清理"
exit 0
fi
echo "📋 检测到虚拟环境: xrequest"
# 询问用户确认
read -p "确定要删除虚拟环境吗?(y/N): " confirm
if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
echo "❌ 操作已取消"
exit 0
fi
# 删除虚拟环境
echo "🗑️ 正在删除虚拟环境..."
rm -rf xrequest
if [ $? -eq 0 ]; then
echo "✅ 虚拟环境已删除"
else
echo "❌ 虚拟环境删除失败"
exit 1
fi
# 询问是否清理日志
if [ -d "${LOGS_DIR:-logs}" ]; then
echo ""
read -p "是否也要清理日志目录?(y/N): " clean_logs
if [[ "$clean_logs" =~ ^[Yy]$ ]]; then
echo "🗑️ 正在清理日志目录..."
rm -rf "${LOGS_DIR:-logs}"
if [ $? -eq 0 ]; then
echo "✅ 日志目录已清理"
else
echo "⚠️ 日志目录清理失败"
fi
fi
fi
# 询问是否清理 __pycache__ 和 .pyc 文件
echo ""
read -p "是否清理 Python 缓存文件 (__pycache__, *.pyc)(y/N): " clean_cache
if [[ "$clean_cache" =~ ^[Yy]$ ]]; then
echo "🗑️ 正在清理 Python 缓存..."
find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
find . -type f -name "*.pyc" -delete 2>/dev/null || true
echo "✅ Python 缓存已清理"
fi
echo ""
echo "🎉 清理完成!"
echo ""
echo "📝 如需重新设置环境,请运行:"
echo " ./setup.sh"
echo ""