def search_packages_info(query):
 installed = dict([(p.project_name.lower(), p) for p in pkg_resources.working_set])
 query_names = [name.lower() for name in query]
 for dist in [installed[pkg] for pkg in query_names if (pkg in installed)]:
  package = {'name': dist.project_name, 'version': dist.version, 'location': dist.location, 'requires': [dep.project_name for dep in dist.requires()]}
  file_list = None
  metadata = None
  if isinstance(dist, pkg_resources.DistInfoDistribution):
   if dist.has_metadata('RECORD'):
    lines = dist.get_metadata_lines('RECORD')
    paths = [l.split(',')[0] for l in lines]
    paths = [os.path.join(dist.location, p) for p in paths]
    file_list = [os.path.relpath(p, dist.location) for p in paths]
   if dist.has_metadata('METADATA'):
    metadata = dist.get_metadata('METADATA')
  else:
   if dist.has_metadata('installed-files.txt'):
    paths = dist.get_metadata_lines('installed-files.txt')
    paths = [os.path.join(dist.egg_info, p) for p in paths]
    file_list = [os.path.relpath(p, dist.location) for p in paths]
   if dist.has_metadata('PKG-INFO'):
    metadata = dist.get_metadata('PKG-INFO')
  if dist.has_metadata('entry_points.txt'):
   entry_points = dist.get_metadata_lines('entry_points.txt')
   package['entry_points'] = entry_points
  installer = None
  if dist.has_metadata('INSTALLER'):
   for line in dist.get_metadata_lines('INSTALLER'):
    if line.strip():
     installer = line.strip()
     break
  package['installer'] = installer
  feed_parser = FeedParser()
  feed_parser.feed(metadata)
  pkg_info_dict = feed_parser.close()
  for key in ('metadata-version', 'summary', 'home-page', 'author', 'author-email', 'license'):
   package[key] = pkg_info_dict.get(key)
  classifiers = []
  for line in metadata.splitlines():
   if (not line):
    break
   if line.startswith('Classifier: '):
    classifiers.append(line[len('Classifier: '):])
  package['classifiers'] = classifiers
  if file_list:
   package['files'] = sorted(file_list)
  (yield package)

def search_packages_info ( query ) : installed = dict ( [ ( p . project_name . lower ( ) , p ) for p in pkg_resources . working_set ] ) query_names = [ name . lower ( ) for name in query ] for dist in [ installed [ pkg ] for pkg in query_names if ( pkg in installed ) ] : package = { 'name' : dist . project_name , 'version' : dist . version , 'location' : dist . location , 'requires' : [ dep . project_name for dep in dist . requires ( ) ] } file_list = None metadata = None if isinstance ( dist , pkg_resources . DistInfoDistribution ) : if dist . has_metadata ( 'RECORD' ) : lines = dist . get_metadata_lines ( 'RECORD' ) paths = [ l . split ( ',' ) [ 0 ] for l in lines ] paths = [ os . path . join ( dist . location , p ) for p in paths ] file_list = [ os . path . relpath ( p , dist . location ) for p in paths ] if dist . has_metadata ( 'METADATA' ) : metadata = dist . get_metadata ( 'METADATA' ) else : if dist . has_metadata ( 'installed-files.txt' ) : paths = dist . get_metadata_lines ( 'installed-files.txt' ) paths = [ os . path . join ( dist . egg_info , p ) for p in paths ] file_list = [ os . path . relpath ( p , dist . location ) for p in paths ] if dist . has_metadata ( 'PKG-INFO' ) : metadata = dist . get_metadata ( 'PKG-INFO' ) if dist . has_metadata ( 'entry_points.txt' ) : entry_points = dist . get_metadata_lines ( 'entry_points.txt' ) package [ 'entry_points' ] = entry_points installer = None if dist . has_metadata ( 'INSTALLER' ) : for line in dist . get_metadata_lines ( 'INSTALLER' ) : if line . strip ( ) : installer = line . strip ( ) break package [ 'installer' ] = installer feed_parser = FeedParser ( ) feed_parser . feed ( metadata ) pkg_info_dict = feed_parser . close ( ) for key in ( 'metadata-version' , 'summary' , 'home-page' , 'author' , 'author-email' , 'license' ) : package [ key ] = pkg_info_dict . get ( key ) classifiers = [ ] for line in metadata . splitlines ( ) : if ( not line ) : break if line . startswith ( 'Classifier: ' ) : classifiers . append ( line [ len ( 'Classifier: ' ) : ] ) package [ 'classifiers' ] = classifiers if file_list : package [ 'files' ] = sorted ( file_list ) ( yield package )
gather details from installed distributions .