Python, In linux obtain VGA specifications via lspci or HAL?

╄→гoц情女王★ 提交于 2019-12-24 07:46:31

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!