v_c@sddlZddlZddlZddlZddlZddlZddlZddlZdZ dZ dZ e dZ dZdZdZd Zd Zd Zejd d ZdZdZdZdZdZdS(iNcCs(t|tjkr$t|}n|S(N(ttypettypest StringTypetstr(targ((s6/usr/lib/python2.7/site-packages/rpmUtils/miscutils.pyt rpmOutToStrsc Cs|\}}}|\}}}|dkr3d}n t|}t|}t|}|dkrld}n t|}t|}t|}tj|||f|||f}|S(Nt0(tNoneRtrpmt labelCompare( t.0t.1te1tv1tr1te2tv2tr2trc((s6/usr/lib/python2.7/site-packages/rpmUtils/miscutils.pyt compareEVR$s          $cCstd|dfd|dfS(s-compare version strings only using rpm vercmpt(R(R R((s6/usr/lib/python2.7/site-packages/rpmUtils/miscutils.pytcompareVerOnly9sc Csd}|jd}tj|tj}y|j|}Wntjk r}t|dkrmd}nt|dkrd}nt|dkrd}nt|dkrd}qn;Xt|\}} |d krtj |~d }n~|r|dkrtj |ddtj tj |j ||} | sd}tj |ddtj tj|j ||ntj tjnytj |Wntk r}nX|j||S( sTakes a transaction set and a package, check it's sigs. By default, only v4 sigs (header-only) will be verified (faster). By setting payload to True, v3 sigs (header+payload) will also be verified (slower). return 0 if they are all fine return 1 if the gpg key can't be found return 2 if the header or payload is in someway damaged return 3 if the key is not trusted return 4 if the pkg is not gpg or pgp signedispublic key not availaiableispublic key not availablespublic key not trustediserror reading package headeriiei(t setVSFlagstostopentO_RDONLYt hdrFromFdnoRterrorRt getSigInfotclosetlseekt setVerbositytRPMLOG_WARNINGt _verifySigst RPMLOG_INFOt RPMLOG_NOTICEtOSError( ttstpackagetpayloadtvaluet currentflagstfdnothdrteRtsiginfotvalid((s6/usr/lib/python2.7/site-packages/rpmUtils/miscutils.pytcheckSig=sH         cCstjtjdd}|j|}|dkrUd}|jd\}}}nd}d}d}d}|||f}||fS( sXchecks signature from an hdr hand back signature information and/or an error codetCs%|DSAHEADER?{%{DSAHEADER:pgpsig}}:{%|RSAHEADER?{%{RSAHEADER:pgpsig}}:{%|SIGGPG?{%{SIGGPG:pgpsig}}:{%|SIGPGP?{%{SIGPGP:pgpsig}}:{(none)}|}|}|}|s(none)it,ietMD5R(tlocalet setlocaletLC_ALLtsprintftsplit(R+tstringR-Rtsigtypetsigdatetsigidt infotuple((s6/usr/lib/python2.7/site-packages/rpmUtils/miscutils.pyR{s cCs|d}|tjs*|tjdkr7|d}nd}|d}|d}|d}|d krpd}n|||||f}|S( s^return a pkgtuple (n, a, e, v, r) from a hdr object, converts None epoch to 0, as well.tnameitarchtsrctversiontreleasetepochRN(RtRPMTAG_SOURCERPMtRPMTAG_SOURCEPACKAGER(R+R=R>tvertrelRBtpkgtuple((s6/usr/lib/python2.7/site-packages/rpmUtils/miscutils.pytpkgTupleFromHeaders        cCs4|\}}}}}t||d|||ffS(sureturns true if the package epoch-ver-rel satisfy the range requested in the reqtuple: ex: foo >= 2.1-1tEQ(t rangeCompare(treqtupleRGtntaR,tvtr((s6/usr/lib/python2.7/site-packages/rpmUtils/miscutils.pyt rangeChecksc Cs|\}}\}}}|\}}\} } } ||kr@dS| sN| rRdS|dkrgd} n|dkr|d} n|dkrd} n| dkrd}nt| | | f|||f} | dkr$|dkrdS|dkr|dkrdSn|dkr$|dkr!dSq$n| dkr|dkrO|dkrOdSn|dkrn|dkrndSn|dkr|dkrdSn|dkr|d krdSn|d!kr|d"krdSqn| dkr |d#kr|d$krdSn|d%kr dSndS(&s,returns true if provtuple satisfies reqtupleiitGTtGEii t>s>=RIit=tLEi tLTis<=t=(sEQiRT(RUi RVis<=RW( RURVsEQi iis<=RWRT(RURVi is<=RW(RQiRS(RQRRii RSs>=(RRi s>=( RQRRsEQRUii ii RSs>=RTs<=(sEQiRT( sEQRRRUii i RTs>=s<=(RUi s<=( sEQRURVRRii ii RTs<=RWs>=(RViRW(RURVi is<=RW( RQRRsEQii iRSs>=RT(RQRRii RSs>=(RURVi is<=RW(RR( RKt provtupletreqntreqftreqetreqvtreqrRLtfR,RNROR((s6/usr/lib/python2.7/site-packages/rpmUtils/miscutils.pyRJs^         !                        cCsDt|}|dkrgSi}yx|D]}d||trelIndexRFtverIndexREt epochIndexRBR=((s6/usr/lib/python2.7/site-packages/rpmUtils/miscutils.pyt splitFilenameDs     ic Cstjj}|j|}~|tjp1d}|dkrStjd|ntjdddt j |d|}x/|j |}|dkrPn|j |q}|jdS(sPerforms roughly the equivalent of rpm2cpio(8). Reads the package from fdno, and dumps the cpio payload to out, using bufsize as the buffer size.tgzips$Unsupported payload compressor: "%s"trbRN(trpmUtilst transactiontinitReadOnlyTransactionRRtRPMTAG_PAYLOADCOMPRESSORt RpmUtilsErrorRytGzipFileRRtfdopentreadtwriteR(R*touttbufsizeR%R+tcomprR^ttmp((s6/usr/lib/python2.7/site-packages/rpmUtils/miscutils.pytrpm2cpiocs  ' cCs|}|rt|tdks<t|tdkr|tjtjBtjB@r|d}|tj@r{|d}n|tj@r|d}n|tj@r|d}n|rd||f}qqn|S(s Return a human readable requirement string (ex. foobar >= 2.0) @param name: requirement name (ex. foobar) @param version: requirent version (ex. 2.0) @param flags: binary flags ( 0010 = equal, 0100 = greater than, 1000 = less than ) ilt RWRSRTs%s %s(RRt RPMSENSE_LESStRPMSENSE_GREATERtRPMSENSE_EQUAL(R=R@tflagsRf((s6/usr/lib/python2.7/site-packages/rpmUtils/miscutils.pyt formatRequirezs6        cCsn|d@}|dkrdS|dkr*dS|dkr:dS|dkrJdS|d krZd S|d krjd S|S( NiiiRViRQiRIi RUi RR(R(R((s6/usr/lib/python2.7/site-packages/rpmUtils/miscutils.pyt flagToStrings       cCs|dkrdS|jd}|dkrbytt|| }Wqhtk r^d}qhXnd}|jd}|dkr||d|!dkrd}n||d|!}||d}n1||ddkrd}n||d}d}|||fS( NRRpiRRoi(NR(NNN(RRrRtlongt ValueError(t verstringRlRBtjR@RA((s6/usr/lib/python2.7/site-packages/rpmUtils/miscutils.pytstringToVersions(       cCsytj|tj}Wntk r:}tjdnXy|j|}Wn/tjk r}tj |tjdnXt |tj krtj |tjdntj ||S(s>hand back the rpm header or raise an Error if the pkg is fubarsUnable to open filesRPM Error opening Packages RPM Error opening Package (type)( RRRR$R{RRRRRRR+(R%R&R*R,R+((s6/usr/lib/python2.7/site-packages/rpmUtils/miscutils.pythdrFromPackages   cCsbttdr^ttdr^tjtjtjtjtjtjgr^t j dq^ndS(Nt checkSignalst signalsCaughti( thasattrRRtsignaltSIGINTtSIGTERMtSIGPIPEtSIGQUITtSIGHUPtsystexit(((s6/usr/lib/python2.7/site-packages/rpmUtils/miscutils.pyRs (RRRyRRR3RtrpmUtils.transactionR{RRRtFalseR/RRHRPRJRmRxtstdoutRRRRRR(((s6/usr/lib/python2.7/site-packages/rpmUtils/miscutils.pyts.            >   P E