You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.0 KiB
36 lines
1.0 KiB
15 years ago
|
import dbus
|
||
|
|
||
|
bus = dbus.SystemBus()
|
||
|
hal_manager_obj = bus.get_object("org.freedesktop.Hal", "/org/freedesktop/Hal/Manager")
|
||
|
hal_manager = dbus.Interface(hal_manager_obj, "org.freedesktop.Hal.Manager")
|
||
|
#device_names = hal_manager.GetAllDevices()
|
||
|
|
||
|
ac = hal_manager.FindDeviceByCapability("ac_adapter")
|
||
|
|
||
|
#all_devices = hal_manager.GetAllDevices()
|
||
|
|
||
|
#for n in device_names: print n
|
||
|
#obj = bus.get_object("org.freedesktop.Hal", u'/org/freedesktop/Hal/devices/acpi_AC')
|
||
|
#obj.GetAllProperties()
|
||
|
|
||
|
name = ac[0]
|
||
|
device_dbus_obj = bus.get_object("org.freedesktop.Hal" ,ac[0])
|
||
|
properties = device_dbus_obj.GetAllProperties(dbus_interface="org.freedesktop.Hal.Device")
|
||
|
|
||
|
try:
|
||
|
parent_name = properties["info.parent"]
|
||
|
except KeyError:
|
||
|
# no parent, must be parent of virtual_root
|
||
|
parent_name = "/"
|
||
|
except TypeError:
|
||
|
print "Error: no properties for device %s"%name
|
||
|
#continue
|
||
|
print properties['ac_adapter.present']
|
||
|
#for p in properties:
|
||
|
# print p, " :: ", properties[p]
|
||
|
if properties['ac_adapter.present']:
|
||
|
print "plugged in"
|
||
|
else:
|
||
|
print "unplugged"
|
||
|
|