我想使用 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/