Skip to content

Commit

Permalink
bootc: Implement the 'remove' subcommand
Browse files Browse the repository at this point in the history
Implement the 'remove' subcommand for the bootc plugin and add
documentation.  Most of the options for this subcommand will come from
global dnf command line option settings.  The only option not handled
is --os=OSNAME from rpm-ostree.

https://issues.redhat.com/browse/SWM-3098
  • Loading branch information
dcantrell committed Oct 17, 2024
1 parent a8ba817 commit b87851d
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 40 deletions.
19 changes: 14 additions & 5 deletions doc/bootc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ Arguments (bootc)
``bootc install [options] <pkg-spec>...``
Install one or more packages.

``bootc remove [options] <pkg-spec>...``
Remove one or more packages.

-------
Options
-------
Expand All @@ -38,26 +41,32 @@ All general DNF options are accepted, see `Options` in :manpage:`dnf(8)` for det
``--pending-exit-77``
If pending deployment available, exit 77 (valid on the status subcommand).

``--install PKG...``
Overlay an additional package (valid on the remove subcommand).

``--uninstall PKG...``
Remove overlayed additional package (valid on the install subcommand).

``--all``
Remove all overlayed additional packages (valid on the remove subcommand).

``-A``, ``--apply-live``
Apply changes to both pending deployment and running filesystem tree (valid on the install subcommand).

``--force-replacefiles``
Allow package to replace files from other packages (valid on the install subcommand).

``-r``, ``--reboot``
Initiate a reboot after operation is complete (valid on the install subcommand).
Initiate a reboot after operation is complete (valid on the install and remove subcommands).

``--allow-inactive``
Allow inactive package requests (valid on the install subcommand).
Allow inactive package requests (valid on the install and remove subcommands).

``--idempotent``
Do nothing if package already (un)installed (valid on the install subcommand).
Do nothing if package already (un)installed (valid on the install and remove subcommands).

``--unchanged-exit-77``
If no overlays were changed, exit 77 (valid on the install subcommand).
If no overlays were changed, exit 77 (valid on the install and remove subcommands).

``--peer``
Force a peer-to-peer connection instead of using the system message bus (valid on the status and install subcommands).
Force a peer-to-peer connection instead of using the system message bus (valid on the status, install, and remove subcommands).
87 changes: 52 additions & 35 deletions plugins/bootc.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class BootcCommand(dnf.cli.Command):

_BOOTC_ALIASES = {"update": "upgrade", "erase": "remove"}
_BOOTC_SUBCMDS = ["status"]
_BOOTC_SUBCMDS_PKGSPECS = ["install"]
_BOOTC_SUBCMDS_PKGSPECS = ["install", "remove"]
_BOOTC_SUBCMDS_ALL = _BOOTC_SUBCMDS + _BOOTC_SUBCMDS_PKGSPECS

_EXT_CMD = "rpm-ostree"
Expand Down Expand Up @@ -84,29 +84,43 @@ def set_argparser(parser):
action="store_true",
help=_("Allow package to replace files from other packages (install)"),
)

# these options are for 'remove'
parser.add_argument(
"--install",
nargs="+",
metavar="PKG",
action="store",
help=_("Overlay additional package(s) (remove)"),
)
parser.add_argument(
"--all",
action="store_true",
help=_("Remove all overlayed additional packages (remove)"),
)

# valid under multiple subcommands
parser.add_argument(
"-r",
"--reboot",
action="store_true",
help=_("Initiate a reboot after operation is complete (install)"),
help=_("Initiate a reboot after operation is complete (install, remove)"),
)
parser.add_argument(
"--allow-inactive",
action="store_true",
help=_("Allow inactive package requests (install)"),
help=_("Allow inactive package requests (install, remove)"),
)
parser.add_argument(
"--idempotent",
action="store_true",
help=_("Do nothing if package already (un)installed (install)"),
help=_("Do nothing if package already (un)installed (install, remove)"),
)
parser.add_argument(
"--unchanged-exit-77",
action="store_true",
help=_("If no overlays were changed, exit 77 (install)"),
help=_("If no overlays were changed, exit 77 (install, remove)"),
)

# valid under multiple subcommands
parser.add_argument(
"--peer",
action="store_true",
Expand All @@ -131,9 +145,7 @@ def configure(self):

# process subcommand arguments
if cmd == "status":
if self.opts.quiet:
self.extargs.append("-q")
elif self.opts.verbose:
if self.opts.verbose:
self.extargs.append("-v")
elif self.opts.json:
self.extargs.append("--json")
Expand All @@ -143,28 +155,48 @@ def configure(self):
self.extargs.append("-b")
elif self.opts.pending_exit_77:
self.extargs.append("--pending-exit-77")
elif self.opts.peer:
self.extargs.append("--peer")
elif self.opts.installroot:
self.extargs.append("--sysroot=%s" % self.opts.installroot)
elif cmd == "install":
if self.opts.cacheonly:
self.extargs.append("-C")
elif self.opts.downloadonly:
self.extargs.append("--download-only")
elif self.opts.uninstall:
for pname in self.opts.uninstall:
self.extargs.append("--uninstall=%s" % pname)
elif self.opts.apply_live:
self.extargs.append("-A")
elif self.opts.force_replacefiles:
self.extargs.append("--force-replacefiles")
elif cmd == "remove":
if self.opts.install:
for pname in self.opts.install:
self.extargs.append("--install=%s" % pname)
elif self.opts.all:
self.extargs.append("--all")

if cmd in ["status", "install", "remove"]:
if self.opts.quiet:
self.extargs.append("-q")
elif self.opts.installroot:
self.extargs.append("--sysroot=%s" % self.opts.installroot)
elif self.opts.peer:
self.extargs.append("--peer")
elif self.opts.assumeyes:

if cmd in ["install", "remove"]:
if self.opts.assumeyes:
self.extargs.append("-y")
elif self.opts.assumeno:
self.extargs.append("-n")
elif self.opts.cacheonly:
self.extargs.append("-C")
elif self.opts.downloadonly:
self.extargs.append("--download-only")
elif self.opts.releasever:
self.extargs.append
self.extargs.append("--releasever=%s" % self.opts.releasever)
elif self.opts.allow_inactive:
self.extargs.append("--allow-inactive")
elif self.opts.idempotent:
self.extargs.append("--idempotent")
elif self.opts.unchanged_exit_77:
self.extargs.append("--unchanged-exit-77")
elif self.opts.reboot:
self.extargs.append("-r")
elif len(self.opts.repos_ed) > 0:
enabled = set()
disabled = set()
Expand All @@ -182,21 +214,6 @@ def configure(self):
if len(list(disabled)) > 0:
for repo in list(disabled):
self.extargs.append("--disablerepo=%s" % repo)
elif self.opts.uninstall:
for pname in self.opts.uninstall:
self.extargs.append("--uninstall=%s" % pname)
elif self.opts.apply_live:
self.extargs.append("-A")
elif self.opts.force_replacefiles:
self.extargs.append("--force-replacefiles")
elif self.opts.reboot:
self.extargs.append("-r")
elif self.opts.allow_inactive:
self.extargs.append("--allow-inactive")
elif self.opts.idempotent:
self.extargs.append("--idempotent")
elif self.opts.unchanged_exit_77:
self.extargs.append("--unchanged-exit-77")

if cmd in self._BOOTC_SUBCMDS_PKGSPECS:
if self.opts.pkgspec is not None and len(self.opts.pkgspec) > 0:
Expand Down

0 comments on commit b87851d

Please sign in to comment.