P2: 清理与一致性

- CLI: --preset 实际生效;--directory-listing/--enable-stats/--enable-*/--ignore-hidden 支持 true/false(修复 type=bool 陷阱),未显式传入时不再覆盖 settings.json
- 版本号统一 v2.3(settings.json/config.py/v1/v2/Dockerfile)
- 移除硬编码 /tmp/pypi_debug.log 写文件;v2 裸 except 改记录错误返回 500
- webhook id 非法输入返回 400;下载趋势 timedelta 导入提升修复 NameError
- 打包模式 auth_token 写入 exe 目录(不再写入 _MEIPASS)
- README 修正: 线程池架构、pyinstaller 构建方式
- mirrors/__init__.py ' Quay.io' 笔误;chunked 响应去掉 Content-Length;docs/ui realpath 边界
- SQLite WAL+busy_timeout;下载计数原子 UPDATE
- requirements 移除未使用的 cachetools/apscheduler
This commit is contained in:
HYC Fixer
2026-08-30 12:25:26 +08:00
parent 237b99b480
commit dfae749612
12 changed files with 4020 additions and 3968 deletions
+583 -583
View File
File diff suppressed because it is too large Load Diff
+8 -21
View File
@@ -35,6 +35,14 @@ class PyPIMirror:
os.makedirs(self.simple_dir, exist_ok=True)
os.makedirs(self.web_dir, exist_ok=True)
def _debug_log(self, msg: str):
"""受 debug 配置控制的调试日志(原硬编码 /tmp/pypi_debug.log)"""
try:
if self.config and self.config.get('debug'):
print(f"[PyPI-Mirror] {msg}")
except Exception:
pass
def handle_request(self, handler, path: str) -> bool:
"""
处理PyPI请求
@@ -155,29 +163,17 @@ class PyPIMirror:
package = package.lower()
# 调试 - 确保函数被调用
debug_file = '/tmp/pypi_debug.log'
with open(debug_file, 'a') as f:
f.write(f"[HANDLE_SIMPLE] START package={package}\n")
# 检查客户端Accept header
accept = handler.headers.get('Accept', '')
wants_json = 'application/vnd.pypi.simple.v1+json' in accept
# 调试
debug_file = '/tmp/pypi_debug.log'
with open(debug_file, 'a') as f:
f.write(f"[SIMPLE_INDEX] package={package}, wants_json={wants_json}, accept={accept[:50]}\n")
# 根据请求格式选择正确的缓存key,统一使用 simple/ 前缀
cache_key = f"simple/{package}"
cached = self._get_cache(cache_key)
# 调试缓存
debug_file = '/tmp/pypi_debug.log'
with open(debug_file, 'a') as f:
f.write(f"[CACHE_CHECK] cache_key={cache_key}, cached={'YES' if cached else 'NO'}\n")
if cached:
# 返回缓存,使用正确的Content-Type
if wants_json:
@@ -213,9 +209,6 @@ class PyPIMirror:
cache_key = f"simple/{package}"
else:
# 转换为HTML格式
debug_file = '/tmp/pypi_debug.log'
with open(debug_file, 'a') as f:
f.write(f"[CONVERT_CALL] Before conversion\n")
try:
proxy_data = self._convert_simple_html(package, data)
with open(debug_file, 'a') as f:
@@ -564,9 +557,6 @@ class PyPIMirror:
import sys
import os
# 写入调试文件
debug_file = '/tmp/pypi_debug.log'
with open(debug_file, 'a') as f:
f.write(f"[PyPI] Converting HTML for package: {package}\n")
# 打印前几个链接用于调试
import re
test_matches = re.findall(r'href="([^"]+)"', html)[:3]
@@ -621,9 +611,6 @@ class PyPIMirror:
def convert_relative_match(match):
"""转换相对路径链接"""
href = match.group(1)
debug_file = '/tmp/pypi_debug.log'
with open(debug_file, 'a') as f:
f.write(f"[CONVERT] Input href: {href[:80]}...\n")
# 提取文件名
filename = href.split('/')[-1].split('#')[0]
# 提取完整的hash路径(从 packages/ 后面的所有部分除了文件名)