-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·100 lines (74 loc) · 2.81 KB
/
main.py
File metadata and controls
executable file
·100 lines (74 loc) · 2.81 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/python3
import sys
from PySide6.QtGui import QIcon
from PySide6.QtWidgets import QApplication
from PySide6.QtQml import QQmlApplicationEngine
from PySide6.QtCore import QTimer
import psutil
import os
import platform
import subprocess
import getpass
## overview
def fetchUsername():
engine.rootObjects()[0].setProperty('username', getpass.getuser())
def fetchSystemInfo():
os_info = platform.system()
host = platform.node()
kernel = platform.release()
shell = os.environ.get('SHELL', 'Unknown shell')
desktop_env = os.environ.get('XDG_CURRENT_DESKTOP', 'Unknown DE')
systemfetch = f"OS {os_info}\nHost {host}\nKernel {kernel}\nShell {shell}\nDE {desktop_env}"
engine.rootObjects()[0].setProperty('systemfetch', systemfetch)
def fetchRAM():
result = subprocess.run(['free', '-m',], capture_output=True, text=True)
result = result.stdout.splitlines()[1].split()
total = int(result[2]) / 1024
used = int(result[1]) / 1024
memData = f"{total:.1f}/{used:.1f} GB"
engine.rootObjects()[0].setProperty('mem', memData)
def fetchCPUUsage():
engine.rootObjects()[0].setProperty('cpuData', f"{psutil.cpu_percent()}%")
def fetchDisk():
total_used = 0
total_capacity = 0
for partition in psutil.disk_partitions():
usage = psutil.disk_usage(partition.mountpoint)
total_used += usage.used
total_capacity += usage.total
total_percentage = (total_used / total_capacity) * 100 if total_capacity > 0 else 0
engine.rootObjects()[0].setProperty('diskUsageData', f"{total_percentage:.1f}%")
## cpu
def fetchCPUDetails():
result = subprocess.run(['lscpu', '-J'], check=True, capture_output=True, text=True)
engine.rootObjects()[0].setProperty('cpuJSON', result.stdout)
## ip
def fetchNetworkDetails():
result = subprocess.run(['ip', '-json', 'a'], check=True, capture_output=True, text=True)
engine.rootObjects()[0].setProperty('ipJSON', result.stdout)
## storage
def fetchLSBLK():
result = subprocess.run(['lsblk', '-f', '--json'], check=True, capture_output=True, text=True)
engine.rootObjects()[0].setProperty('lsblkJSON', result.stdout)
############################################
if __name__ == "__main__":
app = QApplication(sys.argv)
app.setWindowIcon(QIcon(os.path.dirname(os.path.realpath(__file__)) + "/" + "codex.png"))
engine = QQmlApplicationEngine()
engine.load(os.path.dirname(os.path.realpath(__file__)) + "/" + "App.qml")
if not engine.rootObjects():
sys.exit(-1)
timer = QTimer()
timer.setInterval(1000)
timer.timeout.connect(fetchRAM)
timer.timeout.connect(fetchCPUUsage)
timer.start()
fetchRAM()
fetchUsername()
fetchDisk()
fetchCPUUsage()
fetchSystemInfo()
fetchCPUDetails()
fetchNetworkDetails()
fetchLSBLK()
sys.exit(app.exec())