mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-07-20 20:21:50 +08:00
删除PROXY_SUPPLEMENT变量,增加只读属性‘PIP_OPTIONS’
1、删除`proxychains4`模块支持,`pip`代理已支持全局模式下的`socks4`、`socks4a`、`socks5`、`socks5h`、`http`、`https`协议; 2、删除`PROXY_SUPPLEMENT`变量,取消手动控制功能; 3、增加自动判断,将`pip`与`update`的代理判断,从手动改为自动,优先级:镜像站 > 全局 > 不代理; 4、将`pip`的附加代理参数,作为只读属性`PIP_OPTIONS`写入到`config`中,其他对象可通过`settings.PIP_OPTIONS`实现快速调用。
This commit is contained in:
@@ -150,8 +150,6 @@ class Settings(BaseSettings):
|
||||
GITHUB_PROXY: Optional[str] = ''
|
||||
# pip镜像站点,格式:https://pypi.tuna.tsinghua.edu.cn/simple
|
||||
PIP_PROXY: Optional[str] = ''
|
||||
# 代理补全开关,支持 True、False, 在没有配置镜像站的时候,True 使用 PROXY_HOST 补全镜像站缺失,False 在没有配置镜像站的时候,不使用全局补全
|
||||
PROXY_SUPPLEMENT: bool = True
|
||||
# 大内存模式
|
||||
BIG_MEMORY_MODE: bool = False
|
||||
|
||||
@@ -231,33 +229,22 @@ class Settings(BaseSettings):
|
||||
return None
|
||||
|
||||
@property
|
||||
def PROXY_URLPARSE(self, url: str = PROXY_HOST):
|
||||
def PROXY_URLPARSE(self):
|
||||
"""
|
||||
解析地址组成 - 允许其他地址调用
|
||||
解析地址组成
|
||||
"""
|
||||
if url:
|
||||
# 解析 URL
|
||||
parsed_url = urlparse(url)
|
||||
# 协议
|
||||
protocol = parsed_url.scheme or ""
|
||||
# 用户名
|
||||
username = parsed_url.username or ""
|
||||
# 密码
|
||||
password = parsed_url.password or ""
|
||||
# 主机
|
||||
host = parsed_url.hostname or ""
|
||||
# 端口:
|
||||
port = parsed_url.port or ""
|
||||
# 路径
|
||||
path = parsed_url.path or ""
|
||||
# 用户名:密码@主机:端口
|
||||
netloc = parsed_url.netloc or ""
|
||||
# 查询参数: ?key=value
|
||||
query = parsed_url.query or ""
|
||||
# 使用;分割的参数
|
||||
params = parsed_url.params or ""
|
||||
# 片段: #fragment
|
||||
fragment = parsed_url.fragment or ""
|
||||
if self.PROXY_HOST:
|
||||
parsed_url = urlparse(self.PROXY_HOST)
|
||||
protocol = parsed_url.scheme or "" # 协议
|
||||
username = parsed_url.username or "" # 用户名
|
||||
password = parsed_url.password or "" # 密码
|
||||
host = parsed_url.hostname or "" # 主机
|
||||
port = parsed_url.port or "" # 端口
|
||||
path = parsed_url.path or "" # 路径
|
||||
netloc = parsed_url.netloc or "" # 用户名:密码@主机:端口
|
||||
query = parsed_url.query or "" # 查询参数: ?key=value
|
||||
params = parsed_url.params or "" # 使用;分割的参数
|
||||
fragment = parsed_url.fragment or "" # 片段: #fragment
|
||||
|
||||
if not port:
|
||||
if protocol == "https":
|
||||
@@ -267,7 +254,6 @@ class Settings(BaseSettings):
|
||||
elif protocol in {"socks5", "socks5h", "socks4", "socks4a"}:
|
||||
port = 1080
|
||||
|
||||
# 返回解析结果
|
||||
return {
|
||||
"protocol": protocol,
|
||||
"username": username,
|
||||
@@ -300,6 +286,28 @@ class Settings(BaseSettings):
|
||||
}
|
||||
return {}
|
||||
|
||||
@property
|
||||
def PIP_OPTIONS(self):
|
||||
"""
|
||||
pip调用附加参数
|
||||
"""
|
||||
protocol = host = port = ""
|
||||
parsed_url = self.PROXY_URLPARSE
|
||||
if parsed_url:
|
||||
protocol = parsed_url.get("scheme", "").lower()
|
||||
host = parsed_url.get("host", "").lower()
|
||||
port = parsed_url.get("port", "")
|
||||
# 优先级:镜像站 > 全局 > 不代理
|
||||
if settings.PIP_PROXY:
|
||||
PIP_OPTIONS = f" -i {settings.PIP_PROXY} "
|
||||
# 全局代理地址
|
||||
elif protocol in {"http", "https", "socks4", "socks4a", "socks5", "socks5h"} and host and port:
|
||||
PIP_OPTIONS = f" --proxy={settings.PROXY_HOST} "
|
||||
# 不使用代理
|
||||
else:
|
||||
PIP_OPTIONS = ""
|
||||
return PIP_OPTIONS
|
||||
|
||||
@property
|
||||
def VAPID(self):
|
||||
return {
|
||||
|
||||
@@ -222,52 +222,7 @@ class PluginHelper(metaclass=Singleton):
|
||||
# 插件目录下如有requirements.txt则安装依赖
|
||||
requirements_file = plugin_dir / "requirements.txt"
|
||||
if requirements_file.exists():
|
||||
# 初始化
|
||||
protocol = host = port = username = password = PROXY_CHAINS = PIP_PROXY = ""
|
||||
# 返回json格式解析结果
|
||||
parsed_url = settings.PROXY_URLPARSE()
|
||||
if parsed_url:
|
||||
protocol = parsed_url.get("scheme", "").lower()
|
||||
username = parsed_url.get("username", "")
|
||||
password = parsed_url.get("password", "")
|
||||
host = parsed_url.get("host", "").lower()
|
||||
port = parsed_url.get("port", "")
|
||||
|
||||
# 全局优先,镜像站不存在时,使用全局代理
|
||||
if settings.PROXY_SUPPLEMENT:
|
||||
|
||||
# 检查settings.PROXY_HOST的协议类型,http或https
|
||||
if protocol in {"http", "https"}:
|
||||
if settings.PIP_PROXY:
|
||||
PIP_PROXY = f" -i {settings.PIP_PROXY} " if settings.PIP_PROXY else ""
|
||||
else:
|
||||
# 有主机名与端口号的时候
|
||||
if host and port:
|
||||
PIP_PROXY = f" --proxy={settings.PROXY_HOST} " if settings.PROXY_HOST else ""
|
||||
|
||||
# Todo:目前proxychains4的临时调用命令不支持socks5h和socks4a,需要生成临时配置文件才能解决,后面考虑支持一下
|
||||
elif protocol in {"socks4", "socks4a", "socks5", "socks5h"}:
|
||||
# 没有主机名,端口号
|
||||
if not host or not port:
|
||||
PIP_PROXY = f" -i {settings.PIP_PROXY} " if settings.PIP_PROXY else ""
|
||||
# 将拓展的socks协议转换为proxychains4支持的socks4和socks5
|
||||
else:
|
||||
if protocol in {"socks5", "socks5h"}:
|
||||
protocol = "socks5"
|
||||
elif protocol in {"socks4", "socks4a"}:
|
||||
protocol = "socks4"
|
||||
# 生成配置
|
||||
PROXY_CHAINS = f"proxychains4 -f <( echo -e '[ProxyList]\n{protocol} {host} {port} {username} {password}')"
|
||||
|
||||
# 不支持的协议类型
|
||||
else:
|
||||
PIP_PROXY = f" -i {settings.PIP_PROXY} " if settings.PIP_PROXY else ""
|
||||
|
||||
# 本地优先,镜像站不存在时,不使用全局代理
|
||||
else:
|
||||
PIP_PROXY = f" -i {settings.PIP_PROXY} " if settings.PIP_PROXY else ""
|
||||
|
||||
SystemUtils.execute(f"{PROXY_CHAINS} pip install -r {requirements_file} {PIP_PROXY} > /dev/null 2>&1")
|
||||
SystemUtils.execute(f"pip install -r {requirements_file} {settings.PIP_OPTIONS} > /dev/null 2>&1")
|
||||
# 安装成功后统计
|
||||
self.install_reg(pid)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user