gpt4 book ai didi

python - 如何使用 Python APT 标记特定的 conffile 以进行覆盖?

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:19:53 25 4
gpt4 key购买 nike

我正在使用 Python APT wrapper library编写交互式 APT 界面。我想处理 APT 在 apt-upgrade 期间提示是否覆盖或保留配置文件的情况。

这对应于命令行 APT 中的以下用户交互:

Configuration file '/var/usr/myconf.cfg'
==> File on system created by you or by a script.
==> File also in package provided by package maintainer.
What would you like to do about it ? Your options are:
Y or I : install the package maintainer's version
N or O : keep your currently-installed version
D : show the differences between the versions
Z : start a shell to examine the situation
The default action is to keep your current version.
*** myconf.cfg (Y/I/N/O/D/Z) [default=N] ? Y
Installing new version of config file var/usr/myconf.cfg ...
Status change

我发现 apt.progress.base.InstallProgress 有一个回调函数 conffile 当 APT 提示是否覆盖时调用。

它具有以下签名:

def conffile(self, current, new):
"""(Abstract) Called when a conffile question from dpkg is detected."""

参数 currentnew 是涉及的两个文件路径。如何使用 Python APT 以编程方式将配置文件标记为覆盖或保留?

最佳答案

Python APT 库似乎没有提供任何解决方法。我最终写了 Dpkg::Options { "–force-confnew"; }/etc/apt/apt.conf.d/local,它总是用新的 conf 文件覆盖旧的 conf 文件;我无法花时间扩展库。

获得更多用户交互的一种可能解决方案是使用 apt 命令执行手动试运行,并从控制台输出中解析所有配置文件冲突。然后可以提示用户为所有 conf 文件提供解决方案并编写/etc/apt/apt.conf.d/local 适本地 + 从 Python APT 库调用升级。

更新:answerSeeker 找到了一种以编程方式设置这些选项的方法 - 请参阅 this post .

关于python - 如何使用 Python APT 标记特定的 conffile 以进行覆盖?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44970138/

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