宝塔面板添加Python项目安装python环境失败

2025-12-29 20:33 morefun

https://github.com/aaPanel/BaoTa/blob/main/class/projectModel/btpyvm.py

/www/server/panel/class/projectModel/btpyvm.py 

顶部导入

bs4 from bs4 import BeautifulSoup 

替换解析代码 


        def __parser_xml(self, data_txt: str) -> List[PythonVersion]:
        res_list = []
        
        # data_txt = data_txt.replace("<hr>", "")
   
        last_2 = {
            "data": (2, 0, 0),
            "version": None,
        }

        # root = cElementTree.fromstring(data_txt)
        # for data in root.findall("./body/pre/a"):
        #     v_str = data.text
        #     if v_str.startswith("2."):
        #         ver = v_str.strip("/")
        #         t_version = parse_version_to_list(ver)
        #         if t_version > last_2["data"]:
        #             last_2["data"] = t_version
        #             last_2["version"] = ver
        #         continue
        #     if v_str.startswith("3."):
        #         p_v = PythonVersion(v_str.strip("/"))
        #         res_list.append(p_v)
        #         continue

        soup = BeautifulSoup(data_txt, 'html.parser')
        links = soup.find_all('a')
        for link in links:
            v_str = link.text
            if  v_str.startswith("2."):
                ver = v_str.strip("/")
                t_version = parse_version_to_list(ver)
                if t_version > last_2["data"]:
                    last_2["data"] = t_version
                    last_2["version"] = ver
                continue
            elif v_str.startswith("3."):
                p_v = PythonVersion(v_str.strip("/"))
                res_list.append(p_v)
                continue
            
        if last_2["version"]:
            res_list.insert(0, PythonVersion(last_2["version"]))

        res_list.sort(key=lambda x: x.ver_t)

        need_remove = []
        for ver in res_list[::-1]:
            if not self.test_last_version_is_stable(ver):
                need_remove.append(ver)
            else:
                break
        for ver in need_remove:
            res_list.remove(ver)

        return res_list


插件»

发表评论:

Powered by MoreFun.CN 粤ICP备2025398508号