cmds.distro.CmdXxx: Rename to cmds.pkg.CmdXxx

With the exception of the "info" subcommand, nearly all of distro's
subcommands deal with package managing, so push them into their own
command category.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-04-24 11:04:22 +02:00
commit 5830984bfc
Signed by: Jan Lindemann
GPG key ID: 3750640C9E25DD61
15 changed files with 65 additions and 41 deletions

View file

@ -8,7 +8,7 @@ from .Cmd import Cmd as CmdBase
class CmdDistro(CmdBase): # export
def __init__(self, parent: App) -> None:
super().__init__(parent, 'distro', help="System package manager wrapper")
super().__init__(parent, 'distro', help="Miscellaneous platform-related comamnds")
self._add_subcommands()
def add_arguments(self, p: ArgumentParser) -> None:

View file

@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-
from argparse import ArgumentParser
from ..App import App
from .Cmd import Cmd as CmdBase
class CmdPkg(CmdBase): # export
def __init__(self, parent: App) -> None:
super().__init__(parent, 'pkg', help="System package manager wrapper")
self._add_subcommands()
def add_arguments(self, p: ArgumentParser) -> None:
super().add_arguments(p)

View file

@ -1,18 +0,0 @@
# -*- coding: utf-8 -*-
from argparse import Namespace, ArgumentParser
from .Cmd import Cmd
from ..CmdDistro import CmdDistro
class CmdPkg(Cmd): # export
def __init__(self, parent: CmdDistro) -> None:
super().__init__(parent, 'pkg', help="Show package information")
self._add_subcommands()
def add_arguments(self, parser: ArgumentParser) -> None:
super().add_arguments(parser)
async def _run(self, args: Namespace) -> None:
return await super()._run(args)

View file

@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from ...lib.Distro import Distro
from ..CmdPkg import CmdPkg
from ..Cmd import Cmd as Base
class Cmd(Base): # export
def __init__(self, parent: CmdPkg, name: str, help: str) -> None:
super().__init__(parent, name, help)

View file

@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
from argparse import Namespace, ArgumentParser
from .Cmd import Cmd
from ..CmdPkg import CmdPkg
class CmdDelete(Cmd): # export
def __init__(self, parent: CmdPkg) -> None:
super().__init__(parent, 'delete', help="Delete packages by name")
def add_arguments(self, parser: ArgumentParser) -> None:
super().add_arguments(parser)
parser.add_argument("names", nargs="*", help="Names of packages to be deleted")
async def _run(self, args: Namespace) -> None:
return await self.distro.delete(args.names)

View file

@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
from argparse import Namespace, ArgumentParser
from .Cmd import Cmd
from ..CmdPkg import CmdPkg
class CmdDup(Cmd): # export
def __init__(self, parent: CmdPkg) -> None:
super().__init__(parent, 'dup', help="Upgrade distribution")
def add_arguments(self, parser: ArgumentParser) -> None:
super().add_arguments(parser)
parser.add_argument('--download-only', default=False, action='store_true',
help='Only download packages from the repos, don\'t install them, yet')
async def _run(self, args: Namespace) -> None:
return await self.distro.dup(download_only=args.download_only)

View file

@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
from argparse import Namespace, ArgumentParser
from .Cmd import Cmd
from ..CmdPkg import CmdPkg
class CmdInstall(Cmd): # export
def __init__(self, parent: CmdPkg) -> None:
super().__init__(parent, 'install', help="Install the distribution's notion of available packages")
def add_arguments(self, parser: ArgumentParser) -> None:
super().add_arguments(parser)
parser.add_argument("names", nargs="*", help="Packages to be installed")
parser.add_argument('--only-update', default=False, action='store_true', help='Only update the listed packages, don\'t install them')
parser.add_argument('-F', '--fixed-strings', action='store_true',
help='Don\'t expand platform.expand_macros macros in <names>')
async def _run(self, args: Namespace) -> None:
names = names if args.fixed_strings else self.app.distro.expand_macros(args.names)
return await self.distro.install(names, only_update=args.only_update)

View file

@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
from argparse import Namespace, ArgumentParser
from .NamedPkgsCmd import NamedPkgsCmd as Base
from ..CmdPkg import CmdPkg
class CmdLs(Base): # export
def __init__(self, parent: CmdPkg) -> None:
super().__init__(parent, 'ls', help="List package contents")
def add_arguments(self, parser: ArgumentParser) -> None:
super().add_arguments(parser)
async def _run(self, args: Namespace) -> None:
for name in args.names:
print('\n'.join(await self.parent.distro.pkg_files(name)))

View file

@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
from argparse import Namespace, ArgumentParser
from .NamedPkgsCmd import NamedPkgsCmd as Base
from ..CmdPkg import CmdPkg
class CmdMeta(Base): # export
def __init__(self, parent: CmdPkg) -> None:
super().__init__(parent, 'meta', help="List package metadata")
def add_arguments(self, parser: ArgumentParser) -> None:
super().add_arguments(parser)
async def _run(self, args: Namespace) -> None:
packages = await self.distro.select(args.names)
for package in packages:
if len(args.names) > 1:
print(f'-- {name}')
print(package)

View file

@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
from argparse import Namespace, ArgumentParser
from .Cmd import Cmd
from ..CmdPkg import CmdPkg
class CmdRebootRequired(Cmd): # export
def __init__(self, parent: CmdPkg) -> None:
super().__init__(parent, 'reboot-required', help="Check whether the machine needs rebooting")
def add_arguments(self, parser: ArgumentParser) -> None:
super().add_arguments(parser)
async def _run(self, args: Namespace) -> None:
return await self.distro.reboot_required()

View file

@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
from argparse import Namespace, ArgumentParser
from .Cmd import Cmd
from ..CmdPkg import CmdPkg
class CmdRefresh(Cmd): # export
def __init__(self, parent: CmdPkg) -> None:
super().__init__(parent, 'refresh', help="Refresh the distribution's notion of available packages")
def add_arguments(self, parser: ArgumentParser) -> None:
super().add_arguments(parser)
async def _run(self, args: Namespace) -> None:
return await self.distro.ref()

View file

@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
from argparse import Namespace, ArgumentParser
import re
from ...lib.Package import Package
from ...lib.PackageFilter import PackageFilterString
from ..CmdPkg import CmdPkg
from .Cmd import Cmd
class CmdSelect(Cmd): # export
def __init__(self, parent: CmdPkg) -> None:
super().__init__(parent, 'select', help="Select packages by filter")
def add_arguments(self, parser: ArgumentParser) -> None:
super().add_arguments(parser)
parser.add_argument("filter", help="Package filter string")
async def _run(self, args: Namespace) -> None:
filter = PackageFilterString(args.filter) if args.filter else None
for p in await self.distro.select(filter):
print(p.name)

View file

@ -0,0 +1,5 @@
TOPDIR = ../../../../../..
PY_UPDATE_INIT_PY = false
include $(TOPDIR)/make/proj.mk
include $(JWBDIR)/make/py-mod.mk

View file

@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-
from argparse import Namespace, ArgumentParser
from .Cmd import Cmd as Base
from ..CmdPkg import CmdPkg as Parent
class NamedPkgsCmd(Base): # export
def __init__(self, parent: Parent, name: str, help: str) -> None:
super().__init__(parent, name, help)
def add_arguments(self, parser: ArgumentParser) -> None:
super().add_arguments(parser)
parser.add_argument('names', nargs='*', help='Package names')

View file

@ -0,0 +1,11 @@
import importlib, pkgutil
__all__ = []
for finder, module_name, ispkg in pkgutil.iter_modules(__path__):
if not module_name.startswith("Cmd"):
continue
module = importlib.import_module(f".{module_name}", __name__)
cls = getattr(module, module_name)
globals()[module_name] = cls
__all__.append(module_name)