Skip to content

Commit

Permalink
feat: improve lifecycle messages
Browse files Browse the repository at this point in the history
Signed-off-by: Sergio Schvezov <sergio.schvezov@canonical.com>
  • Loading branch information
sergiusens committed Oct 31, 2023
1 parent c7dc7da commit 9977439
Showing 1 changed file with 52 additions and 41 deletions.
93 changes: 52 additions & 41 deletions snapcraft/parts/parts.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@

import pathlib
import subprocess
import types
from typing import Any, Dict, List, Optional, Set

import craft_parts
from craft_archives import repo
from craft_cli import emit
from craft_parts import ActionType, Part, ProjectDirs, Step
from craft_parts import Action, ActionType, Part, ProjectDirs, Step
from craft_parts.packages import Repository
from xdg import BaseDirectory # type: ignore

Expand Down Expand Up @@ -171,8 +172,7 @@ def run(

self._install_package_repositories()

emit.progress("Executing parts lifecycle...")

emit.progress("Initialising lifecycle")
with self._lcm.action_executor() as aex:
for action in actions:
# Workaround until canonical/craft-parts#540 is fixed
Expand All @@ -185,11 +185,10 @@ def run(
project_vars=action.project_vars,
properties=action.properties,
)
message = _action_message(action)
emit.progress(f"Executing parts lifecycle: {message}")
with emit.open_stream("Executing action") as stream:
message = _get_parts_action_message(action)
emit.progress(message)
with emit.open_stream(message) as stream:
aex.execute(action, stdout=stream, stderr=stream)
emit.progress(f"Executed: {message}", permanent=True)

if shell_after:
launch_shell()
Expand Down Expand Up @@ -298,42 +297,54 @@ def launch_shell(*, cwd: Optional[pathlib.Path] = None) -> None:
subprocess.run(["bash"], check=False, cwd=cwd)


def _action_message(action: craft_parts.Action) -> str:
msg = {
Step.PULL: {
ActionType.RUN: "pull",
ActionType.RERUN: "repull",
ActionType.SKIP: "skip pull",
ActionType.UPDATE: "update sources for",
},
Step.OVERLAY: {
ActionType.RUN: "overlay",
ActionType.RERUN: "re-overlay",
ActionType.SKIP: "skip overlay",
ActionType.UPDATE: "update overlay for",
ActionType.REAPPLY: "reapply",
},
Step.BUILD: {
ActionType.RUN: "build",
ActionType.RERUN: "rebuild",
ActionType.SKIP: "skip build",
ActionType.UPDATE: "update build for",
},
Step.STAGE: {
ActionType.RUN: "stage",
ActionType.RERUN: "restage",
ActionType.SKIP: "skip stage",
},
Step.PRIME: {
ActionType.RUN: "prime",
ActionType.RERUN: "re-prime",
ActionType.SKIP: "skip prime",
},
ACTION_MESSAGES = types.MappingProxyType(
{
Step.PULL: types.MappingProxyType(
{
ActionType.RUN: "Pulling",
ActionType.RERUN: "Repulling",
ActionType.SKIP: "Skipping pull for",
ActionType.UPDATE: "Updating sources for",
}
),
Step.OVERLAY: types.MappingProxyType(
{
ActionType.RUN: "Overlaying",
ActionType.RERUN: "Re-overlaying",
ActionType.SKIP: "Skipping overlay for",
ActionType.UPDATE: "Updating overlay for",
ActionType.REAPPLY: "Reapplying",
}
),
Step.BUILD: types.MappingProxyType(
{
ActionType.RUN: "Building",
ActionType.RERUN: "Rebuilding",
ActionType.SKIP: "Skipping build for",
ActionType.UPDATE: "Updating build for",
}
),
Step.STAGE: types.MappingProxyType(
{
ActionType.RUN: "Staging",
ActionType.RERUN: "Restaging",
ActionType.SKIP: "Skipping stage for",
}
),
Step.PRIME: types.MappingProxyType(
{
ActionType.RUN: "Priming",
ActionType.RERUN: "Repriming",
ActionType.SKIP: "Skipping prime for",
}
),
}
)

message = f"{msg[action.step][action.action_type]} {action.part_name}"

def _get_parts_action_message(action: Action) -> str:
"""Get a user-readable message for a particular craft-parts action."""
message = f"{ACTION_MESSAGES[action.step][action.action_type]} {action.part_name}"
if action.reason:
message += f" ({action.reason})"

return message + f" ({action.reason})"
return message

0 comments on commit 9977439

Please sign in to comment.