]> git.ipfire.org Git - oddments/fireinfo.git/blame - fireinfo/device.py
Add sendprofile script (version 0.2).
[oddments/fireinfo.git] / fireinfo / device.py
CommitLineData
b45f0e98
MT
1import os
2import string
3
4
5class Device(object):
6 def __init__(self, path):
7 self.path=path
8 self._uevent={}
9 with open(os.path.join(path, "uevent")) as f:
10 for line in f.readlines():
11 key, val = line.split("=")
12 self._uevent[key]=val.rstrip().lower()
13
14 @property
15 def driver(self):
16 return self._uevent.get("DRIVER", None)
17
18
19class PCIDevice(Device):
20 subsystem = "pci"
21
22 @property
23 def model(self):
24 return self._uevent['PCI_ID'].split(":")[1]
25
26 @property
27 def vendor(self):
28 return self._uevent['PCI_ID'].split(":")[0]
29
30 @property
31 def deviceclass(self):
32 return self._uevent['PCI_CLASS']
33
34
35class USBDevice(Device):
36 subsystem = "usb"
37
38 def pad(self, s):
39 while len(s) < 4:
40 s = "0"+s
41 return s
42
43
44 @property
45 def vendor(self):
46 return self.pad(self._uevent['PRODUCT'].split("/")[0])
47
48 @property
49 def model(self):
50 return self.pad(self._uevent['PRODUCT'].split("/")[1])
51
52 @property
53 def deviceclass(self):
54 return self._uevent.get("INTERFACE", None)
55
56
57