1 Star 0 Fork 0

mshqian / autospec-build

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
adapt_failed_commands.py 2.71 KB
一键复制 编辑 原始数据 按行查看 历史
mshqian 提交于 2024-03-28 16:33 . update
from difflib import SequenceMatcher
import math
file = "failed_commands"
pkg_list_file="/root/autospec/openEuler-22.03-LTS-package-list.txt"
def dev2devel():
#change -dev into devel
with open(file,'r') as f:
content = f.read().replace("-dev","-devel")
with open(file,'w') as f:
f.write(content)
def match_pkg_of_openeuler():
with open(pkg_list_file,'r') as plf:
pkg_list = plf.readlines()
changed_lines = []
with open(file,'r') as f:
for line in f.readlines():
if line.startswith('#'):
changed_lines.append(line)
continue
pat,pkg = line.split(',')
pkgs = pkg.strip().split()
matched_pkgs = []
for pkg in pkgs:
pkgs0 = [pkg]
if pkg.startswith("pkgconfig("):
pkg0 = pkg[10:-1]
pkgs0.append(pkg0)
if not pkg0.startswith("lib"):
pkgs0.append("lib"+pkg0)
if not pkg0.endswith("-devel"):
pkgs0.append(pkg0+"-devel")
elif pkg.startswith("pypi("):
pkg0 = pkg[5:-1]
pkg0 = "python3-" + pkg0
pkgs0.append(pkg0)
elif pkg.startswith("pypi-"):
pkg0 = pkg[5:]
pkg0 = "python3-" + pkg0
pkgs0.append(pkg0)
elif pkg.startswith("qt"):
pkg0 = "qt5-" + pkg
pkgs0.append(pkg0)
top_ratio = 0.0
for pkg00 in pkgs0:
for pkg1 in pkg_list:
pkg1 = pkg1.strip('\n')
s = SequenceMatcher(None,pkg00.lower(),pkg1.lower())
ratio = s.ratio()
if math.isclose(ratio,1.0):
matched_pkgs.append(pkg1)
if ratio > top_ratio:
top_ratio = ratio
matched_pkg = pkg1
print("pkgs=" + str(pkgs) + ",pkg00=" + pkg00 + ",matched_pkg=" + matched_pkg + ",top_ratio="+ "{top_ratio:5.2}".format(top_ratio=top_ratio) + ", matched_pkgs=" + str(matched_pkgs))
if len(matched_pkgs) == 0:
changed_lines.append(line)
else:
line1 = pat + ','
for matched_pkg in matched_pkgs:
line1 += ' ' + matched_pkg
line1 += '\n'
changed_lines.append(line1)
with open(file,'w') as f:
for changed_line in changed_lines:
f.write(changed_line)
def main():
dev2devel()
match_pkg_of_openeuler()
main()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mshqian/autospec-build.git
git@gitee.com:mshqian/autospec-build.git
mshqian
autospec-build
autospec-build
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891