3 ft`@sddlmZddlmZddlmZddlZddlmZddlmZddl m Z m Z m Z ddl Z ddlZ ddlZ ddlZddlZejdZGd d d ejZdS) )absolute_import)print_function)unicode_literalsN)commands) OptionParser)ucd_C_dnfc@sPeZdZdZdZedZeddZddZ d d Z d d Z d dZ ddZ dS) SearchCommandzTA class containing methods needed by the cli to execute the search command. searchsez+search package details for the given stringc Cs<|jddtdd|jddtddgdtjtd d dS) Nz--all store_truez'search also package description and URL)actionhelp query_string+ZKEYWORDallzKeyword to search for)nargsmetavarchoicesdefaultrr) add_argumentrrZPkgNarrowCallback)parserr/usr/lib/python3.6/search.py set_argparser0s  zSearchCommand.set_argparsercs4tjdtddfdtddfdtddfdtd fffd d fd d }tjj}x(|D] }j|d|j|d|qbWjj rxd|D] }j|d|j|d|qWn:t |}t |j }x$|D]}t |j ||kr||=qWd}d} d} d} d} jjjs0jjjj|j dj} t} x|jd| dD]}jjjs~|j|j| krlqF| j|j|j||j|kr|j|}d} | |j |kr|j |} d} | |j|| kkr|j|| k} d} | r|| || d} jjj||j||qFWt |dkr0tjtddS)z0Search for simple text tags in a package object.nameZlongNamesummaryZSummary descriptionZ DescriptionZurlZURLc sy|S|SdS)Nr)attr) TRANS_TBLrr_translate_attrCsz.SearchCommand._search.._translate_attrcs^t|}tdj|}|r*td|}n td|}jjj|dj|}tt|dS)Nz & z%s Exactly Matched: %%sz%s Matched: %%sz, )maprjoinbaseoutputZ fmtSectionprintr) exact_matchZattrskeysZ trans_attrsZtrans_attrs_strZ section_textZ formatted)r#selfrr_print_section_headerIs  z4SearchCommand._search.._print_section_headerNF)pkgT)reverseZlimit_torzNo matches found.) collections OrderedDictr rr Z match_counterZ MatchCounter_search_countedoptsrlenlistr*matched_needlesr&ZconfZshowdupesfromrepossackqueryfiltermZlatestsetsortedrZarchaddZ matched_keysZmatched_haystacksr'Z matchcallbackloggerinfo)r+argsr,counterargZneedlesZpkgsr-Z used_attrsr5r)Zprint_section_headerlimitseenr)r"r#r+r_search9s`               zSearchCommand._searchcCs`d||i}tjj|r$d||i}|jjjjtjf|}x|j D]}|j |||qFW|S)Nz %s__substrz%s__glob) r utilZis_glob_patternr&r6r7r8hawkeyZICASErunr;)r+r?r!ZneedleZfdictqr-rrrr1s   zSearchCommand._search_countedcCs |jjs|jjtjtjddS)N)stdoutstderr)r2quietcliZredirect_loggerloggingZWARNINGINFO)r+rrr pre_configureszSearchCommand.pre_configurecCsD|jjs|jj|jj}d|_d|_d|_|jjp:|jj |j_dS)NTF) r2rJrKZredirect_repo_progressdemandsZavailable_reposZfresh_metadataZsack_activationrZquery_string_action)r+rOrrr configures zSearchCommand.configurecCstjtd|j|jjS)NzSearching Packages: )r<debugrrCr2r)r+rrrrFszSearchCommand.runN)r r )__name__ __module__ __qualname____doc__aliasesrr staticmethodrrCr1rNrPrFrrrrr (s O  r )Z __future__rrrr/Zdnf.clirZdnf.cli.option_parserrZdnf.i18nrrr r Zdnf.match_counterZdnf.utilrErLZ getLoggerr<ZCommandr rrrrs