Skip to content

Commit

Permalink
fix: 尝试修复更新问题
Browse files Browse the repository at this point in the history
  • Loading branch information
hanxi committed Dec 19, 2024
1 parent 00733ad commit 811e937
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions supervisor.conf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ command=/app/.venv/bin/python3 /app/xiaomusic.py
directory=/app
autostart=true
autorestart=true
startretries=0
stderr_logfile=/app/xiaomusic.log.txt
stdout_logfile=/app/xiaomusic.log.txt

20 changes: 16 additions & 4 deletions xiaomusic/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import shutil
import string
import subprocess
import tarfile
import tempfile
import urllib.parse
from collections.abc import AsyncIterator
Expand Down Expand Up @@ -1091,17 +1090,30 @@ async def download_and_extract(url: str, target_directory: str):
async for chunk in response.content.iter_any():
f.write(chunk)
log.info(f"文件下载完成: {file_name}")

# 解压下载的文件
if file_name.endswith(".tar.gz"):
with tarfile.open(file_name, "r:gz") as tar:
tar.extractall(path=target_directory)
log.info(f"文件解压完成到: {target_directory}")
await extract_tar_gz(file_name, target_directory)
else:
ret = f"下载失败, 包有问题: {file_name}"
log.warning(ret)

else:
ret = f"下载失败, 状态码: {response.status}"
log.warning(ret)
return ret


async def extract_tar_gz(file_name: str, target_directory: str):
# 使用 asyncio.create_subprocess_exec 执行 tar 解压命令
command = ["tar", "-xzvf", file_name, "-C", target_directory]
# 启动子进程执行解压命令
proc = await asyncio.create_subprocess_exec(*command)
exit_code = await proc.wait() # 等待子进程完成
log.info(f"extract_tar_gz completed with exit code {exit_code}")
return exit_code


def chmodfile(file_path: str):
try:
os.chmod(file_path, 0o775)
Expand Down

0 comments on commit 811e937

Please sign in to comment.