usbinfo/darwin.py
def _ioreg_usb_devices(nodename=None):
    """Returns a list of USB device tree from ioreg"""
    import plistlib

    def _ioreg(nodename):
        """Run ioreg command on specific node name"""
        cmd = ['ioreg', '-a', '-l', '-r', '-n', nodename]
        output = subprocess.check_output(cmd)
        # ST-Link devices (and possibly others?) erroneously store binary data
        # in the <string> serial number, which causes plistlib to blow up.
        # This will convert that to hex and preserve contents otherwise.
        output = _sanitize_xml(output)
        plist_data = []
        if output:
            try:
                plist_data = plistlib.readPlistFromString(output)
            except AttributeError as e:
                plist_data = plistlib.loads(output)
        return plist_data

    if nodename is None:
        xhci = _ioreg('AppleUSBXHCI')
        ehci = _ioreg('AppleUSBEHCI')
        ioreg = xhci + ehci
    else:
        ioreg = _ioreg(nodename)

    def _usb_device(node):
        """Recursively find USB devices and return a list of them"""
        devices = []
        if 'sessionID' in node:
            devices.append(node)

        for child in node.get('IORegistryEntryChildren', []):
            devices += _usb_device(child)

        return devices

    devices = []
    for node in ioreg:
        devices += _usb_device(node)

    return devices
Returns a list of USB device tree from ioreg
Returns a list of USB device tree from ioreg
Returns a list of USB device tree from ioreg
def _ioreg_usb_devices(nodename=None):
    import plistlib
    def _ioreg(nodename):
        cmd = ['ioreg', '-a', '-l', '-r', '-n', nodename]
        output = subprocess.check_output(cmd)
        output = _sanitize_xml(output)
        plist_data = []
        if output:
            try:
                plist_data = plistlib.readPlistFromString(output)
            except AttributeError as e:
                plist_data = plistlib.loads(output)
        return plist_data
    if nodename is None:
        xhci = _ioreg('AppleUSBXHCI')
        ehci = _ioreg('AppleUSBEHCI')
        ioreg = xhci + ehci
    else:
        ioreg = _ioreg(nodename)
    def _usb_device(node):
        devices = []
        if 'sessionID' in node:
            devices.append(node)
        for child in node.get('IORegistryEntryChildren', []):
            devices += _usb_device(child)
        return devices
    devices = []
    for node in ioreg:
        devices += _usb_device(node)
    return devices
def _ioreg_usb_devices ( nodename = None ) : import plistlib def _ioreg ( nodename ) : """Run ioreg command on specific node name""" cmd = [ 'ioreg' , '-a' , '-l' , '-r' , '-n' , nodename ] output = subprocess . check_output ( cmd ) output = _sanitize_xml ( output ) plist_data = [ ] if output : try : plist_data = plistlib . readPlistFromString ( output ) except AttributeError as e : plist_data = plistlib . loads ( output ) return plist_data if nodename is None : xhci = _ioreg ( 'AppleUSBXHCI' ) ehci = _ioreg ( 'AppleUSBEHCI' ) ioreg = xhci + ehci else : ioreg = _ioreg ( nodename ) def _usb_device ( node ) : """Recursively find USB devices and return a list of them""" devices = [ ] if 'sessionID' in node : devices . append ( node ) for child in node . get ( 'IORegistryEntryChildren' , [ ] ) : devices += _usb_device ( child ) return devices devices = [ ] for node in ioreg : devices += _usb_device ( node ) return devices
Returns a list of USB device tree from ioreg
Returns a list of USB device tree from ioreg
"""Returns a list of USB device tree from ioreg""" """Run ioreg command on specific node name""" # ST-Link devices (and possibly others?) erroneously store binary data # in the <string> serial number, which causes plistlib to blow up. # This will convert that to hex and preserve contents otherwise. """Recursively find USB devices and return a list of them"""
nodename