add OS, Host, Kernel, Uptime, Boot time, pkgs, shell, arch information
This commit is contained in:
parent
a66b0a30b9
commit
3b225a4c7e
123
__main__.py
123
__main__.py
@ -1,5 +1,7 @@
|
|||||||
import time
|
import time
|
||||||
import sys, os, platform, socket, psutil, getpass, cpuinfo
|
from datetime import datetime
|
||||||
|
import sys, os, platform, socket, psutil, getpass, cpuinfo, lsb_release
|
||||||
|
import psutil._psutil_linux, subprocess
|
||||||
|
|
||||||
def getNameComponent(index):
|
def getNameComponent(index):
|
||||||
comp = {}
|
comp = {}
|
||||||
@ -12,40 +14,89 @@ def getNameComponent(index):
|
|||||||
|
|
||||||
return (" "*4) + comp[index]
|
return (" "*4) + comp[index]
|
||||||
|
|
||||||
def getHost():
|
def get_host():
|
||||||
return " "*4 + f"\033[0;36m{getpass.getuser()}\033[0m@\033[0;36m{socket.gethostname()}\033[1;35m"
|
return " "*4 + f"\033[0;36m{getpass.getuser()}\033[0m@\033[0;36m{platform.node()}\033[1;35m"
|
||||||
|
|
||||||
|
def get_product_name() -> str:
|
||||||
|
path_name = '/sys/devices/virtual/dmi/id/product_name'
|
||||||
|
path_ver = '/sys/devices/virtual/dmi/id/product_version'
|
||||||
|
|
||||||
|
if os.path.isfile(path_name) and os.path.isfile(path_ver):
|
||||||
|
product_name = open(path_name, 'r').read().strip()
|
||||||
|
product_version = open(path_ver, 'r').read().strip()
|
||||||
|
return f"{product_name} - {product_version}"
|
||||||
|
|
||||||
|
return "Not Supported"
|
||||||
|
|
||||||
|
def get_boottime() -> str:
|
||||||
|
uptimestp = psutil.boot_time()
|
||||||
|
uptime = datetime.fromtimestamp(uptimestp)
|
||||||
|
return f"{uptime.hour} Hours {uptime.minute} Mins"
|
||||||
|
|
||||||
|
def get_uptime():
|
||||||
|
f_uptime_raw = open('/proc/uptime').readline()
|
||||||
|
f_uptime_sec = float(f_uptime_raw.split()[0])
|
||||||
|
|
||||||
|
uptime = {}
|
||||||
|
uptime['hour'] = int(f_uptime_sec / 3600)
|
||||||
|
uptime['mins'] = int((f_uptime_sec % 3600) / 60)
|
||||||
|
|
||||||
|
return uptime
|
||||||
|
|
||||||
|
def get_packages():
|
||||||
|
packages = {}
|
||||||
|
packages['dpkg'] = int(subprocess.check_output('dpkg --list | wc -l', shell=True).strip()) - 1
|
||||||
|
packages['snap'] = int(subprocess.check_output('snap list --all | wc -l', shell=True).strip())
|
||||||
|
return packages
|
||||||
|
|
||||||
|
def get_shell():
|
||||||
|
return os.path.realpath(os.path.join('/proc/', str(os.getppid()), 'exe'))
|
||||||
|
|
||||||
|
def get_memory():
|
||||||
|
memory = psutil.virtual_memory()
|
||||||
|
mem = {}
|
||||||
|
mem['used'] = str(round(memory.used / 1024 ** 2)) + "MB"
|
||||||
|
mem['total'] = str(round(memory.total / 1024 ** 2)) + "MB"
|
||||||
|
mem['percent'] = str(memory.percent) + "%"
|
||||||
|
return mem
|
||||||
|
|
||||||
|
def get_os():
|
||||||
|
release = lsb_release.get_os_release()
|
||||||
|
return f"{release['DESCRIPTION']} [{release['CODENAME']}]"
|
||||||
|
|
||||||
def getSystemInfo():
|
def getSystemInfo():
|
||||||
uname = platform.uname()
|
uname = platform.uname()
|
||||||
|
|
||||||
memory = psutil.virtual_memory()
|
memory = get_memory()
|
||||||
memory_used = str(round(memory.used / 1024 ** 2)) + "MB"
|
|
||||||
memory_total = str(round(memory.total / 1024 ** 2)) + "MB"
|
|
||||||
|
|
||||||
info = {}
|
info = {}
|
||||||
info['system'] = uname.system
|
info['system'] = get_os()
|
||||||
info['kernel'] = uname.release
|
info['kernel'] = uname.release
|
||||||
info['version'] = uname.version
|
info['version'] = uname.version
|
||||||
|
info['shell'] = get_shell()
|
||||||
info['arch'] = uname.machine
|
info['arch'] = uname.machine
|
||||||
info['host'] = socket.gethostname()
|
info['host'] = get_product_name()
|
||||||
info['ip'] = socket.gethostbyname(socket.gethostname())
|
info['ip'] = socket.gethostbyname(socket.gethostname())
|
||||||
info['processor'] = cpuinfo.get_cpu_info()['brand_raw']
|
info['processor'] = cpuinfo.get_cpu_info()['brand_raw']
|
||||||
info['memory'] = f"{memory_used} / {memory_total}"
|
info['memory'] = f"{memory['used']} / {memory['total']} ({memory['percent']})"
|
||||||
|
info['uptime'] = f"{get_uptime()['hour']} Hour, {get_uptime()['mins']} Mins"
|
||||||
|
info['boottime'] = get_boottime()
|
||||||
|
info['packages'] = f"{get_packages()['dpkg']} [dpkg], {get_packages()['snap']} [snap]"
|
||||||
return info
|
return info
|
||||||
|
|
||||||
def printSystemInfo(name, key):
|
def printSystemInfo(name, key):
|
||||||
info = getSystemInfo()
|
info = getSystemInfo()
|
||||||
return " "*4 + f"\033[1;35m{name}: \033[0m{info[key]}\033[1;35m"
|
return " "*4 + f"\033[1;35m{name}: \033[0m{info[key]}\033[1;35m"
|
||||||
|
|
||||||
def getMotd():
|
def get_icon():
|
||||||
return f"""\033[1;35m
|
return f"""\033[1;35m
|
||||||
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣤⡶⠶⠿⠛⠛⠻⡶⠾⠟⠛⠛⠛⠻⠷⣦⣤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀{getHost()}
|
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣤⡶⠶⠿⠛⠛⠻⡶⠾⠟⠛⠛⠛⠻⠷⣦⣤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
|
||||||
⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⡾⠛⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠛⠷⣦⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀{getNameComponent(0)}
|
⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⡾⠛⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠛⠷⣦⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀
|
||||||
⠀⠀⠀⠀⠀⠀⠀⢀⣴⠟⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠙⢷⣄⠀⠀⠀⠀⠀⠀⠀{getNameComponent(1)}
|
⠀⠀⠀⠀⠀⠀⠀⢀⣴⠟⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠙⢷⣄⠀⠀⠀⠀⠀⠀⠀
|
||||||
⠀⠀⠀⠀⠀⠀⣰⡟⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠻⣧⠀⠀⠀⠀⠀⠀{getNameComponent(2)}
|
⠀⠀⠀⠀⠀⠀⣰⡟⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠻⣧⠀⠀⠀⠀⠀⠀
|
||||||
⠀⠀⠀⠀⠀⢰⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠹⣧⠀⠀⠀⠀⠀{getNameComponent(3)}
|
⠀⠀⠀⠀⠀⢰⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠹⣧⠀⠀⠀⠀⠀
|
||||||
⠀⠀⠀⠀⠀⣿⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢻⡆⠀⠀⠀⠀{getNameComponent(0)}
|
⠀⠀⠀⠀⠀⣿⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢻⡆⠀⠀⠀⠀
|
||||||
⠀⠀⠀⠀⢰⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣧⠀⠀⠀⠀{printSystemInfo('Processor', 'processor')}
|
⠀⠀⠀⠀⢰⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣧⠀⠀⠀⠀
|
||||||
⠀⠀⠀⠀⣾⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⠀⠀⠀⠀
|
⠀⠀⠀⠀⣾⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⠀⠀⠀⠀
|
||||||
⠀⠀⠀⢠⡿⠀⠀⠀⠀⢀⡆⠀⠀⠀⠀⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠀⠀⠀⠀⠀⠀⠀⠀⢻⡆⠀⠀⠀
|
⠀⠀⠀⢠⡿⠀⠀⠀⠀⢀⡆⠀⠀⠀⠀⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠀⠀⠀⠀⠀⠀⠀⠀⢻⡆⠀⠀⠀
|
||||||
⠀⠀⠀⣼⠇⠀⠀⠀⠀⢸⡇⠀⠀⠀⠀⣿⣇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠹⣧⡀⠀⠀⠀⠀⠀⠀⠘⣷⡀⠀⠀
|
⠀⠀⠀⣼⠇⠀⠀⠀⠀⢸⡇⠀⠀⠀⠀⣿⣇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠹⣧⡀⠀⠀⠀⠀⠀⠀⠘⣷⡀⠀⠀
|
||||||
@ -62,20 +113,42 @@ def getMotd():
|
|||||||
⠀⠀⠀⠀⠀⠀⠀⠙⠷⣦⣤⣀⣘⣷⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
|
⠀⠀⠀⠀⠀⠀⠀⠙⠷⣦⣤⣀⣘⣷⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
|
||||||
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠉⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
|
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠉⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
|
||||||
|
|
||||||
\033[0m
|
|
||||||
NolaOS v1.0.2-ginger
|
|
||||||
Copyright 2021 (c) Norman Andrians
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def run():
|
def fetch():
|
||||||
print("Starting Nola motd with fetch...")
|
icon_component = get_icon().splitlines()
|
||||||
|
fetch_component = icon_component
|
||||||
|
system_informations = [
|
||||||
|
get_host(),
|
||||||
|
getNameComponent(0),
|
||||||
|
getNameComponent(1),
|
||||||
|
getNameComponent(2),
|
||||||
|
getNameComponent(3),
|
||||||
|
getNameComponent(0),
|
||||||
|
printSystemInfo('OS', 'system'),
|
||||||
|
printSystemInfo('Host', 'host'),
|
||||||
|
printSystemInfo('Kernel', 'kernel'),
|
||||||
|
printSystemInfo('Uptime', 'uptime'),
|
||||||
|
printSystemInfo('Boot Time', 'boottime'),
|
||||||
|
printSystemInfo('Packages', 'packages'),
|
||||||
|
printSystemInfo('Shell', 'shell'),
|
||||||
|
printSystemInfo('Architecture', 'arch')
|
||||||
|
]
|
||||||
|
|
||||||
motd = getMotd()
|
for i in range(len(system_informations)):
|
||||||
|
fetch_component[i+1] = fetch_component[i+1] + system_informations[i]
|
||||||
|
|
||||||
|
return "\n".join(fetch_component)
|
||||||
|
|
||||||
|
def run():
|
||||||
|
print("Starting Nola fetch...")
|
||||||
|
print("Reading System information...")
|
||||||
|
|
||||||
|
texts = fetch()
|
||||||
|
|
||||||
os.system("clear")
|
os.system("clear")
|
||||||
|
|
||||||
for p in motd:
|
for p in texts:
|
||||||
print(p, end='')
|
print(p, end='')
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
time.sleep(0.00001)
|
time.sleep(0.00001)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user