From 1cbb25fb0f105389bf2c27520ace0f035b431f92 Mon Sep 17 00:00:00 2001 From: pennybelle Date: Fri, 30 Aug 2024 22:33:02 -0400 Subject: [PATCH] fix parse_gpu_name.py --- src/pbfetch/parse_funcs/parse_gpu_name.py | 42 ++++++++++++++++------- 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/src/pbfetch/parse_funcs/parse_gpu_name.py b/src/pbfetch/parse_funcs/parse_gpu_name.py index 0769c03..b26109a 100644 --- a/src/pbfetch/parse_funcs/parse_gpu_name.py +++ b/src/pbfetch/parse_funcs/parse_gpu_name.py @@ -1,15 +1,30 @@ -import subprocess +from subprocess import Popen, PIPE +def command(input): + input = Popen( + input, + shell=True, + stdout=PIPE, + stderr=PIPE, + ) + input = str(input.communicate()[0]) + input = input[2 : len(input) - 3] + + return input def parse_gpu(): try: - gpu_name = subprocess.Popen( - 'eglinfo | grep "OpenGL compatibility profile renderer:"', - shell=True, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - ) - gpu_name = str(gpu_name.communicate()[0]) + gpu_name = command("lspci | grep -i nvidia") + + if gpu_name: + print(gpu_name) + return gpu_name + + except Exception: + pass + + try: + gpu_name = command('eglinfo | grep "OpenGL compatibility profile renderer:"') # print(gpu_name) gpu_name = gpu_name.split("\\n")[2] @@ -20,12 +35,15 @@ def parse_gpu(): return gpu_name - except IndexError: - gpu_name = subprocess.Popen( + except Exception: + pass + + try: + gpu_name = Popen( 'lspci | grep "VGA compatible controller:"', shell=True, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, + stdout=PIPE, + stderr=PIPE, ) gpu_name = str(gpu_name.communicate()[0]) # print(gpu_name)