blob: f9ef90c0b6c441353233d9719ebbb6c77b066104 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
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"
|