Skip to content

Commit

Permalink
feat: 加强对--fix-broken的检测
Browse files Browse the repository at this point in the history
  • Loading branch information
fishros committed Sep 6, 2024
1 parent 5217e3f commit 38a2086
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
42 changes: 30 additions & 12 deletions tools/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1284,14 +1284,26 @@ def find_replace_sub(file,start,end,new):
f.write(data)

@staticmethod
def check_result(result,patterns):
if len(result)==3:
result = result[1]+result[2]
def check_result(result, patterns:list):
# 处理 result 如果其长度正好为 3
if len(result) == 3:
# 将 result[1] 和 result[2] 安全转换为字符串并拼接
result = str(result[1]) + str(result[2])

# 如果 result 是字符串,确保它是一个可迭代对象
if isinstance(result, str):
result = [result]

# 遍历 result 中的每一行
for line in result:
line = str(line) # 确保 line 是字符串
# 对每个 pattern 进行检查
for pattern in patterns:
line = str(line)
if len(re.findall(pattern, line))>0:
return True
# 如果找到一个匹配
if len(re.findall(pattern, line)) == 1:
return True # 返回 True 表示匹配成功
# 如果所有行和所有模式都未匹配,返回 False
return False

class AptUtils():
@staticmethod
Expand Down Expand Up @@ -1338,13 +1350,19 @@ def install_pkg(name,apt_tool="apt",auto_yes=True,os_command=False):
yes = ""
if auto_yes:
yes="-y"

result = None
for key in dic.keys():
result = CmdTask("sudo {} install {} {}".format(apt_tool,dic[key],yes), 0, os_command=os_command).run()
if not result:

cmd_result = None
if dic:
for key in dic.keys():
cmd_result = CmdTask("sudo {} install {} {}".format(apt_tool,dic[key],yes), 0, os_command=os_command).run()
if os_command==False:
if FileUtils.check_result(cmd_result,["apt --fix-broken install"]):
print(cmd_result)
CmdTask("sudo apt --fix-broken install -y", os_command=True).run()
cmd_result = CmdTask("sudo {} install {} {}".format(apt_tool,dic[key],yes), 0, os_command=os_command).run()
else:
PrintUtils.print_warn(tr.tr("没有找到包:{}").format(name))
return result
return cmd_result

@staticmethod
def install_pkg_check_dep(name):
Expand Down
1 change: 0 additions & 1 deletion tools/tool_install_ros.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,6 @@ def choose_and_install_ros(self):
if install_tool=='aptitude':
AptUtils.install_pkg('aptitude')

# 先尝试使用apt 安装,之后再使用aptitude。
if code==2:
# 第一次尝试
cmd_result = CmdTask("sudo {} install {} -y".format(install_tool_apt,dic_base[install_version]),300,os_command=True).run()
Expand Down

0 comments on commit 38a2086

Please sign in to comment.