def parse_lsmod_for_module(l_raw, module_name, escape=True):
 if escape:
  module_search = re.escape(module_name)
 else:
  module_search = module_name
 lsmod = re.search(('^(?P<name>%s)\\s+(?P<size>\\d+)\\s+(?P<used>\\d+)\\s*(?P<submodules>\\S+)?$' % module_search), l_raw, re.M)
 if lsmod:
  module_info = lsmod.groupdict([])
  module_info['size'] = int(module_info['size'])
  module_info['used'] = int(module_info['used'])
  if module_info['submodules']:
   module_info['submodules'] = module_info['submodules'].split(',')
  return module_info
 else:
  return {}

def parse_lsmod_for_module ( l_raw , module_name , escape = True ) : if escape : module_search = re . escape ( module_name ) else : module_search = module_name lsmod = re . search ( ( '^(?P<name>%s)\\s+(?P<size>\\d+)\\s+(?P<used>\\d+)\\s*(?P<submodules>\\S+)?$' % module_search ) , l_raw , re . M ) if lsmod : module_info = lsmod . groupdict ( [ ] ) module_info [ 'size' ] = int ( module_info [ 'size' ] ) module_info [ 'used' ] = int ( module_info [ 'used' ] ) if module_info [ 'submodules' ] : module_info [ 'submodules' ] = module_info [ 'submodules' ] . split ( ',' ) return module_info else : return { }
use a regexp to parse raw lsmod output and get module information .