v_c@sdZddlmZddlZddlZddlZddlZddlmZddl Z ddl m Z dfdYZ de fd YZd efd YZd efd YZdZdZdefdYZdS(s; Classes for manipulating and querying groups of packages. i(tPackageSackErrorN(t parsePackages(t compareEVRtPackageSackVersioncBs5eZdZdZdZdZdZRS(cCs"d|_tjdg|_dS(Nitsha1(t_numtmisct Checksumst_chksum(tself((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyt__init__s cCsd|j|jjfS(Ns%u:%s(RRt hexdigest(R ((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyt__str__#scCs|dkrtSt|tdtdfkrDt||kS|j|jkrZtS|jj|jjkr|tStS(Ntu(tNonetFalsettypetstrRRtdigesttTrue(R tother((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyt__eq__&s $cCs ||k S(N((R R((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyt__ne__-scCs`|jd7_|jjt||dk r\|jj|d|jj|dndS(Nii(RRtupdateRR(R tpkgtcsum((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyR0s  (t__name__t __module__R R RRR(((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyRs     tPackageSackBasecBseZdZdZdZdZdZdZdZdZ d%d%d%d%d%dZ ge d Z d Zd Zd%d%d%d%d%d%d Zd%d&d Zd%d'dZdZdZdZdZe dZdZdZdZdZdZd%d%e dZdZe idZd%d%e dZ d%d%e dZ!d%e dZ"dZ#d Z$d!Z%d"Z&d#Z'd%d$Z(RS((s8Base class that provides the interface for PackageSacks.cCs i|_dS(N(tadded(R ((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyR :scCst|jS(N(tlentreturnPackages(R ((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyt__len__=scCs3|j}t|dr%|jSt|SdS(Nt__iter__(RthasattrR!titer(R tret((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyR!@s  cCs|dkrdSt|j}t|j}t|t|krZt|t|SxBtt|t|D]%\}}t||}|rv|SqvWdS(Nii(RtlistRRtziptsortedtcmp(R Rts_reposto_reposts_repoto_repoR$((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyt__cmp__Gs (cCs tdS(N(tNotImplementedError(R t compatArchs((s3/usr/lib/python2.7/site-packages/yum/packageSack.pytsetCompatArchsUscCs tdS(N(R.(R trepotmdtypetcallbackt cacheOnly((s3/usr/lib/python2.7/site-packages/yum/packageSack.pytpopulateXscCs#tjdtdd|j|S(s5return a list of package objects by (n,a,e,v,r) tuples;packagesByTuple() will go away in a future version of Yum. t stackleveli(twarningstwarntDeprecationWarningtsearchPkgTuple(R tpkgtup((s3/usr/lib/python2.7/site-packages/yum/packageSack.pytpackagesByTuple[s  cCs tdS(s6return list of pkgobjects matching the nevra requestedN(R.(R tnametepochtvertreltarch((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyt searchNevracscCs tdS(N(R.(R tnamestreturn_pkgtups((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyt searchNamesgsc Cs7|jd|jd|jd|jd|jd|jS(srreturn list of package objects matching the name, epoch, ver, rel, arch of the package object passed inR=R>R?R@RA(RBR=R>R?R@RA(R tpo((s3/usr/lib/python2.7/site-packages/yum/packageSack.pytsearchPOjs$c Cs=|\}}}}}|jd|d|d|d|d|S(s7return list of pkgobject matching the (n,a,e,v,r) tupleR=RAR>R?R@(RB(R R;tntatetvtr((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyR:qsc Csd|r6|j}|j}|j}|j}|j}nt|jd|d|d|d|d|S(spreturn if there are any packages in the sack that match the given NAEVR or the NAEVR of the given poR=RAR>R?R@(R=RAR>tversiontreleasetboolRB(R R=RAR>R?R@RF((s3/usr/lib/python2.7/site-packages/yum/packageSack.pytcontainsvs     cCs tdS(s5return dict { packages -> list of matching provides }N(R.(R R=tflagsRM((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyt getProvidesscCs tdS(s5return dict { packages -> list of matching requires }N(R.(R R=RQRM((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyt getRequiresscCs tdS(s<return list of package requiring the name (any evr and flag)N(R.(R R=((s3/usr/lib/python2.7/site-packages/yum/packageSack.pytsearchRequiresscCs tdS(s<return list of package providing the name (any evr and flag)N(R.(R R=((s3/usr/lib/python2.7/site-packages/yum/packageSack.pytsearchProvidesscCs tdS(sCreturn list of package conflicting with the name (any evr and flag)N(R.(R R=((s3/usr/lib/python2.7/site-packages/yum/packageSack.pytsearchConflictsscCs tdS(s=return list of package obsoleting the name (any evr and flag)N(R.(R R=((s3/usr/lib/python2.7/site-packages/yum/packageSack.pytsearchObsoletesscCs tdS(sEreturns a dict of obsoletes dict[obsoleting pkgtuple] = [list of obs]N(R.(R tnewest((s3/usr/lib/python2.7/site-packages/yum/packageSack.pytreturnObsoletesscCs tdS(sb Is calling pkg.returnFileEntries(primary_only=True) faster than using searchFiles(). N(R.(R ((s3/usr/lib/python2.7/site-packages/yum/packageSack.pythave_fastReturnFileEntriesscCs tdS(s#return list of packages by filenameN(R.(R R=((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyt searchFilesscCs tdS(s"add a pkgobject to the packageSackN(R.(R tobj((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyt addPackagescCs tdS(sbuilds the useful indexes for searching/querying the packageSack This should be called after all the necessary packages have been added/deletedN(R.(R ((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyt buildIndexesscCs tdS(sdelete a pkgobjectN(R.(R R\((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyt delPackagescCs tdS(sreturn list of all packagesN(R.(R trepoidtpatternst ignore_case((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyRscGs tdS(s Add an "excluder" for all packages in the repo/sack. Can basically do anything based on nevra, changes lots of exclude decisions from "preload package; test; delPackage" into "load excluder". Excluderid is used so the caller doesn't have to track "have I loaded the excluder for this repo.", it's probably only useful when repoid is None ... if it turns out utterly worthless then it's still not a huge wart. N(R.(R R`t excluderidtexcludertargs((s3/usr/lib/python2.7/site-packages/yum/packageSack.pytaddPackageExcludersc CsVd}t}i}i}i}xt|jD]}|j} |j|| x^|D]V} |j|| kr`| |krt|| R?R@RA((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyRBscCs|jd||S(NRE(R(R RCRD((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyREscCs|jd|||S(s5return dict { packages -> list of matching provides }RR(t_computeAggregateDictResult(R R=RQRM((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyRRscCs|jd|||S(s5return dict { packages -> list of matching requires }RS(R(R R=RQRM((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyRSscCs|jd|S(s<return list of package requiring the name (any evr and flag)RT(R(R R=((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyRTscCs|jd|S(s<return list of package providing the name (any evr and flag)RU(R(R R=((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyRUscCs|jd|S(sCreturn list of package conflicting with the name (any evr and flag)RV(R(R R=((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyRVscCs|jd|S(s=return list of package obsoleting the name (any evr and flag)RW(R(R R=((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyRWsc s|s|jdS|jd}td|D}i}d}d }d }dfd}x~t|j|dtdD][} | d} || kr|||  rqn| }| }| |kr|| || sR cSsYt|d|d}|r!|St|d|d|df|d|d|df S(s4 Compare two pkgtup's (ignore arch): n, a, e, v, r. iiii(R(R(txtyR$((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyt_pkgtup_nevr_cmpscs||dkS(Ni((RR(R(s3/usr/lib/python2.7/site-packages/yum/packageSack.pyt_pkgtup_nevr_eqsRDR(iN(RRRR'RER( R RXtobsdictRCtnobsdictt last_nametlast_pkgt last_pkgtupRR;R=((Rs3/usr/lib/python2.7/site-packages/yum/packageSack.pyRYs(     cCs|jd|S(s#return list of packages by filenameR[(R(R R=((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyR[scCsdS(saAdd a pkgobject to the packageSack. This is a meaningless operation for the MetaSack.N((R R\((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyR]scCs(x!|jjD]}|jqWdS(sbuilds the useful indexes for searching/querying the packageSack This should be called after all the necessary packages have been added/deletedN(RRR^(R R((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyR^scCs|jjj|dS(s2Delete a pkgobject if it exists in every sub-sack.N(R1RR_(R R\((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyR_scCs9|s|jdd||S|j|jd|d|S(sReturns a list of packages. Note that the packages are always filtered to those matching the patterns/case. An optional repoid allows you to easily get data for a specific repo. RRaRbN(RRRR(R R`RaRb((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyRs   cGsB|s%|j}|dd|||S|j|jd|||S(s Add an "excluder" for all packages in the repo/sack. Can basically do anything based on nevra, changes lots of exclude decisions from "preload package; test; delPackage" into "load excluder". Excluderid is used so the caller doesn't have to track "have I loaded the excluder for this repo.", it's probably only useful when repoid is None ... if it turns out utterly worthless then it's still not a huge wart. RfN(RRRRf(R R`RcRdRetcalr((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyRfs  cCsf|j}|d|||}t|}| rb|s=|rbdj|pLg}td|n|S(sreturn list of newest packages based on name, arch matching this means(in name.arch form): foo.i386 and foo.noarch are not compared to each other for highest version only foo.i386 and foo.i386 will be compared. Note that given: foo-1.i386; foo-2.i386 and foo-3.x86_64 The last _two_ pkgs will be returned, not just one of them. Rxs, sNo Package Matching %s(RtpackagesNewestByNameArchtjoinR(R RwRaRbRRtui_pats((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyRxs  cCso|jd|||}t|}| rk|s7|rk|rF|}ndj|pUg}td|n|S(sreturn list of newest packages based on name matching this means(in name.arch form): foo.i386 and foo.noarch will be compared to each other for highest version.Rys, sNo Package Matching %s(RtpackagesNewestByNameRR(R R=RaRbRR((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyRys    cCs|jd||S(s,returns a list of pkg tuples (n, a, e, v, r)Rz(R(R RaRb((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyRzs cCs(x!|jjD]}|jqWdS(N(RRR{(R R((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyR{#scCs+x$|jjD]}|j|qWdS(sDexclude incompatible arches. archlist is a list of compatible archesN(RRR}(R R|R((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyR}'scCs|jd|||S(NR(R(R R~RR3((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyR,scCs|jd||S(NR(R(R RR((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyR/sc Csg}g}d}x|jjD]}t|dr"ggg}}}y|j|\}}}Wntk r}q"nX|j||j||dkrt|}q|jt|}q"q"Wt j |}t j |}|dkrg}n t |}|||fS(NR( RRRR"RRtextendRt intersectionRRR%( R RRRRRRJtmtu((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyR2s*       cGsg}x~t|jjD]g}t||rt||}yt||}Wntk riqnX|r|j|qqqW|S(N(R'RRR"tgetattrtapplyRR(R t methodNameRetresultRtmethodt sackResult((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyRMs cGsi}x~t|jjD]g}t||rt||}yt||}Wntk riqnX|r|j|qqqW|S(N(R'RRR"RRRR(R RReRRRR((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyR\s N(NNN(NNN(%RRRR R RRR5R0R<RRBRRERRRSRTRURVRWRYR[R]R^R_RRfRxRyRzR{R}RRRRR(((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyRisD            "           t PackageSackcBsveZdZdZdZddZdZdZd"d"d"d"d"dZ ge dZ d"d#d Z d"d$d Z d Zd Zd ZdZdZe dZdZdZdZdZdZdZdZdZdZdZd"d"e dZd"d"e dZd"d"e dZ d"e dZ!dZ"d Z#d!Z$RS(%s*represents sets (sacks) of Package ObjectscCsktj|i|_i|_i|_i|_i|_i|_i|_i|_ d|_ d|_ dS(Ni( RR tnevrat obsoletestrequirestprovidest conflictst filenamest pkgsByRepotpkgsByIDRRt indexesBuilt(R ((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyR ns          cCs5d}x(|jD]}|t|j|7}qW|S(Ni(RR(R R$R1((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyR sterrorcCsA|js=|dkr!tdq=|dkr=|jq=ndS(scheck to see if the indexes are built, if not do what failure demands either error out or build the indexes, default is to error outRs$Indexes not yet built, cannot searchtbuildN(RRR^(R tfailure((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyt _checkIndexess     cCs|jdS(s* Do nothing, mainly for the testing code. N(t clearIndexes(R ((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyRscCs ||_dS(N(R(R R((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyR0sc Cs?|jdd|||||f|jkrH|j|||||fS|dk r{|jj|ddddfg}n-g}x$|jjD]}|j|qWg}x|D]} |r|| jks|r|| jks|r|| j ks|r|| j ks|r*|| j kr*qn|j | qW|S(s6return list of pkgobjects matching the nevra requestedRRN( RRRtgetRt itervaluesRR=R>R?R@RAR( R R=R>R?R@RARt pkgsbyRepoRRF((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyRBs$ ' cCs|jddg}t}xX|D]P}||kr>q&n|j||j|jj|ddddfgq&W|rg|D]}|j^qS|S(s6return list of pkgobjects matching the names requestedRRN(RRRRRRRR;(R RCRDRtdoneR=R((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyREs    /cCs|jdd|dkr%d}n6t|ttdtfkr[tjj|}ni}xK|jj |gD]4}|j d|||f}|rw||| list of matching provides }RRRit/N(NNN(NNN(RRRRtunicodetrpmUtilst miscutilststringToVersionRRt matchingPrcosR[RgR(R R=RQRMRRFthitsthit((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyRRs  ! cCs|jdd|dkr%d}n6t|ttdtfkr[tjj|}ni}xK|jj |gD]4}|j d|||f}|rw||| list of matching requires }RRRN(NNN( RRRRRRRRRRR(R R=RQRMRRFR((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyRSs  !c Cs|jddt||}tj|\}}\}}}g} g} ||krl| j||nxB| D]:} | j||||||ffrs| j| qsqsW|dkr| Stj|s| S| j|j|tj | S(NRRR( RRRtstring_to_prco_tupleRt checkPrcoRt re_filenameR[R( R R=tprcotypetprcodictRHtfRJRKRLt basic_resultstresultsRF((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyt searchPrcos !  $ cCs|j|dS(s3return list of package requiring the item requestedR(R(R R=((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyRTscCs|j|dS(s3return list of package providing the item requestedR(R(R R=((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyRUscCs|j|dS(s6return list of package conflicting with item requestedR(R(R R=((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyRVscCs|j|dS(s4return list of package obsoleting the item requestedR(R(R R=((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyRWscCsi}xN|jD]@}t|jdkr4qn|j|jgj|jqW|sa|Std|jD}g}x*|D]"}||kr|j|qqWx|D] }||=qW|S(sEreturns a dict of obsoletes dict[obsoleting pkgtuple] = [list of obs]icss|]}|jVqdS(N(R;(RR((s3/usr/lib/python2.7/site-packages/yum/packageSack.pys s( RRRRgR;RRRyR(R RXtobsRFt newest_tupsttogoR((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyRY s#    cCstS(sb Is calling pkg.returnFileEntries(primary_only=True) faster than using searchFiles(). (R(R ((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyRZ#scCs2|jdd||jkr*|j|SgSdS(s& Return list of packages by filename. RRN(RR(R R=((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyR[(s cCs.||krg||R?R@((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyR]Cs   cCsP|jx6|jD]+}x"|j|D]}|j|q(WqWd|_dS(sbuilds the useful indexes for searching/querying the packageSack This should be called after all the necessary packages have been added/deletediN(RRRR(R R`R\((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyR^Ns  cCsLi|_i|_i|_i|_i|_i|_i|_d|_dS(Ni(RRRRRRRR(R ((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyR[s       cCsx?|jdD].\}}\}}}|j|j||qWx?|jdD].\}}\}}}|j|j||qRWx?|jdD].\}}\}}}|j|j||qWx?|jdD].\}}\}}}|j|j||qWxD|jD]6}x-|j|D]}|j|j||q+WqW|j|j |j ||j \} } } } } |j|j | | | | | f||j|j | ddddf|dS(NRRRR(t returnPrcoRRRRRtreturnFileTypestreturnFileEntriesRRRR;RR(R R\RHtflRJRKRLtftypetfileR=RAR>R?R@((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyRgs((((%cCsx?|jdD].\}}\}}}|j|j||qWx?|jdD].\}}\}}}|j|j||qRWx?|jdD].\}}\}}}|j|j||qWx?|jdD].\}}\}}}|j|j||qWxD|jD]6}x-|j|D]}|j|j||q+WqW|j|j |j ||j \} } } } } |j|j | | | | | f||j|j | ddddf|dS(NRRRR(RRRRRRRRRRRR;RR(R R\RHRRJRKRLRRR=RAR>R?R@((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyt_delPackageFromIndexzs((((%cCs6|j|j|j||jr2|j|ndS(sdelete a pkgobjectN(RRR`RR(R R\((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyR_s cCsg}|dkr=xM|jD]}|j|j|qWn%y|j|}Wntk ranX|rt||| dd}|d|d}n|S(s2return list of all packages, takes optional repoidRs repo-pkgkeyiiN(RRRtKeyErrorR(R R`RaRbt returnListR1((s3/usr/lib/python2.7/site-packages/yum/packageSack.pyRs   cCs)i}|rZ|jdd|jj|dddddf}|srtd|qrn|jd|d|}x}|D]u}|j|jf|kr|||j|jfs$     2