1
0
Fork 1
mirror of https://gitlab.postmarketos.org/postmarketOS/pmbootstrap.git synced 2025-07-13 11:29:46 +03:00
pmbootstrap/pmb/helpers/status.py
Oliver Smith 0d320d0613
pmbootstrap status: rework (MR 2294)
Reimplement "pmbootstrap status" to be just a simple and useful status
overview. The previous version ran a bunch of checks every time, and
would fail on these even if pmaports was used for normal development:
  * "non-official" branch checked out in pmaports
  * pmaports.git is not clean

The information about aports.git was also considered not so useful upon
revisiting this command, since it is only used for "pmbootstrap
aportgen". Most users don't need this, and if the user runs this
command, it will tell if aports.git is outdated.

All of the above made the previous version unpleasant to use and I
suspect most people stopped using the command after trying it out a few
times and seeing the irrelevant but loud NOK complaints.

New version:

  $ pmbootstrap status
  Channel: edge (pmaports: master_staging_systemd)
  Device:  qemu-amd64 (x86_64, kernel: virt)
  UI:      console
  systemd: no (default for selected UI)

Old version (without --details it only shows NOK checks):

  $ pmbootstrap status --details
  [00:55:20] *** CONFIG ***
  [00:55:20] Device: qemu-amd64 (x86_64, "QEMU amd64")
  [00:55:20] Kernel: virt
  [00:55:20] User Interface: console
  [00:55:20]
  [00:55:20] *** GIT REPOS ***
  [00:55:20] Path: /home/user/.local/var/pmbootstrap/cache_git
  [00:55:20] - aports_upstream (master)
  [00:55:20] - pmaports (master)
  [00:55:20]
  [00:55:20] *** CHECKS ***
  [00:55:20] [OK ] Chroots zapped recently (or non-existing)
  [00:55:20] [OK ] aports_upstream: on official channel branch
  [00:55:20] [OK ] aports_upstream: workdir is clean
  [00:55:20] [OK ] aports_upstream: tracking proper remote branch 'origin/master'
  [00:55:20] [OK ] aports_upstream: up to date with remote branch
  [00:55:20] [OK ] aports_upstream: remote information updated recently (via git fetch/pull)
  [00:55:20] [OK ] pmaports: on official channel branch
  [00:55:20] [OK ] pmaports: workdir is clean
  [00:55:20] [OK ] pmaports: tracking proper remote branch 'origin/master'
  [00:55:20] [OK ] pmaports: up to date with remote branch
  [00:55:20] [OK ] pmaports: remote information updated recently (via git fetch/pull)
  [00:55:20]
  [00:55:20] NOTE: chroot is still active (use 'pmbootstrap shutdown' as necessary)
  [00:55:20] DONE!
2024-04-16 18:54:35 +00:00

58 lines
1.7 KiB
Python

# Copyright 2024 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import pmb.config
import pmb.config.workdir
import pmb.helpers.git
from argparse import Namespace
def print_status_line(key: str, value: str):
styles = pmb.config.styles
key = f"{styles['GREEN']}{key}{styles['END']}:"
padding = 17
print(f"{key.ljust(padding)} {value}")
def print_channel(args: Namespace) -> None:
pmaports_cfg = pmb.config.pmaports.read_config(args)
channel = pmaports_cfg["channel"]
# Get branch name (if on branch) or current commit
path = pmb.helpers.git.get_path(args, "pmaports")
ref = pmb.helpers.git.rev_parse(args, path, extra_args=["--abbrev-ref"])
if ref == "HEAD":
ref = pmb.helpers.git.rev_parse(args, path)[0:8]
if not pmb.helpers.git.clean_worktree(args, path):
ref += ", dirty"
value = f"{channel} (pmaports: {ref})"
print_status_line("Channel", value)
def print_device(args: Namespace) -> None:
kernel = ""
if pmb.parse._apkbuild.kernels(args, args.device):
kernel = f", kernel: {args.kernel}"
value = f"{args.device} ({args.deviceinfo['arch']}{kernel})"
print_status_line("Device", value)
def print_ui(args: Namespace) -> None:
print_status_line("UI", args.ui)
def print_systemd(args: Namespace) -> None:
yesno, reason = pmb.config.other.systemd_selected_str(args)
print_status_line("systemd", f"{yesno} ({reason})")
def print_status(args: Namespace) -> None:
""" :param details: if True, print each passing check instead of a summary
:returns: True if all checks passed, False otherwise """
print_channel(args)
print_device(args)
print_ui(args)
print_systemd(args)