<s> from __future__ import absolute_import <EOL> from email . parser import FeedParser <EOL> import logging <EOL> import os <EOL> from pip . basecommand import Command <EOL> from pip . status_codes import SUCCESS , ERROR <EOL> from pip . _vendor import pkg_resources <EOL> logger = logging . getLogger ( __name__ ) <EOL> class ShowCommand ( Command ) : <EOL> """<STR_LIT>""" <EOL> name = '<STR_LIT>' <EOL> usage = """<STR_LIT>""" <EOL> summary = '<STR_LIT>' <EOL> def __init__ ( self , * args , ** kw ) : <EOL> super ( ShowCommand , self ) . __init__ ( * args , ** kw ) <EOL> self . cmd_opts . add_option ( <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> default = False , <EOL> help = '<STR_LIT>' ) <EOL> self . parser . insert_option_group ( <NUM_LIT:0> , self . cmd_opts ) <EOL> def run ( self , options , args ) : <EOL> if not args : <EOL> logger . warning ( '<STR_LIT>' ) <EOL> return ERROR <EOL> query = args <EOL> results = search_packages_info ( query ) <EOL> if not print_results ( results , options . files ) : <EOL> return ERROR <EOL> return SUCCESS <EOL> def search_packages_info ( query ) : <EOL> """<STR_LIT>""" <EOL> installed = dict ( <EOL> [ ( p . project_name . lower ( ) , p ) for p in pkg_resources . working_set ] ) <EOL> query_names = [ name . lower ( ) for name in query ] <EOL> for dist in [ installed [ pkg ] for pkg in query_names if pkg in installed ] : <EOL> package = { <EOL> '<STR_LIT:name>' : dist . project_name , <EOL> '<STR_LIT:version>' : dist . version , <EOL> '<STR_LIT:location>' : dist . location , <EOL> '<STR_LIT>' : [ dep . project_name for dep in dist . requires ( ) ] , <EOL> } <EOL> file_list = None <EOL> metadata = None <EOL> if isinstance ( dist , pkg_resources . DistInfoDistribution ) : <EOL> if dist . has_metadata ( '<STR_LIT>' ) : <EOL> lines = dist . get_metadata_lines ( '<STR_LIT>' ) <EOL> paths = [ l . split ( '<STR_LIT:U+002C>' ) [ <NUM_LIT:0> ] for l in lines ] <EOL> paths = [ os . path . join ( dist . location , p ) for p in paths ] <EOL> file_list = [ os . path . relpath ( p , dist . location ) for p in paths ] <EOL> if dist . has_metadata ( '<STR_LIT>' ) : <EOL> metadata = dist . get_metadata ( '<STR_LIT>' ) <EOL> else : <EOL> if dist . has_metadata ( '<STR_LIT>' ) : <EOL> paths = dist . get_metadata_lines ( '<STR_LIT>' ) <EOL> paths = [ os . path . join ( dist . egg_info , p ) for p in paths ] <EOL> file_list = [ os . path . relpath ( p , dist . location ) for p in paths ] <EOL> if dist . has_metadata ( '<STR_LIT>' ) : <EOL> metadata = dist . get_metadata ( '<STR_LIT>' ) <EOL> if dist . has_metadata ( '<STR_LIT>' ) : <EOL> entry_points = dist . get_metadata_lines ( '<STR_LIT>' ) <EOL> package [ '<STR_LIT>' ] = entry_points <EOL> installer = None <EOL> if dist . has_metadata ( '<STR_LIT>' ) : <EOL> for line in dist . get_metadata_lines ( '<STR_LIT>' ) : <EOL> if line . strip ( ) : <EOL> installer = line . strip ( ) <EOL> break <EOL> package [ '<STR_LIT>' ] = installer <EOL> feed_parser = FeedParser ( ) <EOL> feed_parser . feed ( metadata ) <EOL> pkg_info_dict = feed_parser . close ( ) <EOL> for key in ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> package [ key ] = pkg_info_dict . get ( key ) <EOL> classifiers = [ ] <EOL> for line in metadata . splitlines ( ) : <EOL> if not line : <EOL> break <EOL> if line . startswith ( '<STR_LIT>' ) : <EOL> classifiers . append ( line [ len ( '<STR_LIT>' ) : ] ) <EOL> package [ '<STR_LIT>' ] = classifiers <EOL> if file_list : <EOL> package [ '<STR_LIT>' ] = sorted ( file_list ) <EOL> yield package <EOL> def print_results ( distributions , list_all_files ) : <EOL> """<STR_LIT>""" <EOL> results_printed = False <EOL> for dist in distributions : <EOL> results_printed = True <EOL> logger . info ( "<STR_LIT>" ) <EOL> logger . info ( "<STR_LIT>" , dist . get ( '<STR_LIT>' ) ) <EOL> logger . info ( "<STR_LIT>" , dist [ '<STR_LIT:name>' ] ) <EOL> logger . info ( "<STR_LIT>" , dist [ '<STR_LIT:version>' ] ) <EOL> logger . info ( "<STR_LIT>" , dist . get ( '<STR_LIT>' ) ) <EOL> logger . info ( "<STR_LIT>" , dist . get ( '<STR_LIT>' ) ) <EOL> logger . info ( "<STR_LIT>" , dist . get ( '<STR_LIT>' ) ) <EOL> logger . info ( "<STR_LIT>" , dist . get ( '<STR_LIT>' ) ) <EOL> if dist [ '<STR_LIT>' ] is not None : <EOL> logger . info ( "<STR_LIT>" , dist [ '<STR_LIT>' ] ) <EOL> logger . info ( "<STR_LIT>" , dist . get ( '<STR_LIT>' ) ) <EOL> logger . info ( "<STR_LIT>" , dist [ '<STR_LIT:location>' ] ) <EOL> logger . info ( "<STR_LIT>" , '<STR_LIT:U+002CU+0020>' . join ( dist [ '<STR_LIT>' ] ) ) <EOL> logger . info ( "<STR_LIT>" ) <EOL> for classifier in dist [ '<STR_LIT>' ] : <EOL> logger . info ( "<STR_LIT>" , classifier ) <EOL> if list_all_files : <EOL> logger . info ( "<STR_LIT>" ) <EOL> if '<STR_LIT>' in dist : <EOL> for line in dist [ '<STR_LIT>' ] : <EOL> logger . info ( "<STR_LIT>" , line . strip ( ) ) <EOL> else : <EOL> logger . info ( "<STR_LIT>" ) <EOL> if '<STR_LIT>' in dist : <EOL> logger . info ( "<STR_LIT>" ) <EOL> for line in dist [ '<STR_LIT>' ] : <EOL> logger . info ( "<STR_LIT>" , line . strip ( ) ) <EOL> return results_printed </s>
