保存现有功能 增加域名和添加时间关联
This commit is contained in:
@@ -14,15 +14,6 @@ import random
|
||||
import string
|
||||
from typing import Dict, Any, Optional, Tuple
|
||||
|
||||
# 尝试导入必要的库,如果不存在则安装
|
||||
required_packages = [
|
||||
"loguru",
|
||||
"pymysql",
|
||||
"aiomysql",
|
||||
"redis",
|
||||
"pyyaml"
|
||||
]
|
||||
|
||||
# 设置颜色输出
|
||||
class Colors:
|
||||
HEADER = '\033[95m'
|
||||
@@ -61,6 +52,97 @@ def print_error(message):
|
||||
"""打印错误信息"""
|
||||
print(f"{Colors.RED}✗ {message}{Colors.ENDC}")
|
||||
|
||||
# 检测虚拟环境
|
||||
def is_in_virtualenv():
|
||||
"""检查是否在虚拟环境中运行"""
|
||||
return hasattr(sys, 'real_prefix') or (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix)
|
||||
|
||||
def setup_virtualenv():
|
||||
"""设置虚拟环境"""
|
||||
print_title("虚拟环境检测")
|
||||
|
||||
if is_in_virtualenv():
|
||||
print_success("已在虚拟环境中运行")
|
||||
return True
|
||||
|
||||
print_warning("当前不在虚拟环境中运行")
|
||||
create_venv = input("是否创建并使用虚拟环境? (推荐) (y/n, 默认: y): ").strip().lower()
|
||||
|
||||
if create_venv == 'n':
|
||||
print_warning("跳过虚拟环境创建,将直接在系统Python环境中安装依赖")
|
||||
return True
|
||||
|
||||
venv_path = input("请输入虚拟环境路径 (默认: ./venv): ").strip() or "./venv"
|
||||
|
||||
try:
|
||||
# 检查venv模块
|
||||
try:
|
||||
import venv
|
||||
has_venv = True
|
||||
except ImportError:
|
||||
has_venv = False
|
||||
|
||||
if not has_venv:
|
||||
print_warning("Python venv模块不可用,尝试安装...")
|
||||
if sys.platform.startswith('linux'):
|
||||
print("在Linux上安装venv模块...")
|
||||
try:
|
||||
subprocess.check_call(["sudo", "apt", "install", "-y", "python3-venv", "python3-full"])
|
||||
except:
|
||||
try:
|
||||
subprocess.check_call(["sudo", "yum", "install", "-y", "python3-venv"])
|
||||
except:
|
||||
print_error("无法自动安装venv模块,请手动安装后重试")
|
||||
print_warning("Ubuntu/Debian: sudo apt install python3-venv python3-full")
|
||||
print_warning("CentOS/RHEL: sudo yum install python3-venv")
|
||||
return False
|
||||
else:
|
||||
print_error("请安装Python venv模块后重试")
|
||||
return False
|
||||
|
||||
# 创建虚拟环境
|
||||
print_step("创建", f"正在创建虚拟环境: {venv_path}")
|
||||
if sys.platform.startswith('win'):
|
||||
subprocess.check_call([sys.executable, "-m", "venv", venv_path])
|
||||
else:
|
||||
subprocess.check_call([sys.executable, "-m", "venv", venv_path])
|
||||
|
||||
# 计算激活脚本路径
|
||||
if sys.platform.startswith('win'):
|
||||
activate_script = os.path.join(venv_path, "Scripts", "activate.bat")
|
||||
python_path = os.path.join(venv_path, "Scripts", "python.exe")
|
||||
else:
|
||||
activate_script = os.path.join(venv_path, "bin", "activate")
|
||||
python_path = os.path.join(venv_path, "bin", "python")
|
||||
|
||||
print_success(f"虚拟环境创建成功: {venv_path}")
|
||||
print_warning("请退出当前程序,然后执行以下命令激活虚拟环境并重新运行:")
|
||||
|
||||
if sys.platform.startswith('win'):
|
||||
print(f"\n{Colors.BOLD}Windows:{Colors.ENDC}")
|
||||
print(f" {activate_script}")
|
||||
print(f" python setup_environment.py")
|
||||
else:
|
||||
print(f"\n{Colors.BOLD}Linux/Mac:{Colors.ENDC}")
|
||||
print(f" source {activate_script}")
|
||||
print(f" python setup_environment.py")
|
||||
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
print_error(f"创建虚拟环境失败: {str(e)}")
|
||||
return False
|
||||
|
||||
# 尝试导入必要的库,如果不存在则安装
|
||||
required_packages = [
|
||||
"loguru",
|
||||
"pymysql",
|
||||
"aiomysql",
|
||||
"redis",
|
||||
"pyyaml",
|
||||
"cryptography" # 添加这一行
|
||||
]
|
||||
|
||||
def check_and_install_packages():
|
||||
"""检查并安装必要的Python包"""
|
||||
print_step(1, "检查并安装必要的Python包")
|
||||
|
||||
Reference in New Issue
Block a user