a !c+@sJdZddlmZmZddlmZddlmZmZmZddl 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&d'Z-dS),z% Assorted utility functions for yum. )print_functionabsolute_import)unicode_literals)base64_decodebytes basestringunicode)*NZsha256cCstdurtdjat|S)z( Tests if a string is a shell wildcard. Nz [*?]|\[.+\])_re_compiled_glob_matchrecompilesearch)sr0/usr/lib/python3.9/site-packages/dnf/yum/misc.pyre_glob.s rcCsDtdur(tdj}tdj}||fatD]}||r,dSq,dS)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 ||_dSN)_GenericHolder__iter)selfiterrrr__init__MszGenericHolder.__init__cCs|jdurt||jSdSr)rrrrrr__iter__Ps zGenericHolder.__iter__cCs t||rt||St|dSr)hasattrgetattrKeyError)ritemrrr __getitem__Ts  zGenericHolder.__getitem__cCsddt|DS)z!Return a dictionary of all lists.cSs"i|]\}}t|tur||qSr)typelist).0keyZlist_rrr \s  z+GenericHolder.all_lists..)varsitemsrrrr all_listsZszGenericHolder.all_listscCs0|D]\}}t||g|q |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  rcCstdd|}t}d}d}|dD]d}|drZ op_importglobbasenameshutilcopychmod) r@rLZgpgdirZ make_ro_copyctxfpZrodirfrZZro_fZoptsrrrimport_key_to_pubrings&  (    *rac Cst}z.t|}tj|d}dtjj|f}Wn"t yXdtjj|f}Yn0dtjj |f}t t |}|D]>}t |}t|dr|t|ddkr||d|kr||Sq|tj|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)rRgeteuidpwdgetpwuidrVZi18nZucdconstZPREFIXr ZTMPDIRsortedrYlstatS_ISDIRS_IMODEtempfileZmkdtemp) uidZusertupusernamercdirpathZ cachedirsZthisdirZstatsZcachedirrrr getCacheDirs   ( rqcCsbg}t|}t|}d}||krL||}||||||7}||8}q|||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 rwc CsFzt|Wn2ty@}z|jtjkr,WYd}~n d}~00dS)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)rRunlinkOSErrorerrnoENOENT)filenameerrrunlink_fs  r~Fc Csvz t|WStyp}zL|jtjtjfvrtd"}|}t|WdWS1s20YWnttfy\tYS0dS)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)rWreadrJIOError ValueErrorrRgetuid)fodatarrr _getloginuids  ,rcCstdurtatS)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}|d}|dkr@||d}|dvr@|d|}|durTtjd|rt|}t|}|r|r|j|jkr|Sztj||dWn4t y}ztjt |WYd}~n d}~00|r|rt ||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)z.zckz.xzz.bz2z.gzz.lzmaz.zstz(Could not determine destination filenamei) rfindrV exceptionsZ MiscErrorrst_mtimelibdnfZutils decompress RuntimeErrorstrrRutime) r|destZcheck_timestampsoutZdot_posextfirr}rrrrs,    &rc Csg}t|D]}t|t}|D]^}td|r2q |}|}|sHq |rt|dd}|dd}||q | |q Wdq1s0Yq|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) rYrWr rrstriplstripreplacer,r;rs)ZthisglobZ line_as_listresultsfnamer`rBrrrread_in_items_from_dot_dir9s"    ,r)NT)F)NF)T).r3Z __future__rrrZ dnf.pycomprrrrZ libdnf.utilsrZ dnf.constrVZ dnf.cryptoZdnf.exceptionsZdnf.i18nrzrYr9rRZos.pathrfr r[rmrr rrrrobjectrrCrMrarqrwr~rrrrrrrrrrsJ  #   $