Commit graph

292 commits

Author SHA1 Message Date
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
2d08c2a12d jw.pkg.App.os_cascade: Add more fields

Add more fields to the OS cascade returned by App.os_cascade, based on the ID field in /etc/os-release. This includes some new ones, prefixed by pkg-, revealing which package format is used.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-02-15 16:13:21 +00:00
26e739ca0d src.python.jw.pkg.App: Add property distro_id

Add @property App.distro_id, returning the ID field of /etc/os-release. It is supposed to be the most specific part of the OS cascade.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-02-15 16:13:21 +00: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
a967924102 jw.pkg.App: Add property projs_root

projs_root is used read-only by CmdBuild and CmdModules, so add that property back.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-02-14 20:59:23 +01:00
75041d5505 src/python/jw/pkg/cmds/CmdDistro: Fix ID regex

The ID regex on /etc/os-release also matches ID_LIKE, which is obviously nonsense. Fix that.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-02-14 20:58:33 +01: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
060ff5159b jw.pkg.cmds.projects.CmdGetAuthInfo: Fix run_cmd()

CmdGetAuthInfo calls run_cmd() with a list instead of a *-expanded list of arguments. Fix this to match the current run_cmd() prototype.

And think again if the current prototype conforms to the priciple of least surprise: Most exec- / run- / whatever- functions do expect ether a string to be run by the shell, or an argv list.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-02-14 19:18:48 +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
d50a33d9ab jw.pkg.cmds.lib.Cmd: Define run()

Define run(), which calls _run() in the abstract base class Cmd, not in lib.Cmd. Otherwise lib.Cmd is not abstract, which will predictably confuse including code outside of jw-pkg.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-02-10 10:00:46 +01:00
eaa38113bb jw.pkg.App.get_libname(): Fix typo

get_project_refs() is invoked with projects_only=true, which should read names_only. Fix that.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-02-04 16:00:45 +01:00
a55dd8175c jw.pkg.cmds.projects.CmdProjectDir: Fix warning typo

Trying to find the directory of a project should log a warning. It throws an exception instead. Fix that.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-02-02 15:56:19 +01:00
53ba9e6fbe lib.App: Stay functional without autocomplete

If Python's autocomplete is not installed, jw-pkg.py fails to run commands. Fix that in order stay compatible with minimal excecution environments.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-02-02 12:15:41 +01:00
e075e8902b jw.pkg.cmds.CmdDistro: Default --interactive to true

Better safe than sorry: If things are to happen unattendedly, enforce the need to explicitly request that.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-29 11:32:32 +01:00
6ca4af77d7 jw.pkg.App: Code beautification

Major - but not yet sufficient - code beautification starting from jw.pkg.App.

- Make more methods private - Rename methods to be more self-explanatory - Same for method arguments, notably clean up some inconsistent uses of "module" vs "project" - Add more type hints

Fix API breakage in the command modules.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-29 11:32:14 +01:00
2bbf5bd8e7 jw.pkg.cmds.projects.CmdRequiredOsPkg: Support --quote

--quote puts double quotation marks around the listed dependencies, protecting version requirements (>= 1.0) and parenthesis "perl(GD)" from the shell.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-29 11:28:17 +01:00
26bfda109c cmds.projects.CmdListRepos: Try Forgejo users and orgs

A "username" in jw-pkg terms, as in $(CLONE_FROM_USER), is not sufficient to identify a remote API URL on a Forgejo server, it can denote both an organization and a user, so try organizations first, then users, and stop on the first occasion found.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-28 18:11:10 +01:00
45af308ae6 jw.pkg.cmds.distro.backend.arch: Add Module

Add Arch backend for pacman-based package management.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-28 18:11:09 +01:00
f6a8b6307a jw.pkg.cmds.distro.backend.redhat: Add Module

Add backend for YAM-based package management, as used by RHEL, Fedora, CentOS.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-28 18:11:09 +01:00
3ca544a32d jw.pkg.cmds.distro.backend.suse: Add Module

Add backend code for package managing on OpenSUSE Tumbleweed, Slowroll, LEAP, SLES and SLED.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-28 18:11:09 +01:00
58e56648d2 jw.pkg.cmds.distro.backend.debian: Add Module

Add backend code for Debian-like package managing.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-28 18:11:09 +01:00
674e51a7b2 jw.pkg.cmds.distro.backend: Add module

Add directory to host distro backends.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-28 18:11:09 +01:00
0b6fb48485 jw.pkg.cmds.distro.CmdDup: Add Module

Add CmdDup, the class providing the "jw-pkg.py distro dup" subcommand.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-28 18:11:09 +01:00
6e3fec0bec jw.pkg.cmds.distro.CmdInstall: Add module

Add CmdRefresh, the class providing the "jw-pkg.py distro install" subcommand.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-28 18:11:09 +01:00
6a5e5aaf0d jw.pkg.cmds.distro.CmdRefresh: Add command

Add CmdRefresh, the class providing the "jw-pkg.py distro refresh" subcommand.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-28 18:11:09 +01:00
d0311560da jw.pkg.cmds.distro: Add __init__.py

Add a hand-coded __init__.py into jw.pkg.cmds.distro. Auto-generation works fine, but has to run before it can work. For a freshly downloaded toplevel Makefile / project-dirs-minimal.mk, the targets pkg-install-xxx-deps requires a working package manager without jw-pkg built.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-28 18:11:09 +01:00
ad45ee8510 jw.pkg.cmds.distro: Add directory

Add the subdirectory structure for the distro subcommand.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-28 18:08:48 +01:00
53601c8abd jw.pkg.cmds.projects.CmdListRepos: Remove test code

Remove --insecure from curl invocation on janware.test.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-28 17:44:28 +01:00
4274a71c62 lib.util.run_cmd(): Rewrite it to be async

run_cmd() is synchronous. Now that all commands are asynchronous, we can await it, so rewrite it to be asynchronous, too.

Other changes:

- Make it return stderr as well in case its needed

- Drop into a pseuto-tty if - cmd_input == "mode:interactive" or - cmd_input == "mode:auto" and stdin is a TTY
- Add argument env, defaulting to None. If it's a dict, it will be the environment the command is run in

This entails making all functions using run_cmd() async, too, including run_curl(), get_username() and get_password().

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-28 17:41:40 +01:00
9c06103a4a cmds.project.*: Make _run() async

Cmd._run(), as conceived for working with lib.App, is meant to be an async method. To be conservative about changes, jw-pkg's legacy way of handling _run() was kept when deriving from libApp, and async was not propagated down to the _run() implementations. This commit rectifies that before adding additional subcommands.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-28 17:41:10 +01:00
f175f9d5c9 lib.Cmd: Add argument "parent" to __init__()

During __init__(), commands have no idea of their parent. This is not a problem as of now, but is easy to fix, and it's architecturally desirable to be prepared just in case, so add the parent argument to the ctor before more commands are added.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-28 15:24:24 +01:00
f6ed191d73 jw.pkg.App.get_modules_from_project_txt(): Add Scope

Add the Enum "Scope" to denote the scope argument of jw.pkg.App.get_modules_from_project_txt(), because it explains itself better than an integer.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-26 17:58:23 +01:00
bf4834085e jw.pkg.App: Annotate add_modules_from_project_txt()

Type-annotate add_modules_from_project_txt()'s parameter list.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-26 17:58:23 +01:00
5cdc32abd7 jw.pkg.App: Add lru_cache where possible

ResultCache is a home-grown result cache. The @lru_cache decorator, now available in Python 3, accomplishes the same thing, so try to ditch ResultCache for it.

Sadly, this doesn't entirely work as of now, because it uses hash() to hash the arguments, which won't work for the two list-type arguments to add_modules_from_project_txt() (buf and visited).

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-26 17:58:23 +01:00
a377745e5e jw.pkg.App: Make member variables private

With the exception of top_name, which cmds.project.GetVal needs read-access to, all member variables of jw.pkg.App can be made private.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-26 17:58:23 +01:00
917f56a814 CmdBuild: Don't use App.res_cache()

App.res_cache should be private. It's needed here to cache the results of a function which is private to CmdBuild anyway, so solve that with lru_cache, to allow App to do it's private thing with caching.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-26 17:58:23 +01:00
eafed6434b CmdBuild: Don't use App.dep_cache

App.dep_cache is only used by CmdBuild, prepare for removing it from App.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-26 17:58:23 +01:00
95fa2f0d06 jw.pkg.App: Remove .debug() and friends

Replace the jw.pkg.App.debug(), .warn() and .err() methods by the global log() function. There's no obvious benefit in having App know what's logged.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-26 17:58:23 +01:00
aefe983920 jw.pkg.App: Support --topdir-format

Add support for --topdir-format. The option supports several different values, affecting the console output of App wherever it knows that the output contains a reference to the projects' toplevel directory.

- "unaltered" will have it print the toplevel directory in the same format as passed to the commandline
- "absolute" will try to resolve it to an absolute path before printing

- make:XXX will return the make-varible $(XXX) instead

To implement this, the proj_dir() member function is turned into the private member function __proj_dir(), and a new member function find_dir() is supplied, with two additional parameters: search_subdirs and search_absdirs, which will try to find an existing directory relative to the toplevel directory of the given module, or in the search_absdirs list, respectively.

Command modules in cmds.projects have been updated to use the new function.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-26 17:58:23 +01:00
0b83c863a2 jw.build.cmds: Move build.cmds -> cmds.projects

Reorganize the Python module structure. Placing the command classes under jw.cmds.projects instead of jw.build.cmds will allow to add a nested command structure, with the current commands, being mostly related to building software, found below a "projects" toplevel command.

Other conceivable commands could be "package" for packaging, or "distro" for commands wrapping the distribution's package manager.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-26 17:58:23 +01:00
c8c5788aeb jw.pkg.App.proj_dir(): Return absolute path

Make App.proj_dir() return an absolute path. This looks like a good idea, because some of the $(call proj_query xxx) paths end up being relative, because they get proj_dir()'s idea of a directory prepended. This prohibits caching them in $(TOPDIR)/make/.cache.mk for make benefit glorious nation of performance.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-26 17:58:23 +01:00