11import os
22import yaml
33import requests
4+ import webbrowser
45import subprocess
56from typing import Any
67from colorama import Fore
78import tools .remove as remove
89from function .constant import Response
910from catfood .functions .print import 消息头
11+ from function .maintain .config import 读取配置
1012from catfood .exceptions .request import RequestException
1113from function .files .manifest import 获取现有包版本 , 获取清单目录
1214
@@ -26,6 +28,7 @@ def main(args: list[str]) -> int:
2628 if not 版本列表 :
2729 print (f"{ 消息头 .错误 } 未能获取到版本列表" )
2830 raise KeyboardInterrupt
31+ # NOTE: 对版本列表切片可以只检查指定版本(及)以后的版本
2932 检查软件包版本 (args [0 ], 版本列表 , (args [1 ].lower () in ["y" , "yes" , "skip" , "skip-check" ]))
3033 print (f"{ 消息头 .成功 } 成功检查 { Fore .BLUE } { args [0 ]} { Fore .RESET } 的所有版本" )
3134 return 0
@@ -34,6 +37,10 @@ def main(args: list[str]) -> int:
3437 return 1
3538
3639def 检查软件包版本 (软件包标识符 : str , 版本列表 : list [str ], 跳过检查 : bool ) -> None :
40+ 在浏览器中打开 = 读取配置 ("tools.autoremove.open_in_browser" )
41+ if not isinstance (在浏览器中打开 , bool ):
42+ 在浏览器中打开 = False
43+
3744 for 版本 in 版本列表 :
3845 移除理由 = "Attempt to download using WinGet failed."
3946 # TODO: 在参数中指定这个理由
@@ -45,7 +52,7 @@ def 检查软件包版本(软件包标识符: str, 版本列表: list[str], 跳
4552 print (f"{ 消息头 .成功 } 验证 { Fore .BLUE } { 软件包标识符 } { 版本 } { Fore .RESET } 通过!" )
4653 continue
4754 else :
48- InstallerUrls验证结果 = 检查所有安装程序URL (软件包标识符 , 版本 ) # 验证所有 InstallerUrl
55+ InstallerUrls验证结果 = 检查所有安装程序URL (软件包标识符 , 版本 , 在浏览器中打开 )
4956 if InstallerUrls验证结果 [0 ] in {1 , 2 }:
5057 print (f"{ 消息头 .警告 } 似乎有几个安装程序链接仍然有效,请检查它们。" )
5158 if 是否中止 (input (f"{ 消息头 .问题 } 要移除此版本吗? [y/N]: " )):
@@ -95,7 +102,7 @@ def 使用GitHubAPI检查安装程序URL(InstallerUrl: str) -> str:
95102 except ValueError as e :
96103 return f"{ Fore .RED } 错误 ({ e } ){ Fore .RESET } "
97104
98- def 检查所有安装程序URL (软件包标识符 : str , 软件包版本 : str ) -> tuple [int , str ]:
105+ def 检查所有安装程序URL (软件包标识符 : str , 软件包版本 : str , 在浏览器中打开 : bool ) -> tuple [int , str ]:
99106 """
100107 检查指定 软件包标识符 软件包版本 的安装程序清单中的所有 InstallerUrl 是否有失效的。
101108
@@ -135,6 +142,8 @@ def 检查所有安装程序URL(软件包标识符: str, 软件包版本: str) -
135142 for InstallerUrl in InstallerUrls :
136143 print (f"正在检查 { InstallerUrl } ..." , end = "" )
137144 try :
145+ if 在浏览器中打开 :
146+ webbrowser .open (InstallerUrl )
138147 try :
139148 # 尝试 HEAD 下
140149 响应 = requests .head (InstallerUrl , allow_redirects = True )
0 commit comments