3 Pf@sddlmZddlmZddlZddlZddlmZddlm Z m Z ddl m Z ddl mZejeZGdd d eZd d Zdd dZdS))absolute_import) FeedParserN)Command)SUCCESSERROR) pkg_resources)canonicalize_namecs4eZdZdZdZdZdZfddZddZZ S) ShowCommandz6Show information about one or more installed packages.Zshowz$ %prog [options] ...z*Show information about installed packages.cs>tt|j|||jjddddddd|jjd|jdS) Nz-fz--filesfiles store_trueFz7Show the full list of installed files for each package.)destactiondefaulthelpr)superr __init__Zcmd_optsZ add_optionparserZinsert_option_group)selfargskw) __class__/usr/lib/python3.6/show.pyrszShowCommand.__init__cCs8|stjdtS|}t|}t||j|jds4tStS)Nz.ERROR: Please provide a package name or names.) list_filesverbose)loggerZwarningrsearch_packages_info print_resultsr rr)rZoptionsrqueryresultsrrrrun"s zShowCommand.run) __name__ __module__ __qualname____doc__nameZusagesummaryrr __classcell__rr)rrr s  r c#sixtjD]}|t|j<q Wdd|D}xfdd|DD]ΉjjjddjDd}d}d}ttjrވj drȈj d}dd|D}fd d|D}fd d|D}j d r܈j d }nPj d rj d }fd d|D}fdd|D}j dr.j d}j drLj d}||d<j drx,j dD]} | j rd| j |d<PqdWt } | j|| j} xdD]} | j| || <qWg} x4|jD](} | jdr| j| tddqW| |d<|rt||d<|VqFWdS)z Gather details from installed distributions. Print distribution name, version, location, and installed files. Installed files requires a pip generated 'installed-files.txt' in the distributions '.egg-info' directory. cSsg|] }t|qSr)r).0r%rrr :sz(search_packages_info..csg|]}|kr|qSrr)r(Zpkg) installedrrr)<scSsg|] }|jqSr) project_name)r(Zdeprrrr)As)r%versionlocationrequiresNZRECORDcSsg|]}|jddqS),r)split)r(lrrrr)Iscsg|]}tjjj|qSr)ospathjoinr-)r(p)distrrr)Jscsg|]}tjj|jqSr)r2r3relpathr-)r(r5)r6rrr)KsZMETADATAzinstalled-files.txtcsg|]}tjjj|qSr)r2r3r4Zegg_info)r(r5)r6rrr)Sscsg|]}tjj|jqSr)r2r3r7r-)r(r5)r6rrr)TszPKG-INFOzentry_points.txt entry_pointsZ INSTALLER installermetadata-versionr& home-pageauthor author-emaillicensez Classifier: classifiersr )r:r&r;r<r=r>)rZ working_setrr+r,r-r. isinstanceZDistInfoDistributionZ has_metadataZget_metadata_linesZ get_metadatastriprZfeedcloseget splitlines startswithappendlensorted)rr5Z query_namespackageZ file_listZmetadatalinespathsr8lineZ feed_parserZ pkg_info_dictkeyr?r)r6r*rr/s^                  rFc Csd}xt|D]\}}d}|dkr0tjdtjd|jddtjd|jd dtjd |jd dtjd |jd dtjd|jddtjd|jddtjd|jddtjd|jddtjddj|jdg|rxtjd|jddtjd|jddtjdx"|jdgD]}tjd|q0Wtjd x&|jd!gD]}tjd|jq^W|rtjd"x&|jd#gD]}tjd|jqWd#|krtjd$qW|S)%zD Print the informations from installed distributions found. FTrz---zName: %sr%z Version: %sr,z Summary: %sr&z Home-page: %sz home-pagez Author: %sr<zAuthor-email: %sz author-emailz License: %sr>z Location: %sr-z Requires: %sz, r.zMetadata-Version: %szmetadata-versionz Installer: %sr9z Classifiers:r?z %sz Entry-points:r8zFiles:r z!Cannot locate installed-files.txt) enumeraterinforCr4rA) Z distributionsrrZresults_printedir6Z classifierentryrLrrrrxs>    r)FF)Z __future__rZ email.parserrZloggingr2Zpip.basecommandrZpip.status_codesrrZ pip._vendorrZpip._vendor.packaging.utilsrZ getLoggerr!rr rrrrrrs      I