def _parse_udevadm_info(udev_info):
 devices = []
 dev = {}
 for line in (line.strip() for line in udev_info.splitlines()):
  if line:
   line = line.split(':', 1)
   if (len(line) != 2):
    continue
   (query, data) = line
   if (query == 'E'):
    if (query not in dev):
     dev[query] = {}
    (key, val) = data.strip().split('=', 1)
    try:
     val = int(val)
    except ValueError:
     try:
      val = float(val)
     except ValueError:
      pass
    dev[query][key] = val
   else:
    if (query not in dev):
     dev[query] = []
    dev[query].append(data.strip())
  elif dev:
   devices.append(_normalize_info(dev))
   dev = {}
 if dev:
  _normalize_info(dev)
  devices.append(_normalize_info(dev))
 return devices

def _parse_udevadm_info ( udev_info ) : devices = [ ] dev = { } for line in ( line . strip ( ) for line in udev_info . splitlines ( ) ) : if line : line = line . split ( ':' , 1 ) if ( len ( line ) != 2 ) : continue ( query , data ) = line if ( query == 'E' ) : if ( query not in dev ) : dev [ query ] = { } ( key , val ) = data . strip ( ) . split ( '=' , 1 ) try : val = int ( val ) except ValueError : try : val = float ( val ) except ValueError : pass dev [ query ] [ key ] = val else : if ( query not in dev ) : dev [ query ] = [ ] dev [ query ] . append ( data . strip ( ) ) elif dev : devices . append ( _normalize_info ( dev ) ) dev = { } if dev : _normalize_info ( dev ) devices . append ( _normalize_info ( dev ) ) return devices
parse the info returned by udevadm command .