python - 在 python 中获取 deb 包中的 conffiles 列表

标签 python package apt

我想使用 python 获取与 deb 包关联的配置文件列表。我正在做一个项目,我需要知道是否修改了一个包安装的任何配置文件,所以我需要一个包安装的配置文件列表,这样我就可以用它来查看哪个配置文件被修改了。

我尝试使用 python-apt library documentation ,但找不到任何方法,请建议我这样做的方法。我知道我可以提取控制信息并读取原始 conffiles 文件,但我认为库本身可能有一个方法。

最佳答案

这是在 python-apt 上测试的: 我使用的包是:

http://ftp.debian.org/debian/pool/main/o/openssh/openssh-server_5.5p1-6+squeeze1_amd64.deb

from apt.debfile import DebPackage
ssh = DebPackage('openssh-server_5.5p1-6+squeeze1_amd64.deb')
print ssh.control_content('conffiles').split('\n')

[u'/etc/init.d/ssh', u'/etc/default/ssh', u'/etc/network/if-up.d/openssh-server', u'/etc/ufw/applications.d/openssh-server', u'/etc/pam.d/sshd', u'']

你需要去掉最后一个

print ssh.data_content('etc/init.d/ssh')
u'#! /bin/sh\n\n### BEGIN INIT INFO\n#......'

你需要去掉第一个斜线

关于python - 在 python 中获取 deb 包中的 conffiles 列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8022578/

相关文章:

python - 在 __init__ 内部,使用 __init__ 外部的变量

java - 在Gradle中,在Android上,Storm注释处理器可以像AndroidAnnotations处理器一样运行吗?

python - 为什么这些 apt-packages 在 Ubuntu 和 Heroku 上表现不一样?

python - py2app 错误 : in find_needed_modules TypeError: 'NoneType' object has no attribute '__getitem__'

python - Pandas 数据帧 : How to select rows on multiple conditions?

python - 注释值给出 None,需要 0

java - 如何下载 edu.mit.sketch.geom 库

go - 在外壳程序脚本中运行时,“go get”命令不会生成bin文件夹

java - 如何使一个方法在所有子包中都可访问

Ubuntu 18.10 - 如何安装特定版本的 gcc