]>
git.ipfire.org Git - oddments/fireinfo.git/blob - fireinfo/device.py
2 ###############################################################################
5 # Copyright (C) 2010, 2011 IPFire Team (www.ipfire.org) #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
26 This is an abstract class that represents all devices in the system.
27 Every single device has its own instance of this class.
30 def __init__(self
, path
):
32 Collect all information about the device by reading the
33 "uevent" file and parsing it.
36 # Save the path in /sys to the device.
39 # Datastructure to store information we read.
42 # Open the uevent file and parse all lines.
43 with
open(os
.path
.join(path
, "uevent")) as f
:
44 for line
in f
.readlines():
45 key
, val
= line
.split("=")
46 self
._uevent
[key
] = val
.rstrip().lower()
51 Get the driver/kernel module that device is driven by or return None.
53 return self
._uevent
.get("DRIVER", None)
56 class PCIDevice(Device
):
58 A class that represents all PCI (and PCIe) devices in a system.
66 Return the PCI model id of this device.
68 return self
._uevent
['PCI_ID'].split(":")[1]
73 Return the PCI vendor id of this device.
75 return self
._uevent
['PCI_ID'].split(":")[0]
78 def deviceclass(self
):
80 Return the PCI device class of this device.
82 return self
._uevent
['PCI_CLASS']
87 Return the PCI vendor sub id of this device.
89 return self
._uevent
["PCI_SUBSYS_ID"].split(":")[0]
94 Return the PCI model sub id of this device.
96 return self
._uevent
["PCI_SUBSYS_ID"].split(":")[1]
99 class USBDevice(Device
):
101 A class that represents all USB devices in a system.
108 A function to pad ids that have no leading zeroes.
117 Return the USB vendor id of this device.
119 return self
.pad(self
._uevent
['PRODUCT'].split("/")[0])
124 Return the USB model id of this device.
126 return self
.pad(self
._uevent
['PRODUCT'].split("/")[1])
129 def deviceclass(self
):
131 Return the USB device class of this device.
133 return self
._uevent
.get("INTERFACE", None)