1 Star 0 Fork 1

muyuying/release__pkgs_compares

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
compare_pkgs_cvrf_release.py 3.06 KB
一键复制 编辑 原始数据 按行查看 历史
mdche 提交于 2022-06-29 11:05 . init repo
import requests
import ssl
import warnings
import xml.etree.ElementTree as et
from lxml import etree
from urllib.request import urlopen
def resolve_xml(cvrf: str) -> list:
"""
resolve cvrf xml to get packages info.
Args:
cvrf(str): name of the cvrf
Returns:
xml_result(list): return the package list of the cvrf
"""
warnings.filterwarnings("ignore", category=DeprecationWarning)
xml_result = []
# tree = ET.parse("/Users/mingdaoche/Downloads/updateinfo_0412/0515/2203/cvrf-openEuler-SA-2022-1681.xml")
ssl._create_default_https_context = ssl._create_unverified_context
cvrf_url = "https://repo.openeuler.org/security/data/cvrf/2022/{}".format(cvrf)
raw_xml = urlopen(cvrf_url)
tree = et.parse(raw_xml)
root = tree.getroot()
# print('root_tag', root.tag)
for branch in root.getchildren()[6].getchildren():
if branch.attrib["Name"] == "openEuler":
continue
for product in branch.getchildren():
# print(product.text)
xml_result.append(product.text)
return xml_result
def resolve_html(version_date) -> list:
"""
resovle test repo's packates
Returns:
html_result(list): package of the test repo
"""
html_result = []
base_url = "http://121.36.84.172/repo.openeuler.org/{}/{}/{}/Packages/"
version_list = ["openEuler-22.03-LTS", "openEuler-20.03-LTS-SP1", "openEuler-20.03-LTS-SP3"]
arch_list = ["aarch64", "source", "x86_64", "noarch"]
for version in version_list:
for arch in arch_list:
response = requests.get(base_url.format(version,version_date, arch))
tree = etree.HTML(response.text)
rows = tree.xpath('//table[@id="list"]/tbody/tr')[1:]
for row in rows:
package_name = row.xpath('./td/a/text()')
# print(package_name)
html_result.append(package_name[0])
return html_result
def compare_packages(xml_result: list, html_result: list):
"""
Compare xml packages version with html packages
Args:
xml_result(list):
html_result(list):
Returns:
"""
return all([xml_pkg in html_result for xml_pkg in xml_result])
def traversal_check_updated_cvrf(version_date):
"""
check updated cvrfs' packages with the test repo
Returns:
bool: The result of the comparasion.
"""
html_result = resolve_html(version_date)
with open("updated_index.txt", 'r', encoding='utf-8') as file:
for line in file.readlines():
xml_name = line.replace("\n", "")
if compare_packages(resolve_xml(line), html_result):
print("cvrf {} packages comparision result is: Pass.".format(xml_name))
else:
print("cvrf {} packages comparision result is: Failed.".format(xml_name))
if __name__ == "__main__":
# print(resolve_html())
# print(resolve_xml("cvrf-openEuler-SA-2022-1683.xml"))
# print(compare_packages(resolve_xml("cvrf-openEuler-SA-2022-1683.xml"), resolve_html()))
traversal_check_updated_cvrf("update_20220529")
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/muyuying1/release__pkgs_compares.git
git@gitee.com:muyuying1/release__pkgs_compares.git
muyuying1
release__pkgs_compares
release__pkgs_compares
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385