Add hardware info in system
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import subprocess
|
||||
import os
|
||||
|
||||
|
||||
def _cmd(cmd: str) -> str:
|
||||
@@ -144,3 +145,44 @@ def disks() -> str:
|
||||
lines.append(f"{icon} {d} — {health}, 🌡 {temp}")
|
||||
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
def hardware() -> str:
|
||||
cpu_model = "n/a"
|
||||
try:
|
||||
with open("/proc/cpuinfo", "r") as f:
|
||||
for line in f:
|
||||
if line.lower().startswith("model name"):
|
||||
cpu_model = line.split(":", 1)[1].strip()
|
||||
break
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
mem_total = "n/a"
|
||||
swap_total = "n/a"
|
||||
try:
|
||||
with open("/proc/meminfo", "r") as f:
|
||||
for line in f:
|
||||
if line.startswith("MemTotal:"):
|
||||
mem_kb = int(line.split()[1])
|
||||
mem_total = f"{mem_kb / (1024**2):.2f} GiB"
|
||||
if line.startswith("SwapTotal:"):
|
||||
swap_kb = int(line.split()[1])
|
||||
swap_total = f"{swap_kb / (1024**2):.2f} GiB"
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
cores = os.cpu_count() or "n/a"
|
||||
uname = os.uname()
|
||||
|
||||
lines = [
|
||||
"🧱 Hardware",
|
||||
"",
|
||||
f"🧠 CPU: {cpu_model}",
|
||||
f"🧩 Cores: {cores}",
|
||||
f"💾 RAM: {mem_total}",
|
||||
f"🌀 Swap: {swap_total}",
|
||||
f"🧬 Arch: {uname.machine}",
|
||||
f"🐧 Kernel: {uname.release}",
|
||||
]
|
||||
return "\n".join(lines)
|
||||
|
||||
Reference in New Issue
Block a user