3 $g<@sdZddlZddlZddlZddlZddlZddlmZddlmZddl m Z ddl m Z ej ddd Zeed s|eje_ejZe d krddlZd d ZnddlmZdd ZddZddZddZddZddZejddZdS)zutility functions for up2dateN) up2dateErrors)config) getPlatform)sstrzrhn-client-toolsT)ZfallbackugettextdebcCs6tj}|d}d}d|kr$|d}|d}|||fS)NZIDzn/aZCODENAMEZRELEASE) lsb_releaseZget_distro_information)Z dist_infoZos_nameZ os_version os_releaser "/usr/lib/python3.6/up2dateUtils.py_getOSVersionAndReleasesr ) transactioncCs~tj}xn|jddD]~}d}t|d}t|d}|dd|dDkrtd dt|d|d D}d ||f}||}t|d ||f}|SWx|jdd D]}d}t|d}t|d}|dd|dDkrtddt|d|d D}d ||f}||}t|d ||f}|SWxL|jddD]2}t|d t|dt|df}|jj|SWtj ddS)NZ Providenamezoraclelinux-releasezsystem-release(releasever)versionreleasecss|]}t|VqdS)N)r).0provider r r ,sz*_getOSVersionAndRelease..Z providenamecss"|]\}}t|t|fVqdS)N)r)rnvr r r r-sZprovideversionz%s-%snamezredhat-releasecss|]}t|VqdS)N)r)rrr r r r8scss"|]\}}t|t|fVqdS)N)r)rrrr r r r9szdistribution-releasezxCould not determine what version of CloudLinux you are running. If you get this error, try running rpm --rebuilddb ) r ZinitReadOnlyTransactionZdbMatchrdictziptsZcloseDBrZRpmError)rhZ SYSRELVERrrZprovidesZosVersionReleaser r r r &s:      " cCs,tj}|drt|dSt\}}}|S)z3 Returns the version of redhat-release rpm ZversionOverride)rZinitUp2dateConfigstrr )Zcfgr rrr r r getVersionLs   rcCst\}}}|S)z4 Returns the name of the redhat-release rpm )r )r rrr r r getOSReleaseVs rcCst\}}}|S)z7 Returns the release of the redhat-release rpm )r )r rrr r r getRelease]s rcCsztjdtjr@tdd}|jj}ddi}||kr<||}|Stjd}tdkrv|dkrbd }|d krnd }|d 7}|S)Nz/etc/rpm/platformrzia32e-redhat-linuxzx86_64-redhat-linuxri486i586i686Zi386Zx86_64amd64z -debian-linux)r r!r")osaccessR_OKopenreadstripunamer)fdplatformreplaceZarchr r r getArchds    r.cCsdS)Nz12.12.2-1.module_el8.10.0+6894+77e439da.cloudlinuxr r r r r rysrccstj\}}tjd}tjd}tj|dtj|dz dVWdtj|dtj|dXtj|tj|<}tjdj|}x$|D]}|j |st |t j dqWWdQRXdS)zP Context manager to suppress errors matching the specified patterns N|)file) r$pipedupdup2closefdopenrecompilejoinsearchprintsysstderr)Zerror_patternsZread_endZ write_endZ old_stdoutZ old_stderrfZcombined_patternliner r r suppress_errors~s           rA)__doc__ contextlibr$r=r8gettextZup2date_clientrrZup2date_client.pkgplatformrZrhn.i18nrZ translationthasattrr_rr r rrrr.rcontextmanagerrAr r r r s0       &