31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
import re
|
|
|
|
|
|
def shorten(name: str) -> str:
|
|
"""Shorten a raw GPU device name (lspci / lact) for display.
|
|
|
|
Strips a trailing "(rev ...)" marker, then reformats by bracket
|
|
group: a name like "Renoir [Radeon Vega Series / ...]" becomes
|
|
"Renoir (Radeon Vega Series)"; a name with two or more groups (typical
|
|
for unbound PCI IDs, e.g. "[1002] Device [1586]") becomes
|
|
"first-group middle-text (last-group)"; anything else is truncated to
|
|
50 characters.
|
|
|
|
Args:
|
|
name: raw device name from lspci or lact.
|
|
|
|
Returns:
|
|
A display-friendly name.
|
|
"""
|
|
name = re.sub(r"\s*\(rev.*\)$", "", name).strip()
|
|
groups = re.findall(r"\[([^\]]+)\]", name)
|
|
if len(groups) >= 2:
|
|
brand = groups[0]
|
|
series = groups[-1].split(" / ")[0]
|
|
model = name.split("]", 1)[1].split("[", 1)[0].strip()
|
|
return f"{brand} {model} ({series})".strip()
|
|
if len(groups) == 1:
|
|
series = groups[0].split(" / ")[0]
|
|
model = name.split("[", 1)[0].strip()
|
|
return f"{model} ({series})".strip()
|
|
return name[:50]
|