v_c@sdZddlZddlZddlZddlZddlmZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddgZyddlZejdWnek rTdZnXddlmZmZddl Tyddl!Z!ddl"Z!Wnek rdZ!nXy+ddl#Z#e$d d d d d gZ%WnNek r&ddl&Z&ddl'Z'e$d d gZ%ddYdYZ#nXe$Z(xe)e%D]Z*ye#j+e*Wq=e,k rZ-e.e-e/re0e-j1dre(j2e*nej3de4e*IJe%j5e*q=Xq=Wx0dZD]Z*e*e%kre*gZ6PqqWedddl m7Z7m8Z8ddl9m:Z:m;Z;ia<ia=dZ>dZ?da@dZAeBdZCdaDdZEdZFdZGdaHdZIdZJdZKdd[d YZLd!d\d"YZMd]dd%ZNd&ZOd'd^d(YZPd)ZQd*d+ZReBd,ZSd-ZTd.ZUddeVd/ZWd0ZXdd1ZYd2eVd3d4ZZd5Z[d6Z\d7Z]d8Z^d9Z_d:Z`d;Zad<Zbd=Zcd>Zdd?d@Zed?dAZfdBZgdCjhdDeidEDZjeBdFZkdGZleBdHZmdIZndaodJZpddlqZqeVeBdKZrdLZsdMZtdNZudOZvdeBeBdPZweBdQZxeVdRZydazdSZ{dTZ|dUZ}dVZ~dWZdXZdS(_s% Assorted utility functions for yum. iN(tStringIOtgztbz2txz(tstringToVersiont flagToString(t*tmd5tsha1tsha256tsha384tsha512thashlibcBseZedZRS(cCs9|dkrtjS|dkr,tjStddS(NRRsBad checksum type(Rtnewtshat ValueError(talgo((s,/usr/lib/python2.7/site-packages/yum/misc.pyR 4s     (t__name__t __module__t staticmethodR (((s,/usr/lib/python2.7/site-packages/yum/misc.pyR 2ssdisabled for fipssChecksum type %s disabledsbroken hashlib(t MiscErrortFIPSNonCompliantError(tto_utf8t to_unicodecCsGt}t|trt}nt|tjkr7|S|j||S(s Take a value and use the same value from the store, if the value isn't in the store this one becomes the shared version. (t_share_data_storet isinstancetunicodet_share_data_store_uttypettypest TupleTypet setdefault(tvaluetstore((s,/usr/lib/python2.7/site-packages/yum/misc.pyt share_data[s  cCsiaiadS(N(RR(((s,/usr/lib/python2.7/site-packages/yum/misc.pyt unshare_datakscCs+tdkr!tjdjant|S(s( Tests if a string is a shell wildcard. s [*?]|\[.+\]N(t_re_compiled_glob_matchtNonetretcompiletsearch(ts((s,/usr/lib/python2.7/site-packages/yum/misc.pytre_globrs cstr[y5|rtjp!d}tjtj|jSWq[tjk rWq[Xn|rzjfdSfdS(s5 Compile shell wildcards, return a 'match' function. ics|jkS(N(tlower(R)(tpat(s,/usr/lib/python2.7/site-packages/yum/misc.pytscs |kS(N((R)(R,(s,/usr/lib/python2.7/site-packages/yum/misc.pyR-s( R*R&tIR'tfnmatcht translatetmatchterrorR+(R,t ignore_casetflags((R,s,/usr/lib/python2.7/site-packages/yum/misc.pytcompile_pattern{s    cCs+tdkr!tjdjant|S(s Tests if a string could be a filename. We still get negated character classes wrong (are they supported), and ranges in character classes. s[/*?]|\[[^]]*/[^]]*\]N(t_re_compiled_filename_matchR%R&R'R1(R)((s,/usr/lib/python2.7/site-packages/yum/misc.pyt re_filenames cCs$t|rtS|dkr tStS(s" Tests if a filename string, can be matched against just primary. Note that this can produce false negatives (Eg. /b?n/zsh) but not false positives (because the former is a perf hit, and the later is a failure). Note that this is a superset of re_primary_dirname(). s/usr/lib/sendmail(tre_primary_dirnametTruetFalse(tfilename((s,/usr/lib/python2.7/site-packages/yum/misc.pytre_primary_filenames   cCs'd|krtS|jdr#tStS(s~ Tests if a dirname string, can be matched against just primary. Note that this is a subset of re_primary_filename(). sbin/s/etc/(R9t startswithR:(tdirname((s,/usr/lib/python2.7/site-packages/yum/misc.pyR8s  cCsdtdkr?tjdj}tjdj}||fanxtD]}||rFtSqFWtS(sC Tests if a string needs a full nevra match, instead of just name. s.*([-.*?]|\[.+\]).s[0-9]+:N(t_re_compiled_full_matchR%R&R'R1R9R:(R)tonettwotrec((s,/usr/lib/python2.7/site-packages/yum/misc.pytre_full_search_neededs   cCsI|j}|jdrtS|jdr2tS|jdrEtStS(s8 Tests if a string is a "remote" URL, http, https, ftp. shttp://shttps://sftp://(R+R=R9R:(R)((s,/usr/lib/python2.7/site-packages/yum/misc.pyt re_remote_urls cCs,t|}|dkrgSyt|}Wntk r?n Xt|Syt|}|jWntk rz~n{X|dkst|d}d}}xI||kr|||kr||||<}|d7}n|d7}qW|| Sg}x*|D]"}||kr|j|qqW|S(s Return a list of the elements in s, but without duplicates. For example, unique([1,2,3,1,2,3]) is some permutation of [1,2,3], unique("abcabc") some permutation of ["a", "b", "c"], and unique(([1, 2], [2, 3], [1, 2])) some permutation of [[2, 3], [1, 2]]. For best speed, all sequence elements should be hashable. Then unique() will usually work in linear time. If not possible, the sequence elements should enjoy a total ordering, and if list(s).sort() doesn't raise TypeError it's assumed that they do enjoy a total ordering. Then unique() will usually work in O(N*log2(N)) time. If that's not possible either, the sequence elements must support equality-testing. Then unique() will usually work in quadratic time. ii(tlentsett TypeErrortlisttsorttAssertionErrortappend(R)tntutttlasttlastititx((s,/usr/lib/python2.7/site-packages/yum/misc.pytuniques6           t ChecksumscBszeZdZd eedZdZeddZdZ ddZ d Z d d Z d Z d d ZRS(sn Generate checksum(s), on given pieces of data. Producing the Length and the result(s) when complete. cCs|dkrt}ng|_g|_d|_t}x|D]}|dkr[d}n||krmq@n|tkrtj|}n4|rq@n(|t krt |n t d||j ||jj ||jj |q@W| r | r t dndS(NiRRs(Error Checksumming, bad checksum type %ss*Error Checksumming, no valid checksum type(R%t_default_checksumst _sumalgost _sumtypest_lenRFt_available_checksumsR R t_fips_noncompliantRRtaddRK(tselft checksumstignore_missingt ignore_nonetdonetsumtypetsumalgo((s,/usr/lib/python2.7/site-packages/yum/misc.pyt__init__ s.              cCs|jS(N(RX(R\((s,/usr/lib/python2.7/site-packages/yum/misc.pyt__len__%stfgetcCs|jS(N(RX(R\((s,/usr/lib/python2.7/site-packages/yum/misc.pyR-)scCs:|jt|7_x|jD]}|j|qWdS(N(RXRERVtupdate(R\tdataRb((s,/usr/lib/python2.7/site-packages/yum/misc.pyRf+siicCs |j|}|j||S(N(treadRf(R\tfotsizeRg((s,/usr/lib/python2.7/site-packages/yum/misc.pyRh0s cCs@i}x3t|j|jD]\}}|j||d}n|j|S(NiRR(R%RWRo(R\tchecksum((s,/usr/lib/python2.7/site-packages/yum/misc.pyRl;s    cCs@i}x3t|j|jD]\}}|j||d}n|j|S(NiRR(R%RWRr(R\Rp((s,/usr/lib/python2.7/site-packages/yum/misc.pyRqJs    Ni(RRt__doc__R%R:RcRdtpropertytlengthRfRhRoRlRrRq(((s,/usr/lib/python2.7/site-packages/yum/misc.pyRTs     tAutoFileChecksumscBs2eZdZeedZdZddZRS(sk Generate checksum(s), on given file/fileobject. Pretending to be a file object (overrrides read). cCs"||_t||||_dS(N(t_foRTR](R\RiR]R^R_((s,/usr/lib/python2.7/site-packages/yum/misc.pyRcXs cCst|j|S(N(tgetattrRw(R\tattr((s,/usr/lib/python2.7/site-packages/yum/misc.pyt __getattr__\sicCs|jj|j|S(N(R]RhRw(R\Rj((s,/usr/lib/python2.7/site-packages/yum/misc.pyRh_s(RRRsR:RcRzRh(((s,/usr/lib/python2.7/site-packages/yum/misc.pyRvTs iicCsyt|tjkr!|}nt|d}t|g}x5|j||rv|dk rB|j|krBPqBqBWt|tjkr|j n|dk r||jkrd||j |fS|j |SWn&t t fk r}t d|nXdS(stakes filename, hand back Checksum of it sumtype = md5 or sha/sha1/sha256/sha512 (note sha == sha1) filename = /path/to/file CHUNK=65536 by defaulttrs!%u!%ss#Error opening file for checksum: %sN(RRt StringTypestopenRTRhR%Rut StringTypetcloseRltIOErrortOSErrorR(RatfiletCHUNKtdatasizeRiRgte((s,/usr/lib/python2.7/site-packages/yum/misc.pyRpcs  cCst|}ytj|}Wn&tk rG}td||fnXx|D]}tjj|d|rt|d|||}qO| s|| jd|krOtjj |d|}|j |qOqOW|S(sfReturn all files in path matching ext, store them in filelist, recurse dirs return list objects Error accessing directory %s, %st/s%s( REtostlistdirRRtpathtisdirt getFileListR+tnormpathRK(Rtexttfilelisttextlentdir_listRtdtnewpath((s,/usr/lib/python2.7/site-packages/yum/misc.pyRs  "t GenericHoldercBs,eZdZddZdZdZRS(sGeneric Holder class used to hold other objects of known types It exists purely to be able to do object.somestuff, object.someotherstuff or object[key] and pass object to another function that will understand itcCs ||_dS(N(t_GenericHolder__iter(R\titer((s,/usr/lib/python2.7/site-packages/yum/misc.pyRcscCs$|jdk r t||jSdS(N(RR%R(R\((s,/usr/lib/python2.7/site-packages/yum/misc.pyt__iter__scCs)t||rt||St|dS(N(thasattrRxtKeyError(R\titem((s,/usr/lib/python2.7/site-packages/yum/misc.pyt __getitem__s N(RRRsR%RcRR(((s,/usr/lib/python2.7/site-packages/yum/misc.pyRs  cCstjdd|}t}d}d}x|jdD]}|jdrXd}q:|ry|jdkryd}q:|r|jdrPq:|r|jdrPq:|r:|j|dq:q:Wtj|j S( s-Convert ASCII armoured GPG key to binary s ?s is$-----BEGIN PGP PUBLIC KEY BLOCK-----its"-----END PGP PUBLIC KEY BLOCK-----t=( R&tsubRtsplitR=tstriptwritetbase64t decodestringtgetvalue(trawkeytblocktinblockt pastheaderstline((s,/usr/lib/python2.7/site-packages/yum/misc.pyt procgpgkeys    icCsn|d}tj|}|rjgtdt||D]}||||!^q;}dj|}n|S(s Given a key_info data from getgpgkeyinfo(), return an ascii fingerprint. Chop every 4 ascii values, as that is what GPG does. t fingerprintit (tbinasciithexlifytrangeREtjoin(tinfotchoptfpRQ((s,/usr/lib/python2.7/site-packages/yum/misc.pytgpgkey_fingerprint_asciis  6c Csg}ytj|}Wn%tk r@}tt|nXt|dkrbtdnx|D]}|jj}i|jd6t j d|dd6|jj d6|jj d6|j d6td 6td 6}x|jdD]{}t|tjsqn|j|krt|d r`|jtj} | d kr]t| d |dQtkeyidt timestampRtraw_keythas_sigt valid_sigthashed_subpaksiN(tpgpmsgtdecode_multiple_keyst ExceptionRtstrREt public_keytkey_idtuser_idtstructtunpackRRRR:tuser_idsRt signatureRtget_hashed_subpaktSIG_SUB_TYPE_CREATE_TIMER%tintRK( Rtmultiplet key_info_objstkeysRtkeyt keyid_blobRRttspkt((s,/usr/lib/python2.7/site-packages/yum/misc.pyt getgpgkeyinfos<       cCs d|d@S(s[Convert an integer representing a GPG key ID to the hex version string used by RPM s%08xl((R((s,/usr/lib/python2.7/site-packages/yum/misc.pyt keyIdToRPMVerscCswt|}xd|jddD]P}|d|krt|dd}||krXdS||krhdSdSqqWd S( sd Return if the GPG key described by the given keyid and timestamp are installed in the rpmdb. The keyid and timestamp should both be passed as integers. The ts is an rpm transaction set object Return values: - -1 key is not installed - 0 key with matching ID and timestamp is installed - 1 key with matching ID is installed but has a older timestamp - 2 key with matching ID is installed but has a newer timestamp No effort is made to handle duplicates. The first matching keyid is used to calculate the return result. tnames gpg-pubkeytversiontreleaseiiiii(RtdbMatchR(ttsRRthdrt installedts((s,/usr/lib/python2.7/site-packages/yum/misc.pyt keyInstalled s    cCstdkrtS|s#d|}ntjj|sEtj|nt|}|tjdtGTs>=tGERtEQtt t tfk r}d|t|f}tj|nX|sPny|j|Wqt t fk rL}d |t|f}tj|qXqW|j|jdS( Ns%s compression not availableRR{RRRisError reading from file %s: %ssError writing to file %s: %s(t_available_compressionR>RRtBZ2FiletlzmatLZMAFiletgziptGzipFileR}R9RhRRtEOFErrorRRR(tsourcetdesttztypetmsgts_fnt destinationRgR((s,/usr/lib/python2.7/site-packages/yum/misc.pyt_decompress_chunked s2       cCst||dddS(s1 Extract the bzipped contents of source to dest. RURN(RY(RSRT((s,/usr/lib/python2.7/site-packages/yum/misc.pyt bunzipFile/scCstjd}ttjd|}x|D]x}|jd|}x]|D]U}|d}|dd krxd}n t|}|d|d||d|d fSWq0Wd S( s}This takes the output of uname and figures out the pkgtup of the running kernel (name, arch, epoch, version, release).is/boot/vmlinuz*%s*t basenamestepochR,RtarchRRN(NNNNN(RtunameRRRR%R(RtvertfnstfntmithR((s,/usr/lib/python2.7/site-packages/yum/misc.pytget_running_kernel_pkgtup3s     (cCs2t|}|ddk r.|d|dfSdS(sgThis takes the output of uname and figures out the (version, release) tuple for the running kernel.iiiN(NN(RdR%(Rtpkgtup((s,/usr/lib/python2.7/site-packages/yum/misc.pyt"get_running_kernel_version_releaseGs s /var/lib/yumc Csg}d|df}d|df}tj|}tj|}xT|D]L}|jdrfqKntjj|}|jdd}|j|qKW|j|S(sreturns a list of the timestamps from the filenames of the unfinished transactions remaining in the yumlibpath specified. s%s/%sstransaction-all*stransaction-done*tdisabledstransaction-all.R(RtendswithRRRtreplaceRKRI( t yumlibpatht timestampsttsallgttsdonegttsallsttsdonesRattransR((s,/usr/lib/python2.7/site-packages/yum/misc.pytfind_unfinished_transactionsOs  cCseg}d|d|f}d|d|f}g}tjj|sH|Stjj|rt|d}|j}|jnt|d}|j}|jx-|D]%} | |krqn|j| qWx|D]} | jdd} | dkrqny| j\} } Wn)t k rI} d|} t j | nX|j | | fqW|S(sthis function takes the timestamp of the transaction to look at and the path to the yum lib dir (defaults to /var/lib/yum) returns a list of tuples(action, pkgspec) for the unfinished transaction elements. Returns an empty list if none. s%s/%s.%sstransaction-allstransaction-doneR{s Rs(Transaction journal file %s is corrupt.( RRRR}t readlinesRtremoveRiRRR>RRK(RRjtto_complete_itemst tsallpatht tsdonepatht tsdone_itemst tsdone_fottsall_fot tsall_itemsRtactiontpkgspecRRV((s,/usr/lib/python2.7/site-packages/yum/misc.pytfind_ts_remainingcs8         cCs~g}t|}t|}d}xB||krh||}|j|||!||7}||8}q'W|j|||S(sE Given a seq, split into a list of lists of length max_entries each. i(RERHRK(tseqt max_entriesRmtnumtbegtend((s,/usr/lib/python2.7/site-packages/yum/misc.pyt seq_max_splits    Rccs'|]}|dkrt|VqdS(i i i N(i i i (tchr(t.0RQ((s,/usr/lib/python2.7/site-packages/yum/misc.pys si cCst|tkrRyt|dWqtk rNt|djd}qXnGt|tkrv|jd}n#|dkrdStdt||j}|j dt }|j dd}|j dd}|j d d }|r|j d d }|j d d}n|S(s_ Returns xml-friendly utf-8 encoded string. Accepts utf-8, iso-8859-1, or unicode. sutf-8s iso-8859-1RsString expected, got %st&s&R4s<R0s>t"s"t's'N( RRRtUnicodeDecodeErrortencodeR%RtreprtrstripR0t _deletecharsRi(Rtattrib((s,/usr/lib/python2.7/site-packages/yum/misc.pytto_xmls&   cCsXytj|Wn@tk rS}|jtjtjtjtjfkrTqTnXdS(s| Call os.unlink, but don't die if the file isn't there. This is the main difference between "rm -f" and plain "rm". N(RtunlinkRterrnotENOENTtEPERMtEACCEStEROFS(R;R((s,/usr/lib/python2.7/site-packages/yum/misc.pytunlink_fs 'cCsiytj|SWnQtk rd}|jtjtjfkrBdS|r^|jtjkr^dSnXdS(sF Call os.stat(), but don't die if the file isn't there. Returns None. N(RtstatRRRtENOTDIRR%R(R;t ignore_EACCESR((s,/usr/lib/python2.7/site-packages/yum/misc.pytstat_fscCsXytd}Wntk r$dSX|j}yt|SWntk rSdSXdS(s Get the audit-uid/login-uid, if available. None is returned if there was a problem. Note that no caching is done here. s/proc/self/loginuidN(R}RR%RhRR(RiRg((s,/usr/lib/python2.7/site-packages/yum/misc.pyt _getloginuids   cCstdkrtantS(s Get the audit-uid/login-uid, if available. None is returned if there was a problem. The value is cached, so you don't have to save it. N(t_cached_getloginuidR%R(((s,/usr/lib/python2.7/site-packages/yum/misc.pyt getloginuids  cCsy3tjtjd|r2tjtjdnWnCtjk rx}tjdIJdtjdd SqAn|sy?t||||r|rtj||j|jfnWqt |qXn|S( s|take a filename and decompress it into the same relative location. if the file is not compressed just return the files.gzRRs.bzs.bz2Rs.xzRN( RhRiRRtst_mtimeR%RYRtutimeR(R;RTtfn_onlytcheck_timestampstoutRUtfiRi((s,/usr/lib/python2.7/site-packages/yum/misc.pyt decompress^sF      #  cCsstjj|d|}yt|d|dtSWn8ttfk rn}|rh|jtjkrhdSnXdS(s This is a wrapper around decompress, where we work out a cached generated name, and use check_timestamps. filename _must_ be from a repo. and generated_name is the type of the file. s/gen/RTRN( RRR>RR9RRRRR%(R;tgenerated_nametcachedRTR((s,/usr/lib/python2.7/site-packages/yum/misc.pytrepo_gen_decompressscCsg}xtj|D]}xt|D]}tjd|rGq)n|j}|j}|skq)n|r|jdd}|jdd}|j|jq)n|j |q)WqW|S(s'takes a glob of a dir (like /etc/foo.d/*.foo) returns a list of all the lines in all the files matching that glob, ignores comments and blank lines, optional paramater 'line_as_list tells whether to treat each line as a space or comma-separated list, defaults to Trues\s*(#|$)s Rt,( RR}R&R1RtlstripRitextendRRK(tthisglobt line_as_listtresultstfnameR((s,/usr/lib/python2.7/site-packages/yum/misc.pytread_in_items_from_dot_dirs   cCsMtdkrIyddlm}Wntk r?ddl}nX|andS(s Importing xElementTree all the time, when we often don't need it, is a huge timesink. This makes python -c 'import yum' suck. So we hide it behind this function. And have accessors. i(t cElementTreeN(t__cached_cElementTreeR%t xml.etreeRR(R((s,/usr/lib/python2.7/site-packages/yum/misc.pyt_cElementTree_imports   cCsttj|S(s) Lazily load/run: cElementTree.iterparse (RRt iterparse(R;((s,/usr/lib/python2.7/site-packages/yum/misc.pytcElementTree_iterparsescCsttj|S(s% Lazily load/run: cElementTree.parse (RRtparse(R;((s,/usr/lib/python2.7/site-packages/yum/misc.pytcElementTree_xmlparsescCs|dkr|Sg}xo|D]g}|jdkrbd|jkrGqn|jj|krwqqwn|j|krwqn|j|qW|S(s Given a list of packages, filter them for those "in" the repoid. uses from_repo for installed packages, used by repo-pkgs commands. t installedt from_repoN(R%trepoidt yumdb_infoRRK(R(RRmR*((s,/usr/lib/python2.7/site-packages/yum/misc.pytfilter_pkgs_repoids   cCs=tjtjd}x"|D]}||kr|SqWdSdS(s;Return the first invalid char found in the repoid, or None.s-_.:N(tstringt ascii_letterstdigitsR%(Rt allowed_charstchar((s,/usr/lib/python2.7/site-packages/yum/misc.pytvalidate_repoids   csd|}tjj|s+|SxZtj|D]I\}}fd||D}|tfd|D7}q;W|S(s>Return disk usage of the given filename, recursively for dirs.cSstj|jdS(Ni(RRt st_blocks(R((s,/usr/lib/python2.7/site-packages/yum/misc.pytusagesc3s$|]}tjj|VqdS(N(RRR(Rtentry(troot(s,/usr/lib/python2.7/site-packages/yum/misc.pys sc3s|]}|VqdS(N((RR(R(s,/usr/lib/python2.7/site-packages/yum/misc.pys s(RRRtwalktsum(RttotaltdirsRtpaths((RRs,/usr/lib/python2.7/site-packages/yum/misc.pyt disk_usages  $((R ssha1((i((RsRRRtos.patht cStringIORRRRR&RR>R;RRRRR/RRPRRRRLRNRKRR%trpmUtils.miscutilsRRRRtgpgme.editutilR RFRYRRRZRHtctypeR RRRRRRhR[RRRsRURRti18nRRRRR"R#R$R*R:R5R6R7R<R8R?RCRDRSRTRvRpRRRRRRRR9RRR R!R$R+R/R:RGRKRYRZRdRfRqR}RRRRRRRRRRRRRRRRRRRRRRRRRR(((s,/usr/lib/python2.7/site-packages/yum/misc.pyts                                  $            BO   2  !1  (  # "     .  !   # 4