j.ddlmZddlmZddlmZddlZddlZddlZddlZddlZddl Z ddl m Z m Z ddlmZddlmZmZmZdd lmZdd lmZdd lmZd ZGd deZGddee eZdS))print_function)division)absolute_importN)ABCMetaabstractmethod)time)INSTALLING_STATUSREMOVING_STATUSAcquireInterpreterLockError)with_metaclass)is_testing_enabled_repo)GroupInfoReaderiQceZdZdS)PkgManagerErrorN)__name__ __module__ __qualname__W/opt/cloudlinux/venv/lib64/python3.11/site-packages/clselect/baseclselect/pkgmanager.pyrr"sDrrceZdZdZdZdZdZdZdZddgZ e dZ e dZ e dZdZd Zed Ze d Zd Ze d Ze dZddZdZdZedZedZdZdZdZe j!dZ"edZ#edZ$edZ%dZ&edZ'dZ(edZ)dS) BasePkgManagerz Class responsible for all interactions with Yum, interpreter versions installation/removal and gathering info about already installed versions Nyumz--disableplugin=fastestmirrorcLt|ts4tdt |jt |d}ttj }d|d<tj |tj |tj d|S)Nz(run_background expects argv list, got {}abCLANGF)stdinstdoutstderrshellenv) isinstancelist TypeErrorformattyperopendictosenviron subprocessPopenDEVNULLSTDOUT)clsargvlogfilelog_fpr#s rrun_backgroundzBasePkgManager.run_background8s $%% :F#VDJJ$788:: :gt$$2:F  $$     rcL|j|jSt}||_|SN)_testing_repo_enabled_cacher)selfress r_testing_enabledzBasePkgManager._testing_enabledLs,  + 73 3%''+.( rc|jr%tj|jdStj|jdS)Nzyum_cache.dat.testing_enabledz yum_cache.dat)r;r+pathjoin _config_dirr9s r_yum_cache_filezBasePkgManager._yum_cache_fileUsA   S7<< 02QRR Rw||D,o>>>rctj|j}t|}t |jd5}|D]}||d ddddS#1swxYwYdS)Nw )rget_group_info _alt_namesr%keysr)rAwrite)r9groupsfgroups rupdate_yum_cachezBasePkgManager.update_yum_cache[s /@@fkkmm$$ $& , , & & &5 %%%% & & & & & & & & & & & & & & & & & & &sA<<BBc tj|j}n#t$rYdSwxYwt |jz t krdSt|jS)z;Return data from file or None if file is absent or outdatedN) r+statrAOSErrorrst_mtimeMAX_CACHE_AGE_SECr)read)r9rNs r_read_yum_cachezBasePkgManager._read_yum_cachebsx 74/00DD   44  FFT] "&7 7 74D())..000s  **c` tj|dS#ttf$rYdSwxYw)z* Silently remove file ignoring all errors N)r+removerOIOError)rJs r_remove_silentzBasePkgManager._remove_silentns?  IaLLLLL!    DD s --c|j||_t|jS)z Returns list of installed interpreter versions by scanning alt_node_dir and cache result. Cache also can be pre-filled at init time for testing/debugging purposes )_versions_info_scan_interpreter_versionsr%rGr@s rinstalled_versionsz!BasePkgManager.installed_versionsvs>   &"&"A"A"C"CD D',,..///rc|j||_ |j|dS#t$r|cYSwxYw)a Should return full interpreter version for a particular major version or just fallback to given version if info is not available for any reason. This information is taken from the hash map populated during installed_packages scan. :param maj: Major interpreter version :return: Full interpreter version or Major if info is not available N full_version)rYrZKeyError)r9majs rget_full_versionzBasePkgManager.get_full_versions]   &"&"A"A"C"CD  &s+N; ;   JJJ s5 AAcLtj|jdS)Nz yum.pid.lockr+r=r>r?r@s r_pid_lock_filezBasePkgManager._pid_lock_filesw||D,n===rcLtj|jdS)Nzyum_cache.pid.lockrbr@s r_cache_lock_filezBasePkgManager._cache_lock_filesw||D,.BCCCrc tj|js|t j|t||ttdt|j ddS)z :param pid: pid of Yum process :param version: interpreter version or None for "cache update" case :param status: what yum is currently doing(few predefined statuses) :return: None )pidversionstatusrrCN) r+r=existsr?_create_config_dirsjsondumpstrfloatrr)rc)r9rgrhris r_write_yum_statusz BasePkgManager._write_yum_statussw~~d.// '  $ $ & & & 7||$&&MM   #S ) )  + + + + +rcv|}|"d|d|dSdS)Nz>{} of version '{}' is in progress. Please, wait till it's donerirh)_read_yum_statusr'r9 ongoing_yums r_check_yum_in_progressz%BasePkgManager._check_yum_in_progresssE++--  "1 H-{9/EFF G # "rc|jt tjt |j}n+#t $r||jYdSwxYwtj| ds||jdS tj |dtj \}}n#t$r|cYSwxYw|dkr|S||jdS)a Result "None" - means installing/removing of our packages is not currently in progress. However, it doesn't mean that any other yum instance is not running at the same time, but we ok with this because our yum process will start processing automatically once standard /var/run/yum.pid lock is removed by other process :return: None or dict Nrgr)rcNotImplementedErrorrlloadr) ExceptionrWpsutil pid_existsgetr+waitpidWNOHANGrO)r9datarg_s rrrzBasePkgManager._read_yum_statuss"   &%'' ' 9T$"56677DD       3 4 4 444   %11     3 4 4 44 ZU RZ88FC   KKK  !88K D/000ts!&>$A&%A&-(C C%$C%ct)a Build the yum install argv for a given interpreter version. Returns a list[str] suitable for subprocess.Popen(shell=False). The historical name is kept for caller compatibility; the return type changed from str to list[str] as part of CLOS-4372 hardening. :param version: version of interpreter for installing :rtype: list[str] rwr9rhs r format_cmd_string_for_installingz/BasePkgManager.format_cmd_string_for_installings"###rct)z Build the yum remove argv for a given interpreter version. Returns a list[str] suitable for subprocess.Popen(shell=False). :param version: version of interpreter for removing :rtype: list[str] rrs rformat_cmd_string_for_removingz-BasePkgManager.format_cmd_string_for_removings"###rcx||}|r|S||jvrd|S|}|dS||vrd|S||}|||j}||j|tdS)Return None or Error stringz!Version "{}" is already installedNz^Updating available versions cache is currently in progress. Please, try again in a few minuteszGVersion "{}" is not available. Please, make sure you typed it correctly) _verify_actionr[r'checkout_availablerr5 _log_filerprgr )r9rherr availabler2ps rinstall_versionzBasePkgManager.install_versions!!'**  J d- - -6==gFF F++--  FF ) # #??Evg P44W==   dn 5 5 qug/@AAAAArcr||}|r|S||jvrd|S||rdS||rdS||}|||j}||j |tdS)rzVersion "{}" is not installedzeThis version is currently in use by another operation. Please, wait until it's complete and try againzPIt's not possible to uninstall version which is currently in use by applicationsN) rr[r'is_interpreter_locked_is_version_in_userr5rrprgr )r9rhrr2rs rremove_versionzBasePkgManager.remove_versions!!'**  J $1 1 1299'BB B  % %g . . DDD  " "7 + + 666227;;   dn 5 5 qug?????rc|}|)|dttfvr|d|dddiSdS)zr Should return version and it's status for versions that is currently installing|removing Nrirh)ribase_dir)rrr r rss r in_progresszBasePkgManager.in_progresss_ ++--  "H%*;_)NNNI&)(3 "))  trc#rK||} t|d}n#t$rt|wxYw t j|tjtjzn#t$rYnwxYw dV|dS#|wxYw)NrC) _get_lock_file_pathr)rVr fcntlflockLOCK_EXLOCK_NBcloser9interpreter_version lock_namelfs racquire_interpreter_lockz'BasePkgManager.acquire_interpreter_lock+s,,-@AA  Ci%%BB C C C-.ABB B C  KEMEM9 : : : :    D    EEE HHJJJJJBHHJJJJs'*A,A55 BBB B6ctr7rr@s rrz!BasePkgManager.checkout_availableB!###rctr7rr@s rrZz)BasePkgManager._scan_interpreter_versionsFrrctr7rr@s rrkz"BasePkgManager._create_config_dirsJrrc||}tj|sdSt |d} t j|t jt jzn%#t$rY| dSwxYw | n#| wxYwdS)NFrCT) rr+r=isfiler)rrrrrVrrs rrz$BasePkgManager.is_interpreter_lockedNs,,-@AA w~~i(( 5 )S ! !  KEMEM9 : : : :    HHJJJJJ  ; HHJJJJBHHJJJJus*,A54B05 B?B0BB00Cctr7rrs rrzBasePkgManager._verify_action[rrctr7rrs rrz"BasePkgManager._get_lock_file_path_s!###rctr7rrs rrz!BasePkgManager._is_version_in_usebrr)NN)*rrr__doc__r8r?rYrFr _yum_argv classmethodr5propertyr;rArLrS staticmethodrWr[r`rcrerprurrrrrrrr contextlibcontextmanagerrrrZrkrrrrrrrrr&s #'KNJI 78I  [ &X??X? &&& 1 1 1\00X0">>X>DDXD++++ GGG###J $ $^ $ $ $^ $BBB,@@@* ,$$^$$$^$$$^$   $$^$$$$$$^$$$rr) __future__rrrrr+rrzr- simplejsonrlabcrrrrr r r future.utilsr clcommon.utilsrclcommon.group_info_readerrrQryrobjectrrrrrs&%%%%%&&&&&&  '''''''' ('''''222222666666     i   ~$~$~$~$~$^^GV44~$~$~$~$~$r