rpm-software-management / dnf5

Next-generation RPM package management system
Other
241 stars 83 forks source link

ENH,REQ: dnf install --json #1799

Open westurner opened 3 hours ago

westurner commented 3 hours ago

ENH,REQ,STORY: Users can show the (space-indented (by default) or JSON) recursive list of packages that will be installed with a CLI option to dnf install like --pkgtrees or --deplist and also --json

# TC1: In order to install vim-enhanced in a ~devcontainer,
#      install all of these packages *without installing X (libX*)* and tracker-miners, etc:

# setUp() {
#   # echo "FROM fedora-toolbox:41" >> Dockerfile
#
#   dnf install -y toolbox
#   toolbox create -i fedora-toolbox:41 -n dnftest && toolbox enter dnftest
# 
#   dnf install -y distrobox
#   distrobox create -i fedora-toolbox:41 -n dnftest && distrobox enter dnftest 
# }

pkgs="vim-enhanced powerline-fonts fzf python3-virtualenv ruff black python3-pyflakes python3-flake8 python3-lsp-server python3-jupyter-lsp"
sudo dnf install $pkgs
# ...
# Transaction Summary:
# Installing:      343 packages
# Upgrading:         2 packages
# Replacing:         2 packages

## To determine which pkgspec passed to dnf install is resulting in X being installed:
for pkg in $pkgs; do (set -x; dnf install --assumeno "${pkg}"); done
#  Downsides:
#  - $pkgs is not correctly quoted; it probably should be `IFS=" " read args; for arg in "${args[@]}"`
#  - This simulates installing each package independently, not all at once
#  - This has to open and close the database for each command invocation

dnf repoquery --help | grep queryformat

## To *approximate* dnf install with repoquery --qf="depends, requires, suggests, supplements"
for pkg in $pkgs; do (set -x; dnf repoquery --queryformat='## Depends\n%{depends}## Requires\n%{requires}## Suggests\n%{suggests}## Supplements\n%{supplements}\n' "${pkg}"); done
#  Downsides:
#  - this isn't JSON, you must parse the pkgspecs, are they?
#  - this doesn't optionally list the 'suggests' and 'supplements' only if those flags were passed

# Ideally, there would be simple cli opt like --tree or --deplist
# that shows the (space-indented or json) recursive list of packages that will be installed;
# something like:

dnf install --show-recursive-dependency-list-first [ --json [-o <dnf.log.json>]] 

dfn install --deplist --json [-o <dnf.log.json>]] 

dnf install --deplist
dnf install --json     # could imply --deplist  # or whatever the opt should be called
westurner commented 2 hours ago

Here's how to read the trasaction json files with the dnf history command in dnf4: