-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
52 lines (43 loc) · 1.59 KB
/
utils.py
File metadata and controls
52 lines (43 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import signal
import sys
from typing import Final, List, Optional
from types import FrameType
from rich.console import Console
from rich.panel import Panel
console: Final[Console] = Console()
def _signal_handler(_signum: int, _frame: Optional[FrameType]) -> None:
console.print()
console.print(Panel.fit(
"[red]✗[/red] Installation interrupted by user",
border_style = "red"
))
console.print("[yellow]Exiting gracefully...[/yellow]")
sys.exit(130)
def setup_signal_handlers():
signal.signal(signal.SIGINT, _signal_handler)
signal.signal(signal.SIGTERM, _signal_handler)
def format_execution_time(execution_time: float) -> str:
if execution_time < 60:
return f"{execution_time:.1f} seconds"
else:
minutes = int(execution_time // 60)
seconds = execution_time % 60
return f"{minutes}m {seconds:.1f}s"
def display_error_summary(errors: List, console: Console) -> None:
if not errors:
return
console.print()
console.print(Panel.fit(
f"[red]✗[/red] {len(errors)} error(s) occurred during installation",
border_style = "red"
))
errors_by_section = {}
for error in errors:
section = error.section_name or "Unknown"
if section not in errors_by_section:
errors_by_section[section] = []
errors_by_section[section].append(error)
for section_name, section_errors in errors_by_section.items():
console.print(f"\n[bold red]Section: {section_name}[/bold red]")
for error in section_errors:
console.print(f" {error}")