added adaptive quickshell
This commit is contained in:
1 parent
6eb56d2065
commit
5b33a73fd8
189 files changed
+8678
-15
No files matched your search
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Read-only system overview. Never execute user-provided commands."""
|
||||
import json
|
||||
import os
|
||||
import platform
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def os_release(path='/etc/os-release'):
|
||||
result = {}
|
||||
try:
|
||||
for line in Path(path).read_text(encoding='utf-8').splitlines():
|
||||
if '=' not in line or line.startswith('#'):
|
||||
continue
|
||||
key, value = line.split('=', 1)
|
||||
if key in ('PRETTY_NAME', 'NAME', 'VERSION_ID'):
|
||||
result[key] = value.strip().strip('"')
|
||||
except OSError:
|
||||
pass
|
||||
return result
|
||||
|
||||
|
||||
def memory_kib(path='/proc/meminfo'):
|
||||
values = {}
|
||||
try:
|
||||
for line in Path(path).read_text(encoding='utf-8').splitlines():
|
||||
key, _, val = line.partition(':')
|
||||
if key in ('MemTotal', 'MemAvailable'):
|
||||
values[key] = int(val.strip().split()[0])
|
||||
except (OSError, ValueError, IndexError):
|
||||
pass
|
||||
return values
|
||||
|
||||
|
||||
def uptime_seconds(path='/proc/uptime'):
|
||||
try:
|
||||
return max(0, int(float(Path(path).read_text().split()[0])))
|
||||
except (OSError, ValueError, IndexError):
|
||||
return 0
|
||||
|
||||
|
||||
def snapshot():
|
||||
release = os_release()
|
||||
memory = memory_kib()
|
||||
return {
|
||||
'os': release.get('PRETTY_NAME') or release.get('NAME') or 'Linux',
|
||||
'kernel': platform.release(),
|
||||
'architecture': platform.machine(),
|
||||
'hostname': platform.node(),
|
||||
'memoryTotalMiB': memory.get('MemTotal', 0) // 1024,
|
||||
'memoryAvailableMiB': memory.get('MemAvailable', 0) // 1024,
|
||||
'uptimeSeconds': uptime_seconds(),
|
||||
}
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(json.dumps(snapshot(), ensure_ascii=False))
|
||||
Reference in new issue
Block a user