Commit graph jw-pkg/src/python/jw/pkg/cmds
Author SHA1 Message Date
d449472ceb
cmds.projects.lib.pkg_relations: Add module
BaseCmdPkgRelations contains pkg_relations(), a function doing
package graph analysis code. The function needs to be made available
to code outside BaseCmdPkgRelations, so move it to
cmds.projects.lib.pkg_relations.

The commit also applies style fixes to both BaseCmdPkgRelations and
pkg_relations which anticipate broader style changes to jw-pkg in
general.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-05-31 18:19:44 +02:00
3b65bcabb8
cmds.projects.CmdCreatePkgConfig: Use tmpl_render()
Use tmpl_render() to render the file template. Better for centralized
template definition.

The commit also applies style fixes to CmdCreatePkgConfig which
anticipate broader style changes to jw-pkg in general.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-05-31 18:19:39 +02:00
7edf5a4c26
cmds.projects.lib.templates: Add module
Add tmpl_render(), a function to provide a primitive template
renderer. It takes a dictionary for values to replace variables
shaped {some-variable} in templates found by their name. For now, the
templates are defined in the templates module instead of being read
from a template directory. The values may be lists, in which case
they are rendered with a delimiter, defaulting to ",".

Using an existing template engine like jinja2 is tempting but would
introduce additional dependencies jw-pkg is trying hard to avoid.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-05-31 17:52:20 +02:00
4e15552fc2
cmds.projects.lib: Add Module
Add a sub-module for code that's too specific to jw.pkg.cmds.projects
to go into jw.pkg.lib but too generic to go into a command module.

Long-term, it might be a good idea to create a place for code which
jw-pkg doesn't exclusively use for its own purposes. jw.lib, for
example. Then, liberated from the burden to be generally useful also
externally, jw.pkg.lib might be a better fit for code currently in
jw.pkg.cmds.xxx.lib, and a more natural place usable across
subcommands.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-05-31 17:52:20 +02:00
8697695697
CmdBase / cmds.projects.Cmd: Add modules
Lots of sub- and sub-subcommands are derived from the base class of
the invoking command, notably below cmds.projects. That provides some
properties shared across the ancestor hierarchy of a command, but is
semantically unsound. Introduce jw.pkg.BaseCmd class as a place to
provide basic helpers shared across all commands used in a
jw.pkg.App's context. Also add cmds.projects.Cmd to be used by other
commands in cmds.projects in later commits.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-05-31 17:52:20 +02:00
13ec34cc57
lib.init.detect_modules(): Add function
Not all __init__.py modules are generated by python-tools.sh, some
are needed early to make jw-pkg useful without generation, notably in
jw.pkg.cmds.

Add detect_modules() to unify that detection, and place it into a
minimal module lib.init to not increase startup time cost.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-05-31 17:52:20 +02:00
f6f6e56943
make / scripts: git.janware.com -> devgit.janware.com
janware upstream development server moved from git.janware.com to
devgit.janware.com. This commit follows the move with pretty much a
simple

	s/git.janware.com/devgit.janware.com/

over jw-pkg. It found 14 matches, that's pretty bad.

FIXME: Reduce the redundancy, or, better, replace the
devgit.janware.com goodies by a more generally useful concept
altogether.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-05-12 15:15:29 +02:00
c9b48880a9
cmds.pkg.CmdSelect: Fix argument order in select()
Argument ordering in the call to distro.select() is mixed up, the
filter is mistaken for names, fix that.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-05-02 07:19:41 +02:00
fc3ac69bd4
cmds.projects.CmdBuild: Don't change handled Exception
Exceptions raised by the build command are handled and changed,
messing up the stack trace. Re-raise the original exception from the
exception handler to fix that.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-05-02 06:59:24 +02:00
30abb227c7
lib.Cmd.print_help(): Add method
Add Cmd.print_help(). By default, it prints a help message. If passed
an integer exit_status, it also calls sys.exit(exit_status).

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-05-01 15:57:16 +02:00
7e2099877c
lib.Cmd.load_subcommands(): Add method
Push cmds.Cmd._add_subcommands() as lib.Cmd.load_subcommands() one
step up to the top of the type hierarchy ladder.

By default, it does the same thing, i.e. load subcommands matching
frobnicate.Cmd* if called on class CmdFrobnicate.

This commit also replaces invocations of Cmd._add_subcommands() by
invocations of this new method.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-05-01 15:56:08 +02:00
7dfe733865
cmds.secrets.lib.DistroContext.install(): Full archive
Make "secrets install" digest archives with a more elaborate layout.
It selects secrets from archives containing:

   default/path/to/secret.jw-secret
   com/janware/grautvornix/path/to/secret.jw-secret

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-04-28 13:00:30 +02:00
530efa1427
cmds.secrets.lib.tar: Add module
Add a module cmds.secrets.lib.tar. Secrets handling demands treating
tar archive members more individually, jw.pkg.lib.TarIo is not a good
fit for that, so try with a different module. To be merged
eventually.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-04-28 13:00:30 +02:00
d9746cd20b
lib + cmds.projects: Use lib.Uri
Remove the feeble attempts at unifying URI handling, and use class
Uri from lib.Uri instead.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-04-28 13:00:29 +02:00
f23c0560e5
cmds.secrets.lib.util.compile_template_file(): Fix
Fix broken call to FilesContext(ctx).compile_template_file() after
trying it out the first time.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-04-25 13:51:12 +02:00
a9475de48e
lib.ExecContext: Add open() + close() around _run()
Enclose ExecContext._run() in an open() / close() - pair. This is
convenient for the caller in that it doesn't need to take care of
opening and closing for one call only, and inconvenient in that it
forces the caller to conciously add an open() / close() - pair around
multiple run() calls where it wants the context to stay open in
between. Or use the ExecContext as a context manager.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-04-25 08:45:29 +02:00
3ac3aff997
lib: Fix silent assertitons
There are a couple of assert statements in the codebase which can
make jw-pkg fail without any detail whatsoever if --backtrace is not
specified, fix that.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-04-25 08:44:49 +02:00
120a6e4d34
cmds.secrets.CmdInstall: Add command
Support

   jw-pkg secrets install mypasswords.tar.gpg [package-1 [package-2 ...]]

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-04-24 16:53:55 +02:00
b88a8ee299
cmds.secrets.lib.DistroContext.install(): Add method
Add DistroContext.install(). It takes a tar file containing secrets,
decrypts it, and installs all secrets needed on target and present in
that file. For every file that should be extracted, it logs if it
acutally did something or didn't.

It also features an only_missing argument, which is just a stub for
"allow to define somy extraction policy with respect to replacing all
/ some / not replace / whatever. Not thought through.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-04-24 16:53:55 +02:00
db22f11b32
cmds.posix.tar.CmdExtract: Log number of extracted files
Add a little log line at execution end, saying how many files were
actually extracted.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-04-24 16:53:55 +02:00
f2ca32a343
CopyContext: Replace src_uri, dst_uri by src, dst
Allow to pass ready-made FileContext objects to CopyContext's
destructor so it doesn't need to instantiate them itself.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-04-24 16:53:55 +02:00
514d66dac1
cmds.distro.CmdInfo: Rename to cmds.platform.CmdInfo
Rename command "distro" to "pkg" together with "info", its last
remaining subcommand. "distro" is often used in the sense of "Linux
distribution", which would be too narrow for the targets jw-pkg could
theoretically support.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-04-24 16:53:55 +02:00
5830984bfc
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>
2026-04-24 16:53:55 +02:00
563ec7463a
cmds.secrets.Cmd: Fix type hints
cmds.secrets.Cmd has a CmdDistro-typed parent, should be CmdSecrets,
fix that.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-04-24 16:53:54 +02:00
7357092576
cmds.posix.Tar: Add command
Add a "jw-pkg posix tar" command. Currently the only thing that can
be done with it is extracting.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-04-23 20:18:42 +02:00
32c3477102
cmds.secrets.lib.DistroContext.list_template_files(): List more
Default to Distro's idea of relevant packages if no packages are
specified on the command line.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-04-21 21:52:10 +02:00
655b17bfec
cmds.secrets.lib.DistroContext: packages -> pkg_names
Cosmetics: The "packages" parameter to some DistroContext's methods
has a confusing name in same contexts, notably when mixed with a list
of Package instances, so rename it to "pkg_names".

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-04-21 21:52:10 +02:00
1646aaeb59
cmds.distro.CmdSelect: Use select(filter)
Ditch the CmdSelect.filter_packages(), because Distro.select() now
supports filtering out of the box.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-04-21 21:52:10 +02:00
b44879c517
lib.FileContext.file_exists(): Fix missing await
file_exists and _stat() in file_exists() are async, need to be
awaited, but aren't. Fix that.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-04-21 21:52:09 +02:00
aa7275f426 App.distro_xxx: Move properties to Distro.xxx
Commit a19679fec reverted the first attempt to make AsyncSSH reuse
one connection during an instance lifetime. That failed because a lot
of distribution-specific properties were filled in a new event loop
thread started by AsyncRunner, and AsyncSSH didn't like that.

This commit is the first part of the solution: Move those properties
from the App class to the Distro class, and load the Distro class
in an async loader. As soon as it's instantiated, it can provide all
its properties without cluttering the code with async keywords.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-04-19 21:00:21 +02:00
003d53b310 cmds.secrets.lib: Add missing bits
- cmds.secrets.lib.base: Add module

  - cmds.secrets.lib.util: Fix missing Attrs type

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-04-19 21:00:14 +02:00
54aecff8e4 lib.ExecContext.run(), .sudo(): Rename env
The name of the env parameter to ExecContext.run() and .sudo() is not
descriptive enough for which environment is supposed to be modified
and how, so rename and split it up as follows:

  - .run(): env -> mod_env

  - .sudo(): env -> mod_env_sudo and mod_env_cmd

The parameters have the following meaning:

  - "mod_env*" means that the environment is modified, not replaced

  - "mod_env" and "mod_env_cmd" modify the environment "cmd" runs in

  - "mod_env_sudo" modifies the environment sudo runs in

Fix the fallout of the API change all over jw-pkg.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-04-19 14:36:50 +02:00
1b821f3b3f cmds.secrets: Make commands work remotely
The "secrets" class of commands currently only works on the host it's
invoked on. Use the current FileContext to allow using the existing
commands on a target host.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-04-18 10:43:31 +02:00
fe3508036e lib.FileContext.put(): Change param mode type str -> int
Don't pass mode as a string to put(). Given the multitunde of
possible string representations for numbers, some understood by
int(string, 0) and some not, there's too much room for passing
strings which are unparseable, or worse, prone to be parsed wrongly.

However, pass mode down to _put() as a string for convenience,
because that's what most _put() implementations will need to use. If
they don't, converting to int is easy from the one defined string
format.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-04-18 10:43:31 +02:00
781393ad42 cmds.projects.ListRepos: Fix missing await
Fix

  CmdListRepos.py:51: RuntimeWarning: coroutine 'FileTransfer.close' was never awaited

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-04-16 16:11:45 +02:00
beab4cb03c cmds.distro.CmdInstall: Support macro expansion
Support macro expansion similar to CmdCopy paths in CmdInstall as
well.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-04-16 16:07:11 +02:00
b72c417510 cmds.posix.CmdCopy: Support platform macros
Expand platform macros (as in %{codename}) in the src and dst command
arguments. Expansion can be turned off by -F --fixed-strings.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-04-16 13:35:02 +02:00
ef21dc1b1e App.distro_info(): Add method
Add a method distro_info() to App, essentially providing CmdInfo's
macro-expansion of platform information to other interested code.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-04-16 13:25:37 +02:00
888c0495ec lib.base: Add module
Add lib.base to provide basic definitions.

For now, move the definiions of Result, Input and InputMode from
ExecContext into lib.base. Having to import them from the ExecContect
module is too heavy-handed for those simple types.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-04-16 12:57:04 +02:00
e811b2dc14 cmds.posix.CmdCopy: Add module
Add CmdCopy, designed to copy data from the filesystem to another
location in the filesystem. Not necessarily local file systems, the
URLs can be all URLs supported by ExecContext.run().

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-04-16 12:56:43 +02:00
16bb4e5bed cmds.CmdPosix: Add command
Add a new group of commands - "posix". The current command categories
are not a good fit for that: "projects" is for CI, "distro" is
distribution-specific for CD, and secrets is for handling secrets
specifically. Introduce the more general command group "posix", a
class of commands not POSIX compliant in the exposed API, but
primarily using POSIX utilities as workhorse.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-04-16 12:56:22 +02:00
1214451c15 lib.ExecContext.close(): Add method
Add ExecContext.close() as a hook to clean up async resources living
longer than an ExecContext method call.

Also, implement __aenter__() and __aexit__(), to allow using
ExecContext as context manager.  close() is invoked it goes out of
scope.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-04-16 10:21:25 +02:00
04b294917f lib.ExecContext: Support bytes-typed cmd_input
The Input instance passed as cmd_input to ExecContext.run() and
.sudo() currently may be of type str. Allow to pass bytes, too.

At the same time, disallow None to be passed as cmd_input. Force the
caller to be more explicit how it wants input to be handled, notably
with respect to interactivity.

Along the way fix a bug: Content in cmd_input should result in
CallContext.interactive == False but doesn't. Fix that.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-04-16 10:21:25 +02:00
281cdf4ec7 cmds.projects.CmdCanonicalizeRemotes: Add command
CmdCanonicalizeRemotes / canonicalize-remotes and the respective
target in topdir.mk remove the /srv/git portion from all remotes'
URLs pointing to git.janware.com.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-04-13 12:23:02 +02:00
5ad65f85fd cmds.secrets.lib.util: Add module
To be able to use secret handling code from other modules, move the
bulk of it from the "secrets"-command centric implementation in
cmds.secrets.Cmd into a new module cmds.secrets.lib.util.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-04-11 14:56:21 +02:00
98ad7442d9 cmds.projects.CmdListRepos: Beautify error logging
Call run_curl() with parse_json=True to make that explicit, and be a
little more verbose about the outcome.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-04-08 10:49:58 +02:00
5fded01d00 cmds.projects.CmdListRepos: Init SSHClient with app opts
Use the global --verbose and --interactive command-line options as
defaults for constructing a SSHClient instance for use with listing
repos over SSH.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-04-07 15:39:29 +02:00
40511947c9 cmds.projects.BaseCmdPkgRelations: Add --hide-jw-pkg
Support --hide-jw-pkg. This is a step towards replacing
required-os-pkg, which leaves out packages from pkg.requires.jw
sections.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-04-06 16:47:46 +02:00
ad0e03f14c cmds.projects.BaseCmdPkgRelations: Fix cross-sec deps
If a package P is added, only those of its dependendencies are added
along which are in the same os-cascade section as P. That's wrong,
fix it.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-04-06 16:02:34 +02:00
a0dcf59277 cmds.projects.BaseCmdPkgRelations: Better variables
Make variable names a little more readable and searchable within the
long pkg_relations_list() method by making their names longer and
truer to what they actually mean.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-04-06 16:02:34 +02:00