]> git.ipfire.org Git - people/ms/ipfire-3.x.git/blob - pkgs/pyfire/src/hal.py
Change file layout of the makefiles.
[people/ms/ipfire-3.x.git] / pkgs / pyfire / src / hal.py
1 #
2 # minihal.py: Simple wrapper around HAL
3 #
4 # Copyright (C) 2007 Red Hat, Inc. All rights reserved.
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #
19 # Author(s): Bill Nottingham <notting@redhat.com>
20 #
21
22 """Simple wrapper around HAL"""
23
24 import dbus
25
26 def get_device(udi):
27 """Retrieve all properties of a particular device (by UDI)"""
28 try:
29 bus = dbus.SystemBus()
30 haldev = dbus.Interface(bus.get_object("org.freedesktop.Hal", udi), "org.freedesktop.Hal.Device")
31 props = haldev.GetAllProperties()
32 except dbus.exceptions.DBusException:
33 return None
34
35 if props.has_key('block.device'):
36 props['device'] = props['block.device'].encode("utf-8")
37 elif props.has_key('linux.device_file'):
38 props['device'] = props['linux.device_file'].encode("utf-8")
39 elif props.has_key('net.interface'):
40 props['device'] = props['net.interface'].encode("utf-8")
41 else:
42 props['device'] = None
43
44 props['description'] = ''
45 if props.has_key('info.product'):
46 if props.has_key('info.vendor'):
47 props['description'] = '%s %s' % (props['info.vendor'],props['info.product'])
48 else:
49 props['description'] = props['info.product']
50 else:
51 props['description'] = props['info.udi']
52 if props.has_key('net.originating_device'):
53 pdev = get_device(props['net.originating_device'])
54 props['description'] = pdev['description']
55
56 return props
57
58 def get_devices_by_type(type):
59 """Retrieve all devices of a particular type"""
60 ret = []
61 try:
62 bus = dbus.SystemBus()
63 hal = dbus.Interface(bus.get_object("org.freedesktop.Hal","/org/freedesktop/Hal/Manager"),"org.freedesktop.Hal.Manager")
64 except:
65 return ret
66 for udi in hal.FindDeviceByCapability(type):
67 dev = get_device(udi)
68 if dev:
69 ret.append(dev)
70 return ret