80 lines
2.2 KiB
Python
80 lines
2.2 KiB
Python
import os
|
|
import subprocess
|
|
import requests
|
|
from tqdm import tqdm
|
|
|
|
# 保存到脚本所在目录
|
|
download_dir = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
# 配置文件信息
|
|
files = {
|
|
"graphviz": {
|
|
"url": "https://blog.sairate.top/upload/app/windows_10_cmake_Release_graphviz-install-12.2.1-win64.exe",
|
|
"filename": "graphviz-install-12.2.1-win64.exe",
|
|
"install_cmd": lambda path: [path, '/S', '/AddToPath=1']
|
|
},
|
|
"cmake": {
|
|
"url": "https://blog.sairate.top/upload/app/cmake-4.0.0-rc4-windows-x86_64.msi",
|
|
"filename": "cmake-4.0.0-rc4-windows-x86_64.msi",
|
|
"install_cmd": lambda path: [
|
|
"msiexec", "/i", path, "/qn", "ADD_CMAKE_TO_PATH=System"
|
|
]
|
|
}
|
|
}
|
|
|
|
# 单独下载但不安装的文件
|
|
optional_files = {
|
|
"plantuml": {
|
|
"url": "https://blog.sairate.top/upload/app/plantuml-1.2025.2.jar",
|
|
"filename": "plantuml-1.2025.2.jar"
|
|
}
|
|
}
|
|
|
|
|
|
def download_file(url, filename):
|
|
file_path = os.path.join(download_dir, filename)
|
|
print(f"开始下载 {filename} ...")
|
|
response = requests.get(url, stream=True)
|
|
total = int(response.headers.get('content-length', 0))
|
|
|
|
with open(file_path, 'wb') as file, tqdm(
|
|
desc=filename,
|
|
total=total,
|
|
unit='iB',
|
|
unit_scale=True,
|
|
unit_divisor=1024,
|
|
) as bar:
|
|
for data in response.iter_content(chunk_size=1024):
|
|
size = file.write(data)
|
|
bar.update(size)
|
|
|
|
print(f"下载完成:{filename}")
|
|
return file_path
|
|
|
|
|
|
def install_file(file_path, install_command):
|
|
print(f"开始安装 {file_path} ...")
|
|
subprocess.run(install_command(file_path), check=True)
|
|
print(f"安装完成:{file_path}")
|
|
|
|
|
|
def main():
|
|
# 安装需要安装的文件
|
|
for name, info in files.items():
|
|
try:
|
|
file_path = download_file(info["url"], info["filename"])
|
|
install_file(file_path, info["install_cmd"])
|
|
except Exception as e:
|
|
print(f"处理 {name} 时出错: {e}")
|
|
|
|
# 下载可选文件
|
|
for name, info in optional_files.items():
|
|
try:
|
|
download_file(info["url"], info["filename"])
|
|
except Exception as e:
|
|
print(f"下载 {name} 时出错: {e}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|