def find_ports(device):
bus_id = device.bus<EOL>dev_id = device.address<EOL>for dirent in os.listdir(USB_SYS_PREFIX):<EOL><INDENT>matches = re.match(USB_PORTS_STR + '<STR_LIT:$>', dirent)<EOL>if matches:<EOL><INDENT>bus_str = readattr(dirent, '<STR_LIT>')<EOL>if bus_str:<EOL><INDENT>busnum = float(bus_str)<EOL><DEDENT>else:<EOL><INDENT>busnum = None<EOL><DEDENT>dev_str = readattr(dirent, '<STR_LIT>')<EOL>if dev_str:<EOL><INDENT>devnum = float(dev_str)<EOL><DEDENT>else:<EOL><INDENT>devnum = None<EOL><DEDENT>if busnum == bus_id and devnum == dev_id:<EOL><INDENT>return str(matches.groups()[<NUM_LIT:1>])<EOL><DEDENT><DEDENT><DEDENT>
Find the port chain a device is plugged on.

This is done by searching sysfs for a device that matches the device
bus/address combination.

Useful when the underlying usb lib does not return device.port_number for
whatever reason.