eaiovnaovbqoebvqoeavibavo 3 ft`W.@sZdZddlmZmZddlmZddlmZmZmZddl Tddl Z ddl Z ddlZ ddlZ ddlZ ddlZddlZddlZddlZddlZddlZddlZddlZddlZdgZdadd Zdad d Zd d ZGddde Z!ddZ"ddZ#d,ddZ$ddZ%ddZ&ddZ'd-ddZ(d d!Z)da*d"d#Z+d.d$d%Z,d&d'Z-d(d)Z.d/d*d+Z/dS)0z% Assorted utility functions for yum. )print_functionabsolute_import)unicode_literals)base64_decodebytes basestringunicode)*NZsha256cCstdkrtjdjat|S)z( Tests if a string is a shell wildcard. Nz [*?]|\[.+\])_re_compiled_glob_matchrecompilesearch)sr/usr/lib/python3.6/misc.pyre_glob.s rcCsFtdkr(tjdj}tjdj}||faxtD]}||r.dSq.WdS)zC Tests if a string needs a full nevra match, instead of just name. Nz.*([-.*?]|\[.+\]).z[0-9]+:TF)_re_compiled_full_matchr r match)r ZoneZtwoZrecrrrre_full_search_needed6s   rcCstdS)Nr)_default_checksumsrrrrget_default_chksum_typeDsrc@s:eZdZdZd ddZddZddZd d Zd d ZdS) GenericHolderzGeneric 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 itNcCs ||_dS)N)_GenericHolder__iter)selfiterrrr__init__MszGenericHolder.__init__cCs|jdk rt||jSdS)N)rr)rrrr__iter__Ps zGenericHolder.__iter__cCs t||rt||St|dS)N)hasattrgetattrKeyError)ritemrrr __getitem__Ts  zGenericHolder.__getitem__cCsddt|jDS)z!Return a dictionary of all lists.cSs"i|]\}}t|tkr||qSr)typelist).0keyZlist_rrr \sz+GenericHolder.all_lists..)varsitems)rrrr all_listsZszGenericHolder.all_listscCs4x.|jjD]\}}t|j|gj|qW|S)z7 Concatenate the list attributes from 'other' to ours. )r(r'r& setdefaultextend)rotherr$valrrr merge_lists_szGenericHolder.merge_lists)N) __name__ __module__ __qualname____doc__rrr r(r-rrrrrGs  rcCstjdd|}tj}d}d}xn|jdD]`}|jdr>d}q*|rT|jdkrTd}q*|rf|jdrfPq*|rx|jdrxPq*|r*|j|dq*Wt|j S) z,Convert ASCII-armored GPG key to binary s ? rs$-----BEGIN PGP PUBLIC KEY BLOCK-----s"-----END PGP PUBLIC KEY BLOCK-----=) r subioBytesIOsplit startswithstripwritergetvalue)rawkeyblockZinblockZ pastheaderslinerrr procgpgkeyes  rAcCsPxJ|jddD]:}|d|krt|dd}||kr8dS||krDdSdSqWd S) ab 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. namez gpg-pubkeyversionreleaserr3)ZdbMatchint)ZtskeyidZ timestampZhdrZ installedtsrrr keyInstalleds rJTc Cstjj|stj|tjj|tjj}ttjj |dd}|j dWdQRX|j ||r|d}tjj|stj|ddxFt j |dD]4}tjj |}|d|} tj|| tj| dqWd } ttjj |dd d}|j | WdQRXd SQRXWdQRXdS) Nzgpg.confwbr4z-roi)modez/*/zlock-never no-auto-check-trustdb trust-model direct no-expensive-trust-checks no-permission-warning preserve-permissions wT)ospathexistsmakedirsdnfZcryptoZ pubring_dirZContextopenjoinr<Z op_importglobbasenameshutilcopychmod) r>rIZgpgdirZ make_ro_copyZctxfpZrodirfrWZro_fZoptsrrrimport_key_to_pubrings&      r]c Cstj}y.tj|}tjj|d}dtjj|f}Wn$t k rZdtjj|f}YnXdtjj |f}t t j |}xB|D]:}tj |}t|drt|ddkr|d|kr|SqWtj|tjj d}|S)zqreturn a path to a valid and safe cachedir - only used when not running as root or when --tempcache is setrz%s-%s-z%s/%s*i)prefixdir)rOgeteuidpwdgetpwuidrSZi18nZucdconstZPREFIXrZTMPDIRsortedrVlstatS_ISDIRS_IMODEtempfileZmkdtemp) ZuidZusertupZusernamer_dirpathZ cachedirsZthisdirZstatsZcachedirrrr getCacheDirs   (rkcCsfg}t|}t|}d}x6||krN||}|j|||||7}||8}qW|j||d|S)zE Given a seq, split into a list of lists of length max_entries each. rN)lenr"append)seqZ max_entriesretZnumZbegendrrr seq_max_splits  rqcCsDytj|Wn0tk r>}z|jtjkr.WYdd}~XnXdS)z| 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)rOunlinkOSErrorerrnoENOENT)filenameerrrunlink_fs  rxFcCs^y tj|Stk rX}z2|jtjtjfkr2dS|rF|jtjkrFdSWYdd}~XnXdS)zF Call os.stat(), but don't die if the file isn't there. Returns None. N)rOstatrsrtruENOTDIRZEACCES)rvZ ignore_EACCESrwrrrstat_fs r{cCsFy$td}|j}t|SQRXWnttfk r@tjSXdS)z 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. z/proc/self/loginuidN)rTreadrHIOError ValueErrorrOgetuid)fodatarrr _getloginuids  rcCstdkrtatS)z 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)_cached_getloginuidrrrrr getloginuid src Cs|r |}nJd}|jd}|dkr@||d}|d kr@|d|}|dkrTtjjd |rt|}t|}|r|r|j|jkr|Sytjj||d Wn2t k r}ztjjt |WYdd}~XnX|r|rt j ||j|jf|S) ztake a filename and decompress it into the same relative location. When the compression type is not recognized (or file is not compressed), the content of the file is copied to the destinationN.r.zck.xz.bz2.gz.lzma.zstz(Could not determine destination filenamei)rrrrrr) rfindrS exceptionsZ MiscErrorr{st_mtimelibdnfZutils decompress RuntimeErrorstrrOutime) rvdestcheck_timestampsoutZdot_posZextZfirrwrrrrs,    "rcCs:tjj|}|d7}tjj|s.tj|dd|d|S)Nz/geni)rLrM)rOrPdirnamerQrR)rvgenerated_namerrrrcalculate_repo_gen_dest8s   rcCst||}t||ddS)z 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. T)rr)rr)rvrrrrrrepo_gen_decompress@s rc Csg}xtj|D]}t|n}xf|D]^}tjd|r6q$|j}|j}|sLq$|rx|jdd}|jdd}|j|jq$|j |q$WWdQRXqW|S)a( 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. z\s*(#|$)  ,N) rVrTr rrstriplstripreplacer*r9rm)ZthisglobZ line_as_listresultsZfnamer\r@rrrread_in_items_from_dot_dirHs"     r)NT)F)NF)T)0r1Z __future__rrrZ dnf.pycomprrrryZ libdnf.utilsrZ dnf.constrSZ dnf.cryptoZdnf.exceptionsZdnf.i18nrtrVr7rOZos.pathrbr rXrirr rrrrobjectrrArJr]rkrqrxr{rrrrrrrrrrrsN  #   #