LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 02-10-2022, 09:30 AM   #1
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,616

Rep: Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554
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?


Last edited by boughtonp; 02-10-2022 at 09:33 AM.
 
Old 02-10-2022, 09:35 AM   #2
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS, Manjaro
Posts: 5,687

Rep: Reputation: 2715Reputation: 2715Reputation: 2715Reputation: 2715Reputation: 2715Reputation: 2715Reputation: 2715Reputation: 2715Reputation: 2715Reputation: 2715Reputation: 2715
Quote:
Originally Posted by boughtonp View Post
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.
 
Old 02-10-2022, 09:58 AM   #3
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
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.

Last edited by shruggy; 02-10-2022 at 02:12 PM.
 
1 members found this post helpful.
Old 02-11-2022, 08:00 AM   #4
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,616

Original Poster
Rep: Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554

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 View Post
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.


Last edited by boughtonp; 02-11-2022 at 08:30 AM.
 
Old 02-11-2022, 11:50 AM   #5
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
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.
 
1 members found this post helpful.
Old 02-11-2022, 12:26 PM   #6
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,616

Original Poster
Rep: Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554

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.

 
Old 02-15-2022, 05:18 AM   #7
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
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.

Last edited by shruggy; 02-15-2022 at 05:31 AM.
 
Old 02-15-2022, 09:02 AM   #8
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,616

Original Poster
Rep: Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554

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)
Attached Files
File Type: txt pkgtree.tgz.txt (1.9 KB, 4 views)

Last edited by boughtonp; 02-15-2022 at 09:03 AM.
 
1 members found this post helpful.
Old 02-15-2022, 10:26 AM   #9
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
Quote:
Originally Posted by boughtonp View Post
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"

Last edited by shruggy; 02-15-2022 at 01:14 PM. Reason: Forgot a parameter, see discussion below
 
Old 02-15-2022, 12:21 PM   #10
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,616

Original Poster
Rep: Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554
Quote:
Originally Posted by shruggy View Post
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 :/

 
1 members found this post helpful.
Old 02-15-2022, 01:14 PM   #11
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
Quote:
Originally Posted by boughtonp View Post
Needed to add a "$1" on the penultimate line.
Ah sorry. I'll correct my post above.

Quote:
Originally Posted by boughtonp View Post
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 View Post
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
non Recursive query and Recursive query prashsharma Linux - Server 1 06-27-2007 09:33 AM
How to do non-recursive Binary Tree LNR Traversing? Mr_Shameless Programming 3 04-29-2007 09:35 PM
recursive backup of hidden files cp -a /home/user1/,* goes up the tree Emmanuel_uk Linux - Newbie 5 02-25-2006 04:42 AM
the bible = the tree of the knowledge of good and evil () Jesus = the tree of life Michael111 General 2 04-14-2004 04:28 PM
need a P-Tree (Patricia Tree) library manaskb Programming 1 11-02-2002 06:15 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration