This commit is contained in:
debianpepper 2024-06-12 21:53:17 +09:00
commit 7523691696
1 changed files with 66 additions and 54 deletions

View File

@ -158,69 +158,69 @@ def get_terminal_emulator():
def get_gpu_info():
""" Get the GPU Information """
try:
output = subprocess.check_output(['lspci', '-nnk'],
universal_newlines=True)
gpu_lines = ([line.strip()
for line in output.split('\n') if 'VGA controller' in line])
if gpu_lines:
gpu_info = gpu_lines[0].split(': ', 1)[1]
result = subprocess.run(['lspci', '-nnk', '|', 'grep', '-i', 'vga', '-A3'], capture_output=True, text=True, shell=True)
if result.returncode == 0:
gpu_info = ""
lines = result.stdout.split('\n')
for line in lines:
if 'VGA' in line:
gpu_info = line.split(':')[2].strip()
break
return gpu_info
except (subprocess.CalledProcessError, FileNotFoundError) as _:
print(f"Error: {_}")
return "Unknown"
except Exception as e:
return f"Erro: {e}"
return "Desconhecido"
def get_memory_info():
memory_info = {}
try:
mem = psutil.virtual_memory()
memory_info['Total'] = f"{mem.total / (1024 ** 3):.2f} GB"
memory_info['Available'] = f"{mem.available / (1024 ** 3):.2f} GB"
memory_info['Used'] = f"{mem.used / (1024 ** 3):.2f} GB"
memory_info['Free'] = f"{mem.free / (1024 ** 3):.2f} GB"
except Exception as e:
return f"Erro: {e}"
return memory_info
# Function to get the desktop environment
def get_desktop_environment():
""" Get the Desktop being used """
desktop_session = os.environ.get("DESKTOP_SESSION")
if desktop_session:
desktop_session = desktop_session.lower()
if desktop_session in ["gnome", "unity", "cinnamon", "mate",
"xfce", "lxde", "lxqt", "kde-plasma", "deepin", "pantheon",
"i3"]:
return desktop_session.capitalize()
if "GNOME_DESKTOP_SESSION_ID" in os.environ:
return "Gnome"
if "MATE_DESKTOP_SESSION_ID" in os.environ:
return "Mate"
if "XDG_CURRENT_DESKTOP" in os.environ:
return os.environ["XDG_CURRENT_DESKTOP"].capitalize()
return "Unknown"
try:
de = os.getenv('XDG_CURRENT_DESKTOP') or os.getenv('DESKTOP_SESSION') or 'Unknown'
return de.lower()
except Exception as e:
return f"DE info not available ({e})"
# Function to get the version of the desktop environment
def get_version(d_e):
""" Get the Desktop versions """
commands = {
"Gnome": ["gnome-shell", "--version"],
"Kde-plasma": ["plasmashell", "--version"],
"Xfce": ["xfce4-session", "--version"],
"Lxde": ["lxpanel", "--version"],
"Lxqt": ["lxqt-session", "--version"],
"Cinnamon": ["cinnamon", "--version"],
"Mate": ["mate-session", "--version"],
"Unity": ["unity", "--version"],
"Deepin": ["deepin", "--version"],
"Pantheon": ["pantheon-session", "--version"],
"I3": ["i3", "--version"]
"gnome": ["gnome-shell", "--version"],
"kde-plasma": ["plasmashell", "--version"],
"xfce": ["xfce4-session", "--version"],
"lxde": ["lxpanel", "--version"],
"lxqt": ["lxqt-session", "--version"],
"cinnamon": ["cinnamon", "--version"],
"mate": ["mate-session", "--version"],
"unity": ["unity", "--version"],
"deepin": ["deepin", "--version"],
"pantheon": ["pantheon-session", "--version"],
"i3": ["i3", "--version"]
}
try:
output = subprocess.check_output(commands[d_e],
universal_newlines=True).strip().split('\n', maxsplit=1)[0]
version = output.split()[-1]
if d_e == "Xfce":
version = get_xfce_version()
elif d_e == "I3":
version = output.split()[-2]
return version
except subprocess.CalledProcessError:
return 'Failed to get display information (xdpyinfo command failed)'
except FileNotFoundError:
return 'xdpyinfo command not found'
except OSError as _:
return f'OS error: {_}'
return "unknown version"
output = subprocess.check_output(commands.get(d_e, ['echo', 'unknown version']), universal_newlines=True)
return output.strip().split('\n')[0].split()[-1] if d_e != 'xfce' else get_xfce_version()
except Exception as e:
return f"DE version info not available ({e})"
# Function to get XFCE version
def get_xfce_version():
try:
xfce_version = subprocess.check_output(['xfce4-session', '--version'], universal_newlines=True)
return xfce_version.split()[1]
except Exception as e:
return f"XFCE version info not available ({e})"
def get_xfce_version():
@ -341,6 +341,16 @@ def print_user_and_hostname():
print(f"{username}@{hostname}")
print("-" * len(f"{username}@{hostname}"))
def get_storage_info():
storage_info = {}
try:
disk = psutil.disk_usage('/')
storage_info['Total'] = f"{disk.total / (1024 ** 3):.2f} GB"
storage_info['Used'] = f"{disk.used / (1024 ** 3):.2f} GB"
storage_info['Free'] = f"{disk.free / (1024 ** 3):.2f} GB"
except Exception as e:
return f"Erro: {e}"
return storage_info
# These are the variables that run the functions
os_name = platform.system()
@ -364,6 +374,7 @@ os_full_information = f"{os_pretty} ({architecture})"
package_information = get_package_info()
shell_information = get_shell_info()
RESOLUTION_INFORMATION = get_display_info()
storage_information = get_storage_info()
# Determmine what Desktop evironment is being used
if desktop_environment == "gnome":
@ -396,7 +407,7 @@ bold_wt_text = f"{BOLD_START}WM Theme:{BOLD_END}"
bold_dt_text = f"{BOLD_START}Theme:{BOLD_END}"
bold_ic_text = f"{BOLD_START}Icons:{BOLD_END}"
bold_gpu_text = f"{BOLD_START}GPU:{BOLD_END}"
bold_storage_text = f"{BOLD_START}Storage:{BOLD_END}"
# Print the OS name and architecture
print_user_and_hostname()
@ -416,3 +427,4 @@ print(f"{bold_term_text} {terminal_emulator}")
print(f"{bold_cpu_text} {cpu_information}")
print(f"{bold_gpu_text} {gpu_information}")
print(f"{bold_mem_text} {mem_information}")
print(f"{bold_storage_text} {storage_information}")