run_cmd() with cmd_input == mode:interactive and verbose == true logs output too often. First, __log() is called, then pty.spawn() writes everything it reads from the PTY master to the terminal.
The fix it to not call __log() from _read() for the PTY reader.
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.
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.
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.
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.
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.
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.
CmdInfo provides what "projects os-cascade" provided as "distro info --format '%{cascade}'" plus additional macros: %{id}, %{name}, %{codename} and ${gnu-triplet}.
Support --remote-owner-base in the command CmdGetAuthInfo. Make it return what currently --remote-base returned: A URL including the user / organization specific prefix of the Git remote's URL that jw-pkg was pulled from.
Rename the --from-user option to --from-owner. Forgejo supports users and organizations under the more general term "owner", so that's the better term.
list-repos tries /users/ and /orgs/ to find a working repo URL in a Forgejo instance, logs a failure and doesn't log anything if it finds one that works. In the context, that can be mildly confusing, beautify the output somewhat.
base-url is not used as a prefix in its entirety, but massaged in a janware-specific way. Still is, but at least this commit is a step towards being more generic.
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.
Deduce module search path for the calling module's subcommands directly from the module path of the calling module. That's more generic than the previous detection algorithm, because it recursively works for subcommands of subcommands as well.
jw.pkg.lib.Cmd._run() is abstract, but it's nice to give it a default implementation which calls self.parent._run() in case parent is also a command class. That allows for some default processing in _run() for each node up the parent chain.
The children / derived classes just need to make sure all classes in the hierarchy do:
async def _run(self, args):
return await super()._run(args)
... add main command logic here ..
Add a function get_profile_env(), a function returning environment variables from /etc/profile. Pass add=True to add its contents to the existing environment dictionary, overwriting old entries, or pass False to get the pristine content.
Add a parameter "output_encoding" to run_cmd(). The parameter allows the caller to specify if the output encoding should be detected as is by passing None (the default), if the output should be returned as undecoded bytes by passing the special string "bytes", or if the output should be treated as the encoding with the specified name and decoded to strings.