Skip to content

Commit dae4251

Browse files
Create main.py
1 parent 1fadd33 commit dae4251

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

main.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env python3
2+
import socket
3+
import getpass
4+
import platform
5+
import os
6+
import psutil
7+
import subprocess
8+
9+
# Get distro name
10+
def get_distro_name():
11+
try:
12+
with open("/etc/os-release") as f:
13+
for line in f:
14+
if line.startswith("PRETTY_NAME="):
15+
return line.strip().split("=")[1].strip('"')
16+
except FileNotFoundError:
17+
return None
18+
19+
# Find amount of packages
20+
def get_package_count():
21+
managers = {
22+
"pacman": "pacman -Q",
23+
"dpkg": "dpkg -l | grep '^ii'",
24+
"rpm": "rpm -qa",
25+
"apk": "apk info",
26+
"xbps-query": "xbps-query -l",
27+
"pkg": "pkg info"
28+
}
29+
30+
for cmd, query in managers.items():
31+
if subprocess.call(f"which {cmd}", shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) == 0:
32+
try:
33+
output = subprocess.check_output(query + " | wc -l", shell=True)
34+
return int(output.strip())
35+
except Exception:
36+
return None
37+
return None
38+
39+
pkg_count = get_package_count()
40+
41+
42+
print(f"Distro: {get_distro_name()}")
43+
print(f"Hostname: {socket.gethostname()}")
44+
print(f"User: {getpass.getuser()}")
45+
print(f"Kernel: {platform.system()} {platform.release()}")
46+
if pkg_count is not None:
47+
print(f"Packages: {pkg_count}")
48+
else:
49+
print("Packages: Unknown")
50+
print(f"PyFetch Version: 1.0.0 Lite")
51+
print(f"CPU: {os.uname().machine}")
52+
print(f"RAM: {round(psutil.virtual_memory().total / (1024**3), 2)} GB")

0 commit comments

Comments
 (0)