如何在 deb 包列表中找到顶级依赖项?

如何在 deb 包列表中找到顶级依赖项?

假设我有一个软件包列表:

foo
libfoo
bar
baz
quux

假设foo要求libfoobar,且baz要求quux

我想要一种方法来放入该列表并取出该列表:

foo
baz

即 - 我想要安装最少的软件包列表,在解决依赖关系后,将安装整个软件包列表。

答案1

我创建了一个脚本,可以完全按照您的要求执行:https://gist.github.com/kotarou3/2b311fb7b79ae6b682246b32acf0b7e9

python3-aptpython3-networkx是依赖项。它使用 apt 包缓存作为包信息的来源。

包名称本身每行输出到 stdout,而有关它们的任何注释(例如,如果它们是循环的一部分)将输出到 stderr

例子:

$ ./find-top-level-packages.py nginx nginx-core zlib1g firefox
firefox
nginx
$ ./find-top-level-package.py -h
usage: find-top-level-packages.py [-h] [--root-dir dir]
                                  [--follow-unspecified-packages]
                                  [--no-use-recommends]
                                  [--show-missing-recommends]
                                  [package [package ...]]

Find top-level packages of the dependency graph

positional arguments:
  package               package names to use (default: all installed packages)

optional arguments:
  -h, --help            show this help message and exit
  --root-dir dir        act as if chrooted in the specified directory
  --follow-unspecified-packages
                        follow dependencies of packages not part of the
                        initial input
  --no-use-recommends   don't use recommended packages for the dependency
                        graph
  --show-missing-recommends
                        list missing recommended packages suffixed with a dash

答案2

我没有足够的声誉来添加评论,因此被迫写一个单独的答案。但这是小太郎提供的答案的附加信息

他的脚本非常棒。请确保安装了正确版本的 networkx 以确保它正常工作。

sudo pip3 安装 networkx==1.11

相关内容