forked from Mirror/pmbootstrap
show the status output on failure (MR 2472)
There is a lot of context and state management needed when using pmbootstrap, sometimes it can be a lot to keep in your head. Let's print the output of "pmbootstrap status" when stuff goes wrong, this might help remind people if e.g. their pmaports checkout is on the wrong branch, or they're building for the wrong device. Additionally, don't print the "run pmbootstrap log for details" message if pmbootstrap was called with --details-to-stdout Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
This commit is contained in:
parent
3b4b9cd061
commit
39235fedfb
4 changed files with 18 additions and 10 deletions
|
@ -19,6 +19,7 @@ from .helpers import frontend
|
|||
from .helpers import logging
|
||||
from .helpers import mount
|
||||
from .helpers import other
|
||||
from .helpers import status
|
||||
from .core import Chroot, Config
|
||||
from .core.context import get_context
|
||||
from .commands import run_command
|
||||
|
@ -43,6 +44,8 @@ if version < (3, 10):
|
|||
|
||||
def print_log_hint() -> None:
|
||||
context = get_context(allow_failure=True)
|
||||
if context and context.details_to_stdout:
|
||||
return
|
||||
log = context.log if context else Config().work / "log.txt"
|
||||
# Hints about the log file (print to stdout only)
|
||||
log_hint = "Run 'pmbootstrap log' for details."
|
||||
|
@ -128,10 +131,12 @@ def main() -> int:
|
|||
|
||||
except Exception as e:
|
||||
# Dump log to stdout when args (and therefore logging) init failed
|
||||
can_print_status = get_context(allow_failure=True) is not None
|
||||
if "args" not in locals():
|
||||
import logging as pylogging
|
||||
|
||||
pylogging.getLogger().setLevel(logging.DEBUG)
|
||||
can_print_status = False
|
||||
|
||||
logging.info("ERROR: " + str(e))
|
||||
logging.info("See also: <https://postmarketos.org/troubleshooting>")
|
||||
|
@ -144,6 +149,8 @@ def main() -> int:
|
|||
"Find the latest version here: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/tags"
|
||||
)
|
||||
print(f"Your version: {__version__}")
|
||||
if can_print_status:
|
||||
status.print_status()
|
||||
return 1
|
||||
|
||||
return 0
|
||||
|
|
|
@ -554,7 +554,7 @@ def lint(args: PmbArgs) -> None:
|
|||
|
||||
|
||||
def status(args: PmbArgs) -> NoReturn:
|
||||
pmb.helpers.status.print_status(args)
|
||||
pmb.helpers.status.print_status()
|
||||
|
||||
# Do not print the DONE! line
|
||||
sys.exit(0)
|
||||
|
|
|
@ -65,7 +65,9 @@ def clone(name_repo: str) -> None:
|
|||
open(fetch_head, "w").close()
|
||||
|
||||
|
||||
def rev_parse(path: Path, revision: str = "HEAD", extra_args: list = []) -> str:
|
||||
def rev_parse(
|
||||
path: Path, revision: str = "HEAD", extra_args: list = [], silent: bool = False
|
||||
) -> str:
|
||||
"""Run "git rev-parse" in a specific repository dir.
|
||||
|
||||
:param path: to the git repository
|
||||
|
@ -75,7 +77,7 @@ def rev_parse(path: Path, revision: str = "HEAD", extra_args: list = []) -> str:
|
|||
or (with ``--abbrev-ref``): the branch name, e.g. "master"
|
||||
"""
|
||||
command = ["git", "rev-parse"] + extra_args + [revision]
|
||||
rev = pmb.helpers.run.user_output(command, path)
|
||||
rev = pmb.helpers.run.user_output(command, path, output="null" if silent else "log")
|
||||
return rev.rstrip()
|
||||
|
||||
|
||||
|
@ -90,10 +92,10 @@ def can_fast_forward(path: Path, branch_upstream: str, branch: str = "HEAD") ->
|
|||
raise RuntimeError("Unexpected exit code from git: " + str(ret))
|
||||
|
||||
|
||||
def clean_worktree(path: Path) -> bool:
|
||||
def clean_worktree(path: Path, silent: bool = False) -> bool:
|
||||
"""Check if there are not any modified files in the git dir."""
|
||||
command = ["git", "status", "--porcelain"]
|
||||
return pmb.helpers.run.user_output(command, path) == ""
|
||||
return pmb.helpers.run.user_output(command, path, output="null" if silent else "log") == ""
|
||||
|
||||
|
||||
def list_remotes(aports: Path) -> list[str]:
|
||||
|
|
|
@ -5,7 +5,6 @@ import pmb.config.other
|
|||
import pmb.config.workdir
|
||||
import pmb.helpers.git
|
||||
from pmb.core import Config
|
||||
from pmb.types import PmbArgs
|
||||
from pmb.core.context import get_context
|
||||
|
||||
|
||||
|
@ -23,11 +22,11 @@ def print_channel(config: Config) -> None:
|
|||
|
||||
# Get branch name (if on branch) or current commit
|
||||
path = pmb.helpers.git.get_path("pmaports")
|
||||
ref = pmb.helpers.git.rev_parse(path, extra_args=["--abbrev-ref"])
|
||||
ref = pmb.helpers.git.rev_parse(path, extra_args=["--abbrev-ref"], silent=True)
|
||||
if ref == "HEAD":
|
||||
ref = pmb.helpers.git.rev_parse(path)[0:8]
|
||||
ref = pmb.helpers.git.rev_parse(path, silent=True)[0:8]
|
||||
|
||||
if not pmb.helpers.git.clean_worktree(path):
|
||||
if not pmb.helpers.git.clean_worktree(path, silent=True):
|
||||
ref += ", dirty"
|
||||
|
||||
value = f"{channel} (pmaports: {ref})"
|
||||
|
@ -52,7 +51,7 @@ def print_systemd(config: Config) -> None:
|
|||
print_status_line("systemd", f"{yesno} ({reason})")
|
||||
|
||||
|
||||
def print_status(args: PmbArgs) -> None:
|
||||
def print_status() -> None:
|
||||
""":param details: if True, print each passing check instead of a summary
|
||||
:returns: True if all checks passed, False otherwise"""
|
||||
config = get_context().config
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue