update pfetch.py
This commit is contained in:
parent
20f1b0646b
commit
aba55a0945
|
@ -158,69 +158,69 @@ def get_terminal_emulator():
|
||||||
|
|
||||||
|
|
||||||
def get_gpu_info():
|
def get_gpu_info():
|
||||||
""" Get the GPU Information """
|
|
||||||
try:
|
try:
|
||||||
output = subprocess.check_output(['lspci', '-nnk'],
|
result = subprocess.run(['lspci', '-nnk', '|', 'grep', '-i', 'vga', '-A3'], capture_output=True, text=True, shell=True)
|
||||||
universal_newlines=True)
|
if result.returncode == 0:
|
||||||
gpu_lines = ([line.strip()
|
gpu_info = ""
|
||||||
for line in output.split('\n') if 'VGA controller' in line])
|
lines = result.stdout.split('\n')
|
||||||
if gpu_lines:
|
for line in lines:
|
||||||
gpu_info = gpu_lines[0].split(': ', 1)[1]
|
if 'VGA' in line:
|
||||||
|
gpu_info = line.split(':')[2].strip()
|
||||||
|
break
|
||||||
return gpu_info
|
return gpu_info
|
||||||
except (subprocess.CalledProcessError, FileNotFoundError) as _:
|
except Exception as e:
|
||||||
print(f"Error: {_}")
|
return f"Erro: {e}"
|
||||||
return "Unknown"
|
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():
|
def get_desktop_environment():
|
||||||
""" Get the Desktop being used """
|
try:
|
||||||
desktop_session = os.environ.get("DESKTOP_SESSION")
|
de = os.getenv('XDG_CURRENT_DESKTOP') or os.getenv('DESKTOP_SESSION') or 'Unknown'
|
||||||
if desktop_session:
|
return de.lower()
|
||||||
desktop_session = desktop_session.lower()
|
except Exception as e:
|
||||||
if desktop_session in ["gnome", "unity", "cinnamon", "mate",
|
return f"DE info not available ({e})"
|
||||||
"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"
|
|
||||||
|
|
||||||
|
|
||||||
|
# Function to get the version of the desktop environment
|
||||||
def get_version(d_e):
|
def get_version(d_e):
|
||||||
""" Get the Desktop versions """
|
|
||||||
commands = {
|
commands = {
|
||||||
"Gnome": ["gnome-shell", "--version"],
|
"gnome": ["gnome-shell", "--version"],
|
||||||
"Kde-plasma": ["plasmashell", "--version"],
|
"kde-plasma": ["plasmashell", "--version"],
|
||||||
"Xfce": ["xfce4-session", "--version"],
|
"xfce": ["xfce4-session", "--version"],
|
||||||
"Lxde": ["lxpanel", "--version"],
|
"lxde": ["lxpanel", "--version"],
|
||||||
"Lxqt": ["lxqt-session", "--version"],
|
"lxqt": ["lxqt-session", "--version"],
|
||||||
"Cinnamon": ["cinnamon", "--version"],
|
"cinnamon": ["cinnamon", "--version"],
|
||||||
"Mate": ["mate-session", "--version"],
|
"mate": ["mate-session", "--version"],
|
||||||
"Unity": ["unity", "--version"],
|
"unity": ["unity", "--version"],
|
||||||
"Deepin": ["deepin", "--version"],
|
"deepin": ["deepin", "--version"],
|
||||||
"Pantheon": ["pantheon-session", "--version"],
|
"pantheon": ["pantheon-session", "--version"],
|
||||||
"I3": ["i3", "--version"]
|
"i3": ["i3", "--version"]
|
||||||
}
|
}
|
||||||
try:
|
try:
|
||||||
output = subprocess.check_output(commands[d_e],
|
output = subprocess.check_output(commands.get(d_e, ['echo', 'unknown version']), universal_newlines=True)
|
||||||
universal_newlines=True).strip().split('\n', maxsplit=1)[0]
|
return output.strip().split('\n')[0].split()[-1] if d_e != 'xfce' else get_xfce_version()
|
||||||
version = output.split()[-1]
|
except Exception as e:
|
||||||
if d_e == "Xfce":
|
return f"DE version info not available ({e})"
|
||||||
version = get_xfce_version()
|
|
||||||
elif d_e == "I3":
|
# Function to get XFCE version
|
||||||
version = output.split()[-2]
|
def get_xfce_version():
|
||||||
return version
|
try:
|
||||||
except subprocess.CalledProcessError:
|
xfce_version = subprocess.check_output(['xfce4-session', '--version'], universal_newlines=True)
|
||||||
return 'Failed to get display information (xdpyinfo command failed)'
|
return xfce_version.split()[1]
|
||||||
except FileNotFoundError:
|
except Exception as e:
|
||||||
return 'xdpyinfo command not found'
|
return f"XFCE version info not available ({e})"
|
||||||
except OSError as _:
|
|
||||||
return f'OS error: {_}'
|
|
||||||
return "unknown version"
|
|
||||||
|
|
||||||
|
|
||||||
def get_xfce_version():
|
def get_xfce_version():
|
||||||
|
@ -341,6 +341,16 @@ def print_user_and_hostname():
|
||||||
print(f"{username}@{hostname}")
|
print(f"{username}@{hostname}")
|
||||||
print("-" * len(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
|
# These are the variables that run the functions
|
||||||
os_name = platform.system()
|
os_name = platform.system()
|
||||||
|
@ -364,6 +374,7 @@ os_full_information = f"{os_pretty} ({architecture})"
|
||||||
package_information = get_package_info()
|
package_information = get_package_info()
|
||||||
shell_information = get_shell_info()
|
shell_information = get_shell_info()
|
||||||
RESOLUTION_INFORMATION = get_display_info()
|
RESOLUTION_INFORMATION = get_display_info()
|
||||||
|
storage_information = get_storage_info()
|
||||||
|
|
||||||
# Determmine what Desktop evironment is being used
|
# Determmine what Desktop evironment is being used
|
||||||
if desktop_environment == "gnome":
|
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_dt_text = f"{BOLD_START}Theme:{BOLD_END}"
|
||||||
bold_ic_text = f"{BOLD_START}Icons:{BOLD_END}"
|
bold_ic_text = f"{BOLD_START}Icons:{BOLD_END}"
|
||||||
bold_gpu_text = f"{BOLD_START}GPU:{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 the OS name and architecture
|
||||||
print_user_and_hostname()
|
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_cpu_text} {cpu_information}")
|
||||||
print(f"{bold_gpu_text} {gpu_information}")
|
print(f"{bold_gpu_text} {gpu_information}")
|
||||||
print(f"{bold_mem_text} {mem_information}")
|
print(f"{bold_mem_text} {mem_information}")
|
||||||
|
print(f"{bold_storage_text} {storage_information}")
|
||||||
|
|
Loading…
Reference in New Issue