gpt4 book ai didi

python - 如何处理使用 python-apt 生成多个配置对话框屏幕的 apt 安装?

转载 作者:行者123 更新时间:2023-11-28 18:45:22 27 4
gpt4 key购买 nike

例如,当安装 lirc 包时,它会提供配置对话框屏幕。如何自动化以选择默认值(或可能提供特定值)并继续?

现在我有一个简单的脚本:

  #!/usr/bin/env python
import apt
import sys

pkg_name = "lirc"

cache = apt.cache.Cache()
cache.update()

pkg = cache[pkg_name]
if pkg.is_installed:
print "{pkg_name} already installed".format(pkg_name=pkg_name)
else:
pkg.mark_install()

try:
cache.commit()
except Exception, arg:
print >> sys.stderr, "Sorry, package installation failed [{err}]".format(err=str(arg))

配置窗口如下链接 http://cdn.avsforum.com/d/db/db48d778_vbattach158986.jpeg

最佳答案

你可以使用

export DEBIAN_FRONTEND=noninteractive

然后使用 debconf提供您选择的值。这howto解释

If you want to supply an answer to a configuration question but do not want to be prompted for it then this can be arranged by preseeding the DebConf database with the required information. You will need to know:

  • the name of the package responsible for asking the question (which might not be the one you asked to install if there are dependencies),
  • the configuration database key against which the answer is recorded, and
  • the type of the answer (string, boolean, select, multiselect or password).

也可以在 python-apt 中使用 apt_pkg.Configuration 提供配置选项类(class)。举例说明

apt_pkg.config.set("Dir", self.tmpdir)

然后您必须找到配置脚本要求的选项的名称,并通过 python 脚本设置它。

关于python - 如何处理使用 python-apt 生成多个配置对话框屏幕的 apt 安装?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21160872/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com