[/\c@@sTdZddlmZmZddlmZddlmZddlmZm Z m Z ddl Tddl Z ddl ZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZedd d d d gZd gZda!d Z"da#dZ$de%fdYZ&dZ'd%ddZ(de%fdYZ)dZ*dZ+de,dZ-dZ.dZ/dZ0dZ1e2dZ3dZ4da5d Z6de2e2d!Z7d"Z8e2d#Z9e,d$Z:dS(&u% Assorted utility functions for yum. i(tprint_functiontabsolute_import(tunicode_literals(t MiscError(tbase64_decodebytest basestringtunicode(t*Numd5usha1usha256usha384usha512cC@s+tdkr!tjdjant|S(u( Tests if a string is a shell wildcard. u [*?]|\[.+\]N(t_re_compiled_glob_matchtNonetretcompiletsearch(ts((s0/usr/lib/python2.7/site-packages/dnf/yum/misc.pytre_glob3s cC@sdtdkr?tjdj}tjdj}||fanxtD]}||rFtSqFWtS(uC Tests if a string needs a full nevra match, instead of just name. u.*([-.*?]|\[.+\]).u[0-9]+:N(t_re_compiled_full_matchR R R tmatchtTruetFalse(R tonettwotrec((s0/usr/lib/python2.7/site-packages/dnf/yum/misc.pytre_full_search_needed;s   t ChecksumscB@szeZdZd eedZdZeddZdZ ddZ d Z d d Z d Z d d ZRS(un Generate checksum(s), on given pieces of data. Producing the Length and the result(s) when complete. cC@s|dkrt}ng|_g|_d|_t}x|D]}|dkr[d}n||krmq@n|tkrtj|}n|rq@nt d||j ||jj ||jj |q@W| r| rt dndS(Niushausha1u(Error Checksumming, bad checksum type %su*Error Checksumming, no valid checksum type( R t_default_checksumst _sumalgost _sumtypest_lentsett_available_checksumsthashlibtnewRtaddtappend(tselft checksumstignore_missingt ignore_nonetdonetsumtypetsumalgo((s0/usr/lib/python2.7/site-packages/dnf/yum/misc.pyt__init__Ns,             cC@s|jS(N(R(R"((s0/usr/lib/python2.7/site-packages/dnf/yum/misc.pyt__len__istfgetcC@s|jS(N(R(R"((s0/usr/lib/python2.7/site-packages/dnf/yum/misc.pytmscC@s^|jt|7_xB|jD]7}t|trC|jdn|}|j|qWdS(Nuutf-8(RtlenRt isinstanceRtencodetupdate(R"tdataR(((s0/usr/lib/python2.7/site-packages/dnf/yum/misc.pyR0os$iicC@s |j|}|j||S(N(treadR0(R"tfotsizeR1((s0/usr/lib/python2.7/site-packages/dnf/yum/misc.pyR2us cC@s@i}x3t|j|jD]\}}|j||d}n|j|S(Niushausha1(R RR9(R"tchecksum((s0/usr/lib/python2.7/site-packages/dnf/yum/misc.pyR6s    cC@s@i}x3t|j|jD]\}}|j||d}n|j|S(Niushausha1(R RR<(R"R:((s0/usr/lib/python2.7/site-packages/dnf/yum/misc.pyR;s    Ni(t__name__t __module__t__doc__R RR)R*tpropertytlengthR0R2R9R6R<R;(((s0/usr/lib/python2.7/site-packages/dnf/yum/misc.pyRJs     cC@stdS(Ni(R(((s0/usr/lib/python2.7/site-packages/dnf/yum/misc.pytget_default_chksum_typesiic C@s(t|trny2t|d|}t||||SWdQXWqnttfk rjtd|qnXnyt|g}x5|j||r|dk r|j |krPqqW|dk r||j krd||j |fS|j |SWn)ttfk r#}td|nXdS(utakes filename, hand back Checksum of it sumtype = md5 or sha/sha1/sha256/sha512 (note sha == sha1) filename = /path/to/file CHUNK=65536 by defaulturbNu#Error opening file for checksum: %su!%u!%su#Error reading file for checksum: %s( R.RtopenR:tIOErrortOSErrorRRR2R RAR6(R'tfiletCHUNKtdatasizeR3R1te((s0/usr/lib/python2.7/site-packages/dnf/yum/misc.pyR:s t GenericHoldercB@s>eZdZddZdZdZdZdZRS(uGeneric 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 itcC@s ||_dS(N(t_GenericHolder__iter(R"titer((s0/usr/lib/python2.7/site-packages/dnf/yum/misc.pyR)scC@s$|jdk r t||jSdS(N(RKR RL(R"((s0/usr/lib/python2.7/site-packages/dnf/yum/misc.pyt__iter__scC@s,t||rt||St|dS(N(thasattrtgetattrtKeyError(R"titem((s0/usr/lib/python2.7/site-packages/dnf/yum/misc.pyt __getitem__s cC@sdt|jDS(u!Return a dictionary of all lists.cS@s1i|]'\}}t|tkr||qS((ttypetlist(t.0tkeytlist_((s0/usr/lib/python2.7/site-packages/dnf/yum/misc.pys s (tvarstitems(R"((s0/usr/lib/python2.7/site-packages/dnf/yum/misc.pyt all_listsscC@sFx?|jjD]+\}}t|j|gj|qW|S(u7 Concatenate the list attributes from 'other' to ours. (RZRYRXt setdefaulttextend(R"totherRVtval((s0/usr/lib/python2.7/site-packages/dnf/yum/misc.pyt merge_listss#N( R=R>R?R R)RMRRRZR_(((s0/usr/lib/python2.7/site-packages/dnf/yum/misc.pyRJs     cC@stjdd|}tj}d}d}x|jdD]}|jdr[d}q=|r||jdkr|d}q=|r|jdrPq=|r|jdrPq=|r=|j|dq=q=Wt|j S( u-Convert ASCII armoured GPG key to binary s ?s is$-----BEGIN PGP PUBLIC KEY BLOCK-----its"-----END PGP PUBLIC KEY BLOCK-----t=( R tsubtiotBytesIOtsplitt startswithtstriptwriteRtgetvalue(trawkeytblocktinblockt pastheaderstline((s0/usr/lib/python2.7/site-packages/dnf/yum/misc.pyt procgpgkeys    cC@skxd|jddD]P}|d|krt|dd}||krLdS||kr\dSdSqqWd S( ub 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 an 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. unameu gpg-pubkeyuversionureleaseiiiii(tdbMatchtint(ttstkeyidt timestampthdrt installedts((s0/usr/lib/python2.7/site-packages/dnf/yum/misc.pyt keyInstalleds   c C@srtjj|s"tj|ntjj|8tjj"}ttjj |dd}|j dWdQX|j ||r^|d}tjj|s^tj|ddx[t j |dD]F}tjj |}|d|} tj|| tj| dqWd } ttjj |dd d}|j | WdQXq^ntSWdQXWdQXdS( Nugpg.confuwbR`u-rotmodeiu/*u/ulock-never no-auto-check-trustdb trust-model direct no-expensive-trust-checks no-permission-warning preserve-permissions uw(tostpathtexiststmakedirstdnftcryptot pubring_dirtContextRCtjoinRht op_importtglobtbasenametshutiltcopytchmodR( RjRstgpgdirt make_ro_copytctxtfptrodirtfRtro_ftopts((s0/usr/lib/python2.7/site-packages/dnf/yum/misc.pytimport_key_to_pubrings(!  $c C@stj}y?tj|}tjj|d}dtjj|f}Wn't k rtdtjj|f}nXdtjj |f}t t j |}xW|D]O}tj |}t|drt|ddkr|d|kr|SqWtjd|dtjj }|S(uqreturn a path to a valid and safe cachedir - only used when not running as root or when --tempcache is setiu%s-%s-u%s/%s*iitprefixtdir(RytgeteuidtpwdtgetpwuidR}ti18ntucdtconsttPREFIXRPtTMPDIRtsortedRtlstattS_ISDIRtS_IMODEttempfiletmkdtemp( tuidtusertuptusernameRtdirpatht cachedirstthisdirtstatstcachedir((s0/usr/lib/python2.7/site-packages/dnf/yum/misc.pyt getCacheDir7s   6cC@s|dkr!tj|d}nB|dkrBtj|d}n!|dkrctj|d}nt|d}xtry|jd}Wnt k rPnX|sPny|j |Wqut t fk r}d|t |f}t jj|quXquW|j|jdS(Nubz2uruxzugzuwbiuError writing to file %s: %s(tbz2tBZ2FiletlzmatLZMAFiletgziptGzipFileRCRR2RDRhREtstrR}t exceptionsRtclose(tsourcetdesttztypets_fnt destinationR1RItmsg((s0/usr/lib/python2.7/site-packages/dnf/yum/misc.pyt_decompress_chunkedOs*      cC@s~g}t|}t|}d}xB||krh||}|j|||!||7}||8}q'W|j|||S(uE Given a seq, split into a list of lists of length max_entries each. i(R-RTR!(tseqt max_entriesR7tnumtbegtend((s0/usr/lib/python2.7/site-packages/dnf/yum/misc.pyt seq_max_splitks    cC@sCytj|Wn+tk r>}|jtjkr?q?nXdS(u| 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(RytunlinkREterrnotENOENT(tfilenameRI((s0/usr/lib/python2.7/site-packages/dnf/yum/misc.pytunlink_fys cC@siytj|SWnQtk rd}|jtjtjfkrBdS|r^|jtjkr^dSnXdS(uF Call os.stat(), but don't die if the file isn't there. Returns None. N(RytstatRERRtENOTDIRR tEACCES(Rt ignore_EACCESRI((s0/usr/lib/python2.7/site-packages/dnf/yum/misc.pytstat_fscC@sTy/td}|j}t|SWdQXWnttfk rOtjSXdS(u Get the audit-uid/login-uid, if available. os.getuid() is returned instead if there was a problem. Note that no caching is done here. u/proc/self/loginuidN(RCR2RqRDt ValueErrorRytgetuid(R3R1((s0/usr/lib/python2.7/site-packages/dnf/yum/misc.pyt _getloginuids  cC@stdkrtantS(u Get the audit-uid/login-uid, if available. os.getuid() is returned instead if there was a problem. The value is cached, so you don't have to save it. N(t_cached_getloginuidR R(((s0/usr/lib/python2.7/site-packages/dnf/yum/misc.pyt getloginuids  c C@s|}|s|}n|jdrHd}|s|jdd}qn|jdsf|jdrd}|s|jdr|jdd}q|jdd}qn?|jdrd}|s|jdd}qn |}d }|r{| r{|r=t|}t|}|r=|r=|j|jkr=|Snt||||r{|r{tj||j|jfq{n|S( u|take a filename and decompress it into the same relative location. if the file is not compressed just return the fileu.gzugzuu.bzu.bz2ubz2u.xzuxzN(tendswithtreplaceR Rtst_mtimeRRytutime(RRtfn_onlytcheck_timestampstoutRtfiR3((s0/usr/lib/python2.7/site-packages/dnf/yum/misc.pyt decompresss:     "cC@sPtjj|}|d7}tjj|sDtj|ddn|d|S(Nu/genRxiu/(RyRztdirnameR{R|(Rtgenerated_nameR((s0/usr/lib/python2.7/site-packages/dnf/yum/misc.pytcalculate_repo_gen_dests  cC@s+t||}t|d|dtd|S(u 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. RRR(RRR(RRtcachedR((s0/usr/lib/python2.7/site-packages/dnf/yum/misc.pytrepo_gen_decompresssc C@sg}xtj|D]}t|}x|D]}tjd|rPq2n|j}|j}|stq2n|r|jdd}|jdd}|j|jq2n|j |q2WWdQXqW|S(u( 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 True. u\s*(#|$)u u u,N( RRCR RtrstriptlstripRR\ReR!(tthisglobt line_as_listtresultstfnameRRn((s0/usr/lib/python2.7/site-packages/dnf/yum/misc.pytread_in_items_from_dot_dirs"   i(;R?t __future__RRRtdnf.exceptionsRt dnf.pycompRRRRRt dnf.constR}t dnf.cryptotdnf.i18nRRRRRcRRytos.pathRR RRRRRR RRRRtobjectRRBR:RJRoRwRRRRRRRRRRRRRRR(((s0/usr/lib/python2.7/site-packages/dnf/yum/misc.pyts^                     N   #     +