LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Show package dependencies as recursive tree (https://www.linuxquestions.org/questions/linux-general-1/show-package-dependencies-as-recursive-tree-4175707804/)

boughtonp 02-10-2022 09:30 AM

Show package dependencies as recursive tree
 
I would like a way to see package dependencies in a nested tree view, for Debian (apt/dpkg).

Like how pstree displays a tree of processes, but with a specified package instead.

There's already "apt depends <packagename>" which shows dependencies (and related packages), but it doesn't do tree format (or provide descriptions).
I also found debtree which can do graphs, but I don't want a graph.

What I want:
* only dependencies (no recommends/suggests/enhances/etc)
* if a package is not already installed, show child dependencies in a tree (recursively)
* output should include the same brief descriptions that packages.debian.org uses (first line of Description field?)
* a status to indicate already installed/downloaded packages
* for lib* packages, either a count or a single line (no dependencies/descriptions needed)

Here's an example of the type of output I'd like:
Code:

$ dependency_tree vim
vim (2:8.2.2434-3+deb11u1) Vi IMproved - enhanced vi editor
- vim-common (= 2:8.2.2434-3+deb11u1) Vi IMproved - Common files
  - xxd tool to make (or reverse) a hex dump
- vim-runtime (= 2:8.2.2434-3+deb11u1) Vi IMproved - Runtime files

If you compare that with "apt depends vim" or the online package page the differences are hopefully apparent.

Am I overlooking a tool that already provides something like that, or is it something I need to go build myself?


wpeckham 02-10-2022 09:35 AM

Quote:

Originally Posted by boughtonp (Post 6327865)
I would like a way to see dependencies in a nested tree view, for Debian (apt/dpkg).

Like how pstree displays a tree of processes, but with a specified package instead.

There's already "apt depends <packagename>" which shows dependencies (and related packages), but it doesn't do tree format (or provide descriptions).
I also found debtree which can do graphs, but I don't want a graph.

What I want is:
* only dependencies (no recommends/suggests/enhances/etc)
* if a package is not already installed, show child dependencies
* output should include the same brief descriptions that packages.debian.org uses (first line of Description field?)
* a status to indicate already installed/downloaded packages
* for lib* packages, either a count or a single line (no dependencies/descriptions needed)

Here's an example of the type of output I'd like:
Code:

$ dependency_tree vim
vim (2:8.2.2434-3+deb11u1) Vi IMproved - enhanced vi editor
- vim-common (= 2:8.2.2434-3+deb11u1) Vi IMproved - Common files
  - xxd tool to make (or reverse) a hex dump
- vim-runtime (= 2:8.2.2434-3+deb11u1) Vi IMproved - Runtime files

If you compare that with "apt depends vim" or the online package page the differences are hopefully apparent.

Am I overlooking a tool that already provides something like that, or is it something I need to go build myself?


Nothing I know of. such a tree would be useful for some maintainers, developers, and a few system admins. Normal users would never need it.

If you make such a thing, let me know because I would love to see the code.

shruggy 02-10-2022 09:58 AM

Perhaps, apt-rdepends? It produces output similar to
Code:

apt -i --recurse -oAPT::Architectures=, \
  -oAPT::Cache::ShowOnlyFirstOr=true depends vim

but with less noise and can print some additional info:
Code:

apt-rdepends -p vim
aptitude search prints descriptions.

First level vim dependencies (packages vim directly depends on):
Code:

aptitude search '~rnative~R^vim$'
Second level vim dependencies (packages that packages from the previous list depend on):
Code:

aptitude search '~rnative~R~R^vim$'
Using explicit search targets one can construct very complex search expressions in aptitude. What is printed can be customized with -F.

Something you can achieve with apt-cache and dctrl-tools:
Code:

apt-cache -i --recurse -oAPT::Architectures=, \
  -oAPT::Cache::ShowOnlyFirstOr=true depends vim|
sed '1d;/^ /d'|
parallel grep-aptavail -dsPackage,Version,Description -\!XFArchitecture i386 -aXP|
tbl-dctrl

xargs -rn1 instead of parallel is also an option. It's even a requirement if you want to sort the output of sed by package name:
Code:

...|sed '1d;/^ /d'|sort|xargs -rn1 ...
If you don't like the default output of tbl-dctl then format it differently, e.g.
Code:

tbl-dctrl -Hd$'\t'|column -ts$'\t'
For installed packages, debfoster -d vim prints a list of everything vim depends on including dependencies of dependencies and so on.

To see what packages would be pulled in and installed automatically as dependencies of a package, I'd just use
Code:

aptitude -sy install vim
apt/apt-get -s is also possible, but they generate too much noise.

boughtonp 02-11-2022 08:00 AM


 
Thanks Shruggy, a lot of interesting+useful stuff there.

I had missed the --recurse option for apt/apt-cache before, but I think I need to do it manually to get the format I want anyway.

Aptitude search is nice and flexible - there have definitely been times in the past where that would have been handy - but for scripting use it's painfully slow.


Quote:

Originally Posted by wpeckham (Post 6327869)
Nothing I know of. such a tree would be useful for some maintainers, developers, and a few system admins. Normal users would never need it.

If you make such a thing, let me know because I would love to see the code.

I never claim to be normal, but my motivation was that of a user. I wanted to switch my Cinnamon desktop to Plasma; not wanting all the software that the tasksel method would have installed, I started looking at the packages involved, and realised there should be an easier way to see what brings in what.

Anyhow, I've been playing around with Python, but may switch it to Bash depending on how it turns out; either way I'll post when I've got something worth showing.


ondoho 02-11-2022 11:50 AM

You could have a look at the Pacman Rosetta page. It doesn't have exactly what you ask (pactree was my first thought), but a few good hints.

boughtonp 02-11-2022 12:26 PM


 
Thanks - I bookmarked that page last time you/someone mentioned it, thinking "that'll come in useful", only to then not even think to look at it. :(


shruggy 02-15-2022 05:18 AM

Not sure if and how they could fit in here, but I just remembered there are those dose3 and botch tools.
Code:

ls /var/lib/apt/lists/*Packages|sed 's#^#deb://#'|
xargs -r dose-ceve -c vim --deb-native-arch amd64 -T deb 2>/dev/null|
grep-dctrl -nsPackage ''|sort -u

The packages are $(apt-cache pkgnames dose-) and botch.

boughtonp 02-15-2022 09:02 AM


 
1 Attachment(s)
Here's the current version of script, but it's still a work in progress.

*sigh* LQ's stupid CloudFlare firewall blocked it, so get the attachment then "tar -xvf pkgtree.tgz.txt" to get the script.

It works on Debian 11, but not Debian 10 because it currently relies on the tree-formatting functionality of bsdextrautils/column which wasn't present in the earlier bsdmainutils/column.

(Wouldn't mind replacing that with something a bit better, but can't find if there's other similar tools because searching just brings up the annoyingly-named file-listing tree command, and not sure if it's worth the effort to write something.)

There's also a function for Yum in there (disconnected and not tested), which might work with RHELv8/compatible (v7 has the older column command).

Anyway, script is attached, here's a couple of quick examples...
Code:

$ ./pkgtree.sh vim
vim          Vi IMproved - enhanced vi editor    [editors] (7)
├─vim-common  Vi IMproved - Common files          [editors] (1)
│ └─xxd      tool to make (or reverse) a hex dump [editors] (1)
└─vim-runtime Vi IMproved - Runtime files          [editors] (1)

Code:

$ ./pkgtree.sh --maxdepth=2 task-kde-desktop
task-kde-desktop              KDE Plasma                                                  [tasks]        (4)
├─tasksel                    tool for selecting tasks for installation on Debian systems [admin]        (5)
├─task-desktop                Debian desktop environment                                  [tasks]        (5)
├─kde-standard                KDE Plasma Desktop and standard set of applications        [metapackages] (23)
│ ├─akregator                RSS/Atom feed aggregator                                    [web]          (55)
│ ├─ark                      archive utility                                            [utils]        (32)
│ ├─dragonplayer              simple video player                                        [video]        (26)
│ ├─gwenview                  image viewer                                                [graphics]    (49)
│ ├─juk                      music jukebox / music player                                [sound]        (34)
│ ├─kaddressbook              address book and contact data manager                      [utils]        (48)
│ ├─kate                      powerful text editor                                        [editors]      (47)
│ ├─kcalc                    simple and scientific calculator                            [math]        (19)
│ ├─kde-plasma-desktop        KDE Plasma Desktop and minimal set of applications          [metapackages] (5)
│ ├─kde-spectacle            Screenshot capture utility                                  [graphics]    (38)
│ ├─kmail                    full featured graphical email client                        [mail]        (114)
│ ├─knotes                    sticky notes application                                    [kde]          (65)
│ ├─korganizer                calendar and personal organizer                            [kde]          (76)
│ ├─kwalletmanager            secure password wallet manager                              [utils]        (27)
│ ├─okular                    universal document viewer                                  [graphics]    (50)
│ ├─plasma-dataengines-addons additional data engines for Plasma                          [kde]          (21)
│ ├─plasma-pa                Plasma 5 Volume controller                                  [kde]          (26)
│ ├─plasma-runners-addons    additional runners for Plasma 5 and Krunner                [kde]          (17)
│ ├─plasma-wallpapers-addons  additional wallpaper plugins for Plasma 5                  [kde]          (2)
│ ├─plasma-widgets-addons    additional widgets for Plasma 5                            [kde]          (47)
│ ├─polkit-kde-agent-1        KDE dialogs for PolicyKit                                  [kde]          (15)
│ └─sweeper                  history and temporary file cleaner                          [utils]        (19)
└─sddm                        modern display manager for X11                              [kde]          (19)
  ├─adduser                  add and remove users and groups                            [admin]        (2)
  ├─xauth                    X authentication utility                                    [x11]          (5)
  ├─x11-common                X Window System (X.Org) infrastructure                      [x11]          (1)
  ├─xserver-xorg              X.Org X server                                              [x11]          (5)
  └─debconf                  Debian configuration management system                      [admin]        (1)


shruggy 02-15-2022 10:26 AM

Quote:

Originally Posted by boughtonp (Post 6329795)
There's also a function for Yum in there (disconnected and not tested), which might work with RHELv8/compatible (v7 has the older column command).

I would suggest this:
Code:

function getPackageInfoDnf()
{
  rpm --quiet -q "$1" &&
    Status='ii ' cmd='rpm -q --qf'    nl='\n' ||
    Status='un ' cmd='dnf -q rq --qf' nl=
  $cmd "%{summary}\n\n$Status$nl" "$1"
  dnf -q rq --requires --resolve "$1"
}

I'd also replace apt-cache show ...|awk ... in getPackageInfo() with
Code:

grep-aptavail -dnsDescription,Section,Pre-Depends,Depends -\!XFArchitecture i386 -aXP "$1"|
sed "2a$Status"


boughtonp 02-15-2022 12:21 PM

Quote:

Originally Posted by shruggy (Post 6329831)
I would suggest this:
Code:

function getPackageInfoDnf()
{
  rpm --quiet -q "$1" &&
    Status='ii ' cmd='rpm -q --qf'    nl='\n' ||
    Status='un ' cmd='dnf -q rq --qf' nl=
  $cmd "%{summary}\n\n$Status$nl"
  dnf -q rq --requires --resolve "$1"
}


Thanks, I've just setup an AlmaLinux VM to test. Needed to add a "$1" on the penultimate line.

Annoyingly it takes about half a second per package, and the lack of any "section" field to filter on means it takes almost 4 minutes for "./pkgtree.sh vim-enhanced", because it iterates through over a hundred glibc langpack packages.


Quote:

I'd also replace apt-cache show ...|awk ... in getPackageInfo() with
Code:

grep-aptavail -dnsDescription,Section,Pre-Depends,Depends -\!XFArchitecture i386 -aXP "$1"|
sed "2a$Status"


That's also taking about half a second for a single record.

As does aptitude, pkcon, and even apt-cache if you use the "wrong" options - the first line of the awk is because "time apt-cache show perl" takes 0.08s whilst any option that gets it to return a single record makes it take over 0.52s :/


shruggy 02-15-2022 01:14 PM

Quote:

Originally Posted by boughtonp (Post 6329877)
Needed to add a "$1" on the penultimate line.

Ah sorry. I'll correct my post above.

Quote:

Originally Posted by boughtonp (Post 6329877)
Annoyingly it takes about half a second per package, and the lack of any "section" field to filter on means it takes almost 4 minutes for "./pkgtree.sh vim-enhanced", because it iterates through over a hundred glibc langpack packages.

Yeah. I think doing this with dnf/yum would be impractical. At least, dnf and repoquery can recurse:
Code:

dnf -q rq --requires --resolve --recursive <package_name>
and repoquery on CentOS 7 can even output a tree
Code:

repoquery -R --output ascii-tree <package_name>
but this not relevant to your use case.

Quote:

Originally Posted by boughtonp (Post 6329877)
the first line of the awk is because "time apt-cache show perl" takes 0.08s whilst any option that gets it to return a single record makes it take over 0.52s

I see. And dropping -X/--exact-match from grep-aptavail doesn't help either. Looks like apt-cache is the fastest option.


All times are GMT -5. The time now is 03:34 PM.