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 logging
|
||||||
from .helpers import mount
|
from .helpers import mount
|
||||||
from .helpers import other
|
from .helpers import other
|
||||||
|
from .helpers import status
|
||||||
from .core import Chroot, Config
|
from .core import Chroot, Config
|
||||||
from .core.context import get_context
|
from .core.context import get_context
|
||||||
from .commands import run_command
|
from .commands import run_command
|
||||||
|
@ -43,6 +44,8 @@ if version < (3, 10):
|
||||||
|
|
||||||
def print_log_hint() -> None:
|
def print_log_hint() -> None:
|
||||||
context = get_context(allow_failure=True)
|
context = get_context(allow_failure=True)
|
||||||
|
if context and context.details_to_stdout:
|
||||||
|
return
|
||||||
log = context.log if context else Config().work / "log.txt"
|
log = context.log if context else Config().work / "log.txt"
|
||||||
# Hints about the log file (print to stdout only)
|
# Hints about the log file (print to stdout only)
|
||||||
log_hint = "Run 'pmbootstrap log' for details."
|
log_hint = "Run 'pmbootstrap log' for details."
|
||||||
|
@ -128,10 +131,12 @@ def main() -> int:
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# Dump log to stdout when args (and therefore logging) init failed
|
# 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():
|
if "args" not in locals():
|
||||||
import logging as pylogging
|
import logging as pylogging
|
||||||
|
|
||||||
pylogging.getLogger().setLevel(logging.DEBUG)
|
pylogging.getLogger().setLevel(logging.DEBUG)
|
||||||
|
can_print_status = False
|
||||||
|
|
||||||
logging.info("ERROR: " + str(e))
|
logging.info("ERROR: " + str(e))
|
||||||
logging.info("See also: <https://postmarketos.org/troubleshooting>")
|
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"
|
"Find the latest version here: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/tags"
|
||||||
)
|
)
|
||||||
print(f"Your version: {__version__}")
|
print(f"Your version: {__version__}")
|
||||||
|
if can_print_status:
|
||||||
|
status.print_status()
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
|
@ -554,7 +554,7 @@ def lint(args: PmbArgs) -> None:
|
||||||
|
|
||||||
|
|
||||||
def status(args: PmbArgs) -> NoReturn:
|
def status(args: PmbArgs) -> NoReturn:
|
||||||
pmb.helpers.status.print_status(args)
|
pmb.helpers.status.print_status()
|
||||||
|
|
||||||
# Do not print the DONE! line
|
# Do not print the DONE! line
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
|
@ -65,7 +65,9 @@ def clone(name_repo: str) -> None:
|
||||||
open(fetch_head, "w").close()
|
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.
|
"""Run "git rev-parse" in a specific repository dir.
|
||||||
|
|
||||||
:param path: to the git repository
|
: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"
|
or (with ``--abbrev-ref``): the branch name, e.g. "master"
|
||||||
"""
|
"""
|
||||||
command = ["git", "rev-parse"] + extra_args + [revision]
|
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()
|
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))
|
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."""
|
"""Check if there are not any modified files in the git dir."""
|
||||||
command = ["git", "status", "--porcelain"]
|
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]:
|
def list_remotes(aports: Path) -> list[str]:
|
||||||
|
|
|
@ -5,7 +5,6 @@ import pmb.config.other
|
||||||
import pmb.config.workdir
|
import pmb.config.workdir
|
||||||
import pmb.helpers.git
|
import pmb.helpers.git
|
||||||
from pmb.core import Config
|
from pmb.core import Config
|
||||||
from pmb.types import PmbArgs
|
|
||||||
from pmb.core.context import get_context
|
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
|
# Get branch name (if on branch) or current commit
|
||||||
path = pmb.helpers.git.get_path("pmaports")
|
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":
|
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"
|
ref += ", dirty"
|
||||||
|
|
||||||
value = f"{channel} (pmaports: {ref})"
|
value = f"{channel} (pmaports: {ref})"
|
||||||
|
@ -52,7 +51,7 @@ def print_systemd(config: Config) -> None:
|
||||||
print_status_line("systemd", f"{yesno} ({reason})")
|
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
|
""":param details: if True, print each passing check instead of a summary
|
||||||
:returns: True if all checks passed, False otherwise"""
|
:returns: True if all checks passed, False otherwise"""
|
||||||
config = get_context().config
|
config = get_context().config
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue