7
rootdir_pattern = re.compile('^.*?/devices')
9
def device_state(name):
11
Follow pmount policy to determine whether a device is removable or internal.
13
with open('/sys/block/%s/device/block/%s/removable' % (name, name)) as f:
17
path = rootdir_pattern.sub('', os.readlink('/sys/block/%s' % name))
18
hotplug_buses = ("usb", "ieee1394", "mmc", "pcmcia", "firewire")
19
for bus in hotplug_buses:
20
if os.path.exists('/sys/bus/%s' % bus):
21
for device_bus in os.listdir('/sys/bus/%s/devices' % bus):
22
device_link = rootdir_pattern.sub('', os.readlink(
23
'/sys/bus/%s/devices/%s' % (bus, device_bus)))
24
if re.search(device_link, path):
30
def usb_support(name, version):
32
Check the USB specification number for both hub port and device
34
path = rootdir_pattern.sub('', os.readlink('/sys/block/%s' % name))
36
# Remove the usb config.interface part of the path
37
m = re.match('((.*usb\d+).*\/)\d-[\d\.:\-]+\/.*', path)
39
device_path = m.group(1)
40
hub_port_path = m.group(2)
42
# Check the highest version of USB the device supports
43
with open('/sys/devices/%s/version' %device_path) as f:
44
if float(f.readline()) < version:
47
# Check the highest version of USB the hub supports
48
with open('/sys/devices/%s/version' %hub_port_path) as f:
49
if float(f.readline()) < version:
57
for path in glob('/sys/block/*/device'):
58
name = re.sub('.*/(.*?)/device', '\g<1>', path)
59
state = device_state(name)
60
usb2 = usb_support(name, 2.00)
61
usb3 = usb_support(name, 3.00)
62
# FIXME: Remove leading block device name when the requirements
63
# checking code in Checkbox allows it
65
%(name)s_state: %(state)s
66
%(name)s_usb2: %(usb2)s
67
%(name)s_usb3: %(usb3)s