]>
git.ipfire.org Git - ipfire-3.x.git/blob - pyfire/src/hal.py
2 # minihal.py: Simple wrapper around HAL
4 # Copyright (C) 2007 Red Hat, Inc. All rights reserved.
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.
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.
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/>.
19 # Author(s): Bill Nottingham <notting@redhat.com>
22 """Simple wrapper around HAL"""
27 """Retrieve all properties of a particular device (by UDI)"""
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
:
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")
42 props
['device'] = None
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'])
49 props
['description'] = props
['info.product']
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']
58 def get_devices_by_type(type):
59 """Retrieve all devices of a particular type"""
62 bus
= dbus
.SystemBus()
63 hal
= dbus
.Interface(bus
.get_object("org.freedesktop.Hal","/org/freedesktop/Hal/Manager"),"org.freedesktop.Hal.Manager")
66 for udi
in hal
.FindDeviceByCapability(type):