Commit graph

60 commits

Author SHA1 Message Date
7e7cee6d11 cmds.distro: Move all modules to lib
Functions abstracting the distribution are not only needed in the
context of the distro subcommand, but also by other code, so make the
bulk of the code abstracting the distribution available in some place
more universally useful than below cmds.distro.

This commit leaves the source files mostly unchanged. They are only
patched to fix import paths, so that functionality is preserved.
Refactoring the code from command-line API to library API will be
done by the next commit.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-03-06 12:06:28 +01:00
404901bcff cmds.distro.backend.debian.Util: Remove --fix-broken
--fix-broken is added to apt-get options in non-interactive mode, but
seems to work only with apt-get install, not with apt-get update.
Don't add it at all for now.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-03-04 16:39:39 +00:00
a25701991d distro.backend.debian.Refresh.run(): Fix apt_get()
Fix call to apt_get(), needs to be a list, not a string.
2026-03-04 16:30:43 +00:00
4eeb12c12e cmds.distro.backend.debian.Util.apt_get(): Fix -yes
Fix a typo in the non-interactive command-line option (--yes) passed
to apt_get().

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-03-04 16:16:20 +00:00
8ca8df859b cmds.distro.backend.debian.Delete: Add class
Add Debian supoort for single-package deletion.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-03-04 16:04:27 +00:00
a7293e0ac9 cmds.distro.backend.debian.Util.py: Add dpkg()
Add utility method .dpkg() to the backend.debian.Utils class, saving
the need to import it, saving the need to import it.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-03-04 16:04:27 +00:00
7e85076b44 cmds.distro.backend.debian.Install|Dup: Fix .apt_get()
.apt_get() is called on self, should be called on self.util instead,
fix that.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-03-04 16:04:27 +00:00
9e8f5e3d2e cmds.distro.backend.debian.Util.apt_get(): Take list
apt_get(), like all other functions and methods spawning processes
should take a list instead of a starred *args array. Implement that.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-03-04 16:04:27 +00:00
39ab1885e6 cmds.distro.backend.suse.Util.rpm(): Relay args
Relay *args and **kwargs unchanged to run_rpm(), no need to limit
them so far.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-03-04 16:02:44 +00:00
770920ef91 cmds.distro.CmdDelete: args.packages -> args.names
Rename the "packages" argument to "names" to be a little more
consistent with the pkg subcommand argument nomenclature.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-03-04 16:02:38 +00:00
0317f46a01 cmds.distro.pkg.CmdMeta: Add class
Support distro pkg meta <package names ...>, returning meta
information for the specified package names.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-03-04 14:56:11 +01:00
f55d3045e0 cmds.distro.backend.debian.Pkg: Add module
Add Debian support for the "pkg"-command.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-03-04 14:55:06 +01:00
2897ba849f cmds.distro.backend.debian.Select: Add class
Add Select for Debian backends.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-03-04 14:54:33 +01:00
7f72d17f7a cmds.distro.lib.dpkg: Add module
As with cmds.distro.lib.rpm, the dpkg module is a place for Python
abstractions of the Debian package manager tools dpkg and friends.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-03-04 14:53:14 +01:00
1bb3c166d6 cmds.distro.lib.rpm.query_packages(): Add function
Replace all_installed_packages() by query_packages(). The function
takes an optional list of packages to be queried. If it's empty, a
list of all installed packages are returned.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-03-04 14:52:14 +01:00
3e9ec1f6c5 cmds.distro.lib.Package: Add more methods
Add more methods, to make Package more useful:

  - __repr__()

  - Class-mMethods to help with parsing of strings gathered from the
    OS-tools' output:

      parse_spec_str()
      parse_specs_str()
      order_tags()

  - Add field maintainer

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-03-04 14:49:11 +01:00
ecd077c93d cmds.distro.CmdPkg: args.name -> names
Make all pkg commands take a "names" argument (plural) instead of
"name", and make it a non-option-argument, to be passed to the
subcomand instead.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-03-04 14:48:46 +01:00
888ea9979a jw.pkg.cmds.distro.CmdDup: Support --donwload-only
Add --download-only to the options of jw-pkg.py distro dup, which
makes the command only download packages from the repositories
without installing them.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-03-03 11:24:49 +01:00
6af16d2dca jw.pkg.cmds.distro.CmdInstall: Support --only-update
Passing --only-update should keep "jw-pkg.py distro install" from
installing packages that are not already installed on the the system.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-03-03 11:24:43 +01:00
79d40af558 jw.pkg.cmds.distro.CmdRebootRequired: Add class
Add the command distro.CmdRebootRequired, adding support for "distro
reboot-required". The command exits with status code 1 if a reboot is
required and 0 otherwise.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-03-03 11:24:22 +01:00
5d95ca01ca jw.pkg.cmds.distro.backend.suse.Util.zypper(): Add verbose
Add boolean parameter verbose to zypper(), causing the obvious.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-03-03 11:24:19 +01:00
fc1431ec48 jw.pkg.cmds.distro.backend.suse.Util.zypper(): Add sudo
Add boolean parameter sudo to zypper(), doing the obvious.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-03-03 11:24:15 +01:00
0b3f12866c jw.pkg.cmds.distro.backend.*._sudo(): Pass *args on
Pass *args and **kwargs on unchanged to run_sudo().

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-03-03 11:24:10 +01:00
565946643b jw.pkg.*.run_xxx(): Return exit status
Most run_xxx() return stdout and stderr. There's no way, really, for
the caller to get hold of the exit code of the spawned executable. It
can pass throw=true, catch, and assume a non-zero exit status. But
that's not semantically clean, since the spawned function can well be
a test function which is expected to return a non-zero status code,
and the caller might be interested in what code that was, exactly.

The clearest way to solve this is to return the exit code as well.
This commit does that.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-03-03 11:23:30 +01:00
03fca61248 jw.pkg.App.distro_id: Don't return opensuse
get-os.sh returned "suse" for SuSE-like distros, and that seems more
appropriate since SLES is not OpenSUSE but should share and ID with
other SuSE variants.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-03-03 05:11:59 +01:00
d22074abf9 jw.pkg.cmds.distro.Cmd._backend_path: Fix suse mapping
App.distro_id used to return "opensuse-tumbleweed", analogous to
what's in ID@/etc/os-release, but now returns "opensuse", and the
"tumbleweed" goes into "codename". That matches more what Debian-like
distributions do, but it confuses _backend_path. Adapt it to map the
new distro_id correctly.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-03-03 04:27:50 +01:00
e2e1b3388c jw.pkg.cmds.distro.CmdInfo: Add class
CmdInfo provides what "projects os-cascade" provided as "distro info
--format '%{cascade}'" plus additional macros: %{id}, %{name},
%{codename} and ${gnu-triplet}.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-03-02 12:55:36 +00:00
b81406e11a run_cmd() and friends: Make args a list[str]
This is a code maintenance commit: some run_xxx() helper functions
take a string, some a list, and some just digest all arguments and
pass them on as a list to exec() to be executed. That's highly
inconsistent. This commit changes that to list-only.

Except for the run_cmd() method of SSHClient, which is still run as a
shell method, because, erm, it's a shell. Might be changed in the
future for consistency reasons.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-02-27 09:09:10 +01:00
881a915098 jw/pkg/cmds/distro/CmdPkg: Add distro pkg ls
Add the distro subcommand class CmdPkg, together with a first
subcommand ls, which prints a list of files contained in a package.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-02-24 14:53:18 +01:00
aebd9bb5e6 jw.pkg.cmds.distro.lib.rpm.list_files(): Add function
Add a function list_files, which takes a package name and returns the
contained files in a list.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-02-24 14:53:17 +01:00
595995e084 jw.pkg.cmds: Replace split('\n') by splitlines()
splitlines() removes empty lines, so use it and save some lines of
code.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-02-24 14:53:05 +01:00
4153fa7c05 jw.pkg.cmds.distro.CmdDelete: Add command
Add command to delete named packages, along with an implementation
for OpenSUSE.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-02-18 01:20:26 +01:00
3ceb2b71b7 jw.pkg.cmds.distro.CmdSelect: Add command
Add the sub-command select to jw-pkg.py distro, along with an
Implementation for OpenSUSE.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-02-18 01:20:26 +01:00
81833e049a jw.pkg.cmds.distro.lib.rpm: Add module
Add a place to bundle utilities for RPM-backed distributions.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-02-18 01:20:26 +01:00
18747b8254 jw.pkg.cmds.distro.lib.Package: Add class
Add a package metadata abstraction.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-02-18 01:20:26 +01:00
6c98c9b650 jw.pkg.cmds.distro.lib: Add Module
Add a place to for distribution related utilities.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-02-18 01:20:26 +01:00
f991bbfcd9 jw.pkg.cmds.distro.backend.suse.Util.rpm(): Add method
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-02-18 01:20:26 +01:00
421e75fc91 jw.pkg.cmds.distro.backend.*.Util: Backend -> ..Util
Derive all jw.pkg.cmds.distro.backend.*.Util classes from the common
base class jw.pkg.cmds.distro.backend.Util.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-02-18 01:20:25 +01:00
3c8f57f636 jw.pkg.cmds.distro.backend.Util: Add class
Add a common base class for all jw.pkg.cmds.distro.backend.*.Util
classes.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-02-18 01:20:25 +01:00
7181849002 jw.pkg.cmds.distro.backend.*.*: Util -> BeXxx
Don't derive the Backend classes from distro-specifiy Util classes
anylonger, but from command-specific BeXxx base classes.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-02-18 01:20:25 +01:00
63395f414f jw.pkg.cmds.distro.backend.*.*: Use util
Don't call self.some_utility() anylonger, make it
self.util.some_utility().

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-02-18 01:20:25 +01:00
82e92ac068 jw.pkg.cmds.distro.backend.Backend: Add property util
Add a property .util to the Backend class, instanciated on demand
from to the respective distribution directory's Util class.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-02-18 01:20:25 +01:00
78835ecc9c jw.pkg.cmds.distro.Cmd: Add property util
Provide a property .util from Cmd, instanciated on demand from to the
respective distribution directory's Util class.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-02-18 01:20:25 +01:00
05f3f33931 jw.pkg.cmds.distro.backend.*.Base -> Util
Rename the class Base of all distribution backends to Util. It
contains distribution specifics, but is not going to be the base
class anymore shortly.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-02-18 01:20:25 +01:00
2cc3b59e75 jw.pkg.cmds.distro.backend.BackendCmd -> Backend
Rename jw.pkg.cmds.distro.backend.BackendCmd to Backend, because it's
not necessarily a command, i.e. doesn't necessarily have a run()
method. It's more of a distribution abstraction of the steps needed
for for a specific command, the run() method itself is implemented in
jw.pkg.cmds.distro.CmdXxx.

This commit is the beginning of a bigger move to change the
distribution backend class hierarchy. At the end of this change set,
the backend command should not derive the backend classes from a base
specific to the respective distribution, but from an abstract base
class specific to the command run. The distribution specifics are
then going to be encapsulated in another class called "Util", an
instance of which is going to be provided to the backend as .util
member.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-02-18 01:20:25 +01:00
b1d4e20295 jw.pkg.util: Add sudo()
Move the body of BackendCmd.sudo() into a function. The rationale
behind that is that its functionality is independent of the calling
object for the most part, so having it in a function instead of a
method is the more modular pattern.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-02-18 01:20:25 +01:00
bdb6ae69b3 apt-get install: Add --fix-broken to commandline
apt-get install suggests it wants to be called with -f to clean up
some mess left behind from a previous install. Adding -f in the hope
add it to the install options by default. OTOH, it wants to be called
that without arguments, not sure if always passing it along is a good
idea.

The man page says:

    -f, --fix-broken

   Fix; attempt to correct a system with broken dependencies in
   place. This option, when used with install/remove, can omit any
   packages to permit APT to deduce a likely solution. If packages
   are specified, these have to completely correct the problem. The
   option is sometimes necessary when running APT for the first time;
   APT itself does not allow broken package dependencies to exist on
   a system. It is possible that a system's dependency structure can
   be so corrupt as to require manual intervention (which usually
   means using dpkg --remove to eliminate some of the offending
   packages). Use of this option together with -m may produce an
   error in some situations. Configuration Item:
   APT::Get::Fix-Broken.

Also turn the short options -yq into long options --yes --quiet for
more obvious debugging if something goes awry.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-02-15 16:13:12 +00:00
2f49bc18d4 jw.pkg.cmds.distro.Cmd._backend: Support Kali Linux
If Kali Linux is detected as distribution, use the Debian backend for
package management.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-02-14 20:41:41 +01:00
0bc06b7c41 jw.pkg.cmds.distro.backend.BackendCmd: Add sudo(opts)
Prepending --login to the argument list of BackendCmd.sudo() fails if
run as root, because BackendCmd.sudo() detects that and leaves the
/usr/bin/sudo out from the exec call. Fix that by adding an
opts: list[str] parameter to sudo, defaulting to an empty list, with
options that should be passed to /usr/bin/sudo.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-02-14 09:20:24 +01:00
ffb84ad8c0 jw.pkg.cmds.distro.backend.Base: sudo --login
On OpenSUSE, run sudo with --login. This picks up a possible
ZYPP_CONF config variable definition in /etc/profile.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-02-12 20:38:12 +01:00