如何在Python中查询和管理Debian包存储库?

2024-04-20 14:04:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我希望能够查看本地.deb文件和远程存储库,并推断依赖关系等,以便可以构建自己的存储库和部分镜像(可能是通过为reprepro创建配置文件)。在

问题是,许多帮助解决这个问题的命令行工具(apt-rdepends等)都假设您在目标系统上运行并利用本地的apt缓存,而我通常会处理与我当前运行的版本不同的Ubuntu和Debian发行版的内容,所以我想在一定距离的情况下再做一点。在

python apt包功能强大,但文档记录非常差,让我可以检查本地文件系统上的.deb文件并提取依赖关系。我现在想知道是否有类似的工具来解析包装.gz存储库中的文件?(这不是太棘手,但我不想重新发明轮子!)在

总体目标是创建和维护两个存储库:一个包含我们自己的软件包,另一个是Ubuntu发行版的部分镜像,其中包含一些已知的必需软件包以及它们或我们自己的软件包所依赖的任何东西。在


Tags: 文件工具命令行利用目标镜像远程关系
2条回答

一个非常有效的方法是为所有相关发行版创建本地apt缓存。来自devscripts包的工具chdist允许您创建许多这样的缓存,而不需要使用根权限。然后,您可以使用您常用的工具(例如apt rdepends)来查询这些缓存,方法是将它们包装在chdist中。甚至可以使用rootdir关键字参数将python apt指向本地缓存apt.cache.Cache,然后在那里可以解析依赖关系。在

你可能想看看repoman,至少可以从中借鉴一些想法。在

例如,获取deb包信息,如https://github.com/synack/repoman#get-detailed-information-about-a-package-1

[
{
    "SHA1": "cae8b9a4a821237a24b5757566efdc95391090d4",
    "Maintainer": "Jeremy Grosser <synack@digg.com>",
    "Description": "server-side, HTML-embedded scripting language (meta-package) This package is a meta-package that, when installed, guarantees that you have at least one of the four server-side versions of the PHP5 interpreter installed.  Removing this package won't remove PHP5 from your system, however it may remove other packages that depend on this one. . PHP5 is an HTML-embedded scripting language. Much of its syntax is borrowed from C, Java and Perl with a couple of unique PHP-specific features thrown in. The goal of the language is to allow web developers to write dynamically generated pages quickly. . Homepage: http://www.php.net/",
    "Package": "php5",
    "Section": "web",
    "MD5sum": "0efa615337f0ba59d8369e4469884730",
    "Installed-Size": "20",
    "Filename": "pool/main/p/php5/php5_5.2.9-digg8_all.deb",
    "Priority": "normal",
    "Depends": "libapache2-mod-php5 (>= 5.2.9-digg8) | php5-cgi (>= 5.2.9-digg8), php5-common (>= 5.2.9-digg8)",
    "Version": "5.2.9-digg8",
    "Architecture": "all",
    "SHA256": "26844b968f6b51c1a02fd59c21455bf6ba47e46e47e53c6676af0ee4c2dd799b",
    "Size": "1024"
}

]

代码https://github.com/synack/repoman/blob/master/repoman/repository.py#L187

相关问题 更多 >