usbinfo/darwin.py
def usbinfo():
    """Return a list of device and interface information for each USB device.
    """
    info_list = []

    _mounts = get_mounts()

    if OSX_VERSION_MINOR_INT >= 11:
        _el_capitan_extras = \
                _ioreg_usb_devices('XHC1') + _ioreg_usb_devices('EHC1')

    for node in _ioreg_usb_devices():
        # Capture device-level information
        try:
            vid = node['idVendor']
            pid = node['idProduct']
        except KeyError:
            # If idVendor or idProduct is not set, it's not a real USB device.
            # This really shouldn't happen.
            continue

        # Ignore Unicode characters
        vendor = node.get('USB Vendor Name', u'').encode('ascii', 'ignore')
        product = node.get('USB Product Name', u'').encode('ascii', 'ignore')
        serno = node.get('USB Serial Number', u'').encode('ascii', 'ignore')

        # USB device, not interface
        devinfo = {
            'idVendor': '%0.4x' % vid,
            'idProduct': '%0.4x' % pid,
            'iManufacturer': vendor,
            'iProduct': product,
            'iSerialNumber': serno,
            'bNumEndpoints': '1',
            'bInterfaceNumber': '',
            'devname': '',
        }

        info_list.append(devinfo)

        # For each interface, we want to capture more information
        for child in node.get('IORegistryEntryChildren', []):
            if (child.get('IOUserClientClass') == 'IOUSBInterfaceUserClientV3'
                    or child.get('IOObjectClass') == 'IOUSBInterface'
                    or ( OSX_VERSION_MINOR_INT >= 15 and child.get('IOObjectClass') == 'AppleUSBInterface')  # for 10.xx.x versions
                    or ( OSX_VERSION_MAJOR_INT >= 11 and child.get('IOObjectClass') == 'AppleUSBInterface')):  # for 11.xx.x versions

                ifinfo = copy.copy(devinfo)

                ifinfo.update({
                    'bInterfaceNumber': str(child['bInterfaceNumber']),
                    'bNumEndpoints': str(child['bNumEndpoints'])
                })

                # On El Capitan (and higher), devname is in a separate tree
                # under 'XHC1' or 'EHC1'. We first need to find the
                # corresponding node under these trees, then run _extra_if_info
                # to fill in the extra information.
                if OSX_VERSION_MINOR_INT >= 11:
                    for extra_node in _el_capitan_extras:
                        _node = _match_node_property(
                            extra_node,
                            'AppleUSBAlternateServiceRegistryID',
                            child.get('IORegistryEntryID')
                        )

                        if _node is not None:
                            extras = _extra_if_info(_node)
                            ifinfo.update(extras)
                            break

                extras = _extra_if_info(child)
                ifinfo.update(extras)

                if 'devname' in ifinfo:
                    mount = _mounts.get(ifinfo['devname'])
                    if mount:
                        ifinfo['mount'] = mount

                info_list.append(ifinfo)

    return info_list
Return a list of device and interface information for each USB device.
    
Return a list of device and interface information for each USB device.
Return a list of device and interface information for each USB device .
def usbinfo():
    info_list = []
    _mounts = get_mounts()
    if OSX_VERSION_MINOR_INT >= 11:
        _el_capitan_extras = \
                _ioreg_usb_devices('XHC1') + _ioreg_usb_devices('EHC1')
    for node in _ioreg_usb_devices():
        try:
            vid = node['idVendor']
            pid = node['idProduct']
        except KeyError:
            continue
        vendor = node.get('USB Vendor Name', u'').encode('ascii', 'ignore')
        product = node.get('USB Product Name', u'').encode('ascii', 'ignore')
        serno = node.get('USB Serial Number', u'').encode('ascii', 'ignore')
        devinfo = {
            'idVendor': '%0.4x' % vid,
            'idProduct': '%0.4x' % pid,
            'iManufacturer': vendor,
            'iProduct': product,
            'iSerialNumber': serno,
            'bNumEndpoints': '1',
            'bInterfaceNumber': '',
            'devname': '',
        }
        info_list.append(devinfo)
        for child in node.get('IORegistryEntryChildren', []):
            if (child.get('IOUserClientClass') == 'IOUSBInterfaceUserClientV3'
                    or child.get('IOObjectClass') == 'IOUSBInterface'
                    or ( OSX_VERSION_MINOR_INT >= 15 and child.get('IOObjectClass') == 'AppleUSBInterface')  
                    or ( OSX_VERSION_MAJOR_INT >= 11 and child.get('IOObjectClass') == 'AppleUSBInterface')):  
                ifinfo = copy.copy(devinfo)
                ifinfo.update({
                    'bInterfaceNumber': str(child['bInterfaceNumber']),
                    'bNumEndpoints': str(child['bNumEndpoints'])
                })
                if OSX_VERSION_MINOR_INT >= 11:
                    for extra_node in _el_capitan_extras:
                        _node = _match_node_property(
                            extra_node,
                            'AppleUSBAlternateServiceRegistryID',
                            child.get('IORegistryEntryID')
                        )
                        if _node is not None:
                            extras = _extra_if_info(_node)
                            ifinfo.update(extras)
                            break
                extras = _extra_if_info(child)
                ifinfo.update(extras)
                if 'devname' in ifinfo:
                    mount = _mounts.get(ifinfo['devname'])
                    if mount:
                        ifinfo['mount'] = mount
                info_list.append(ifinfo)
    return info_list
def usbinfo ( ) : info_list = [ ] _mounts = get_mounts ( ) if OSX_VERSION_MINOR_INT >= 11 : _el_capitan_extras = _ioreg_usb_devices ( 'XHC1' ) + _ioreg_usb_devices ( 'EHC1' ) for node in _ioreg_usb_devices ( ) : try : vid = node [ 'idVendor' ] pid = node [ 'idProduct' ] except KeyError : continue vendor = node . get ( 'USB Vendor Name' , u'' ) . encode ( 'ascii' , 'ignore' ) product = node . get ( 'USB Product Name' , u'' ) . encode ( 'ascii' , 'ignore' ) serno = node . get ( 'USB Serial Number' , u'' ) . encode ( 'ascii' , 'ignore' ) devinfo = { 'idVendor' : '%0.4x' % vid , 'idProduct' : '%0.4x' % pid , 'iManufacturer' : vendor , 'iProduct' : product , 'iSerialNumber' : serno , 'bNumEndpoints' : '1' , 'bInterfaceNumber' : '' , 'devname' : '' , } info_list . append ( devinfo ) for child in node . get ( 'IORegistryEntryChildren' , [ ] ) : if ( child . get ( 'IOUserClientClass' ) == 'IOUSBInterfaceUserClientV3' or child . get ( 'IOObjectClass' ) == 'IOUSBInterface' or ( OSX_VERSION_MINOR_INT >= 15 and child . get ( 'IOObjectClass' ) == 'AppleUSBInterface' ) or ( OSX_VERSION_MAJOR_INT >= 11 and child . get ( 'IOObjectClass' ) == 'AppleUSBInterface' ) ) : ifinfo = copy . copy ( devinfo ) ifinfo . update ( { 'bInterfaceNumber' : str ( child [ 'bInterfaceNumber' ] ) , 'bNumEndpoints' : str ( child [ 'bNumEndpoints' ] ) } ) if OSX_VERSION_MINOR_INT >= 11 : for extra_node in _el_capitan_extras : _node = _match_node_property ( extra_node , 'AppleUSBAlternateServiceRegistryID' , child . get ( 'IORegistryEntryID' ) ) if _node is not None : extras = _extra_if_info ( _node ) ifinfo . update ( extras ) break extras = _extra_if_info ( child ) ifinfo . update ( extras ) if 'devname' in ifinfo : mount = _mounts . get ( ifinfo [ 'devname' ] ) if mount : ifinfo [ 'mount' ] = mount info_list . append ( ifinfo ) return info_list
Return a list of device and interface information for each USB device.
Return a list of device and interface information for each USB device .
"""Return a list of device and interface information for each USB device.
    """ # Capture device-level information # If idVendor or idProduct is not set, it's not a real USB device. # This really shouldn't happen. # Ignore Unicode characters # USB device, not interface # For each interface, we want to capture more information # for 10.xx.x versions # for 11.xx.x versions # On El Capitan (and higher), devname is in a separate tree # under 'XHC1' or 'EHC1'. We first need to find the # corresponding node under these trees, then run _extra_if_info # to fill in the extra information.