问题
I'm currently using dmidecode
for everything else but I've yet to find good information on retrieving specifications for a video card on Linux (Mainly Fedora, Ubuntu, Debian, CentOS, RedHat)
What i was thinking of using was: lspci -v
or HAL
What would be the most efficient way to parse lspci
data, obtaining just VGA portion to then output json
.
def get_graphic_card_properties():
import dbus
bus = dbus.SystemBus()
hal_manager_object = bus.get_object('org.freedesktop.Hal', '/org/freedesktop/Hal/Manager')
hal_manager_interface = dbus.Interface(hal_manager_object, 'org.freedesktop.Hal.Manager')
method = hal_manager_object.get_dbus_method('GetAllDevices', 'org.freedesktop.Hal.Manager')
print "\n".join(list(iter(method())))
That's the only code I was able to come across as an example, doesn't appear to work for me in Fedora 17 64bit, I think because there's no /orc/freedesktop/Hal.Manager
.
Any ideas on this?
回答1:
here is the command sample of lspci here. so basically you would call subprocess to access the command from python.
import subprocess
def find_vga():
vga = subprocess.Popen("lspci -v -s `lspci | awk '/VGA/{print $1}'`", shell=True)
return vga
print(find_vga())
OR
def find_vga():
vga = subprocess.check_output("lspci -v -s `lspci | awk '/VGA/{print $1}'`", shell=True, executable='/bin/bash')
return vga
print(find_vga())
来源:https://stackoverflow.com/questions/13867696/python-in-linux-obtain-vga-specifications-via-lspci-or-hal