MOON
Server: Apache
System: Linux server2.shieldcogroup.com 3.10.0-1160.119.1.el7.tuxcare.els12.x86_64 #1 SMP Fri Nov 8 05:49:38 UTC 2024 x86_64
User: jacom (1029)
PHP: 8.1.34
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //etc/leapp/repos.d/system_upgrade/common/libraries/utils.pyo
�
��ic@s"ddlZddlZddlZddlZddlmZddlmZddlm	Z	m
Z
mZmZm
Z
ddlmZded�Zded�Zed	d
dd�dd
��Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zdd�Zdd�ZdS(i����N(tStopActorExecutionError(tmounting(tapitCalledProcessErrortconfigtruntSTDOUT(t
deprecatedcCs�tjr$tjjjd|�}ntjjj�}|rwtjrwt|tj�rg|j|�q�|j|�nN|r�ddl	m
}t|tj�r�|j||��q�|j|�n|S(s
    Applies a workaround to parse a config file using py3 AND py2

    ConfigParser has a new def to read strings/files in Py3, making
    the old ones (Py2) obsoletes, these function was created to use the
    ConfigParser on Py2 and Py3

    :type cfg: str
    :type strict: bool
    tstricti����(tStringIO(tsixtPY3tmovestconfigparsertConfigParsert
isinstancetstring_typestread_stringt	read_filet	cStringIOR	treadfp(tcfgRtparserR	((sQ/usr/share/leapp-repository/repositories/system_upgrade/common/libraries/utils.pytparse_config
s	i�cCs tjd|d|d|�dS(Ntpathtmodet	exists_ok(Rt	_makedirs(RRR((sQ/usr/share/leapp-repository/repositories/system_upgrade/common/libraries/utils.pytmakedirs.stsinces
2022-02-03tmessages�The "apply_yum_workaround" function has been deprecated, use "DNFWorkaround" message as used in the successive "RegisterYumAdjustment" actor.cCs�tjd�}|s0tdddt���ndd|g}y)|pWtjdd�}|j|�Wnatk
r�}tdd	jt	|����n1t
k
r�}tdd
jt	|����nXdS(sY
    Applies a workaround on the system to allow the upgrade to succeed for yum/dnf.
    thandleyumconfigRs(Failed to find mandatory script to applytdetailss	/bin/bashs-ctbase_dirt/s=Failed to execute script to apply yum adjustment. Message: {}s+Failed to apply yum adjustment. Message: {}N(Rt
get_tool_pathRtreinstall_leapp_repository_hintRtNotIsolatedActionstcalltOSErrortformattstrR(tcontexttyum_script_pathtcmdte((sQ/usr/share/leapp-repository/repositories/system_upgrade/common/libraries/utils.pytapply_yum_workaround2s	cCs�|\}}|tkr)tj�r)dS|tkr>tjntj}tjdkrrtj|j	�|g�n
|j
|�dS(s[
    Custom log handler to always show stdout to console and stderr only in DEBUG mode
    Nii(ii(RRtis_debugtsyststdouttstderrtversion_infotostwritevtfilenotwrite(tfd_infotbuft_unusedtfd_typettarget((sQ/usr/share/leapp-repository/repositories/system_upgrade/common/libraries/utils.pytlogging_handlerPscCsidd6S(s�
    Convenience function for creating a detail for StopActorExecutionError with a hint to reinstall the
    leapp-repository package
    s0Try to reinstall the `leapp-repository` package.thint((((sQ/usr/share/leapp-repository/repositories/system_upgrade/common/libraries/utils.pyR$^scCsttjdkr?tj�jd|j||dj|d�n1tj�jd|j|t|�jt|��dS(sQ
    Helper function for shutil.rmtree to only report errors but don't fail.
    iisTWhile trying to remove directories: %s failed at %s with an exception %s message: %siiN(ii(R0R3Rtcurrent_loggertwarningt__name__ttypeR)(tfuncRtexc_info((sQ/usr/share/leapp-repository/repositories/system_upgrade/common/libraries/utils.pyt%report_and_ignore_shutil_rmtree_errorhs!cCs�yt|�Wnutk
r�}|rXtdt|�didj|d�d6��ntddjdj|�t|����nXdS(	sH
    Perform run with already handled OSError for some convenience.
    RR s2Please ensure that {} is installed and executable.iR>s%Failed to execute command {} with: {}tN(RR'RR)R(tjoin(R,R-((sQ/usr/share/leapp-repository/repositories/system_upgrade/common/libraries/utils.pytcall_with_oserror_handledyscCs_yt|�WnJtk
rZ}tddjdj|�t|��di||6��nXdS(s�
    Perform `run` which handles OSError through call_with_oserror_handled and transforms CalledProcessError to a
    StopActorExecutionError with a hint given by the caller.
    Rs)Failed to execute command `{}`. Error: {}t R N(RHRRR(RGR)(R,R>R-((sQ/usr/share/leapp-repository/repositories/system_upgrade/common/libraries/utils.pytcall_with_failure_hint�s!cs�fd�}|S(s�
    Decorator to handle any exception going through and running cleanup tasks through the given cleanup_function
    parameter.
    cs%tj����fd��}|S(Ncs}y�||�SWnetk
rxtj�jd�y�||�Wn*tk
rqtj�jddt�nX�nXdS(Ns;Clean guard caught an exception - Calling cleanup function.s1Caught and swallowed an exception during cleanup.RD(t	ExceptionRR?tdebugR@tTrue(targstkwargs(tcleanup_functiontf(sQ/usr/share/leapp-repository/repositories/system_upgrade/common/libraries/utils.pytwrapper�s

(t	functoolstwraps(RQRR(RP(RQsQ/usr/share/leapp-repository/repositories/system_upgrade/common/libraries/utils.pyt
clean_wrapper�s!((RPRU((RPsQ/usr/share/leapp-repository/repositories/system_upgrade/common/libraries/utils.pytclean_guard�scCs&t|d��}|j�SWdQXdS(sQ
    Reads the file specified by path in text mode and returns the contents.
    trN(topentread(RRQ((sQ/usr/share/leapp-repository/repositories/system_upgrade/common/libraries/utils.pyR�scCs�d�}|s|}ntj|�}t|d�}|sdd}|jd|j�}||�nt|d�}|r�d}|jd|j�}||�n|S(sa
    Consume and return exactly one message of the given type, error if there are none or more than one available.

    Calls ``error_callback`` if there are none or more than one messages available of the requested type
    with a string describing the error condition.

    Note: this function is private, experimental and will likely be subject to change.

    :param model_class: Message type to consume
    :param Callable[[str], None] error_callback: Callback to call when error condition arises, e.g., raising the
                                                 StopActorExecutionError (default).
    cSst|��dS(N(R(tmsg((sQ/usr/share/leapp-repository/repositories/system_upgrade/common/libraries/utils.pytdefault_callback�ssOExactly one {cls_name} message of type is required, however, none was received.tcls_namesZExactly one {cls_name} message is required, however, more than one messages were received.N(RtconsumetnexttNoneR(RA(tmodel_classterror_callbackR[tmodel_instancestmodel_instanceRZt
next_instance((sQ/usr/share/leapp-repository/repositories/system_upgrade/common/libraries/utils.pyt$_require_exactly_one_message_of_type�s
		

cCshd�}|s|}ntj|�}t|d�}|sdd}|jd|j�}||�n|S(s<
    Consume and return one message of the given type, error if there are no messages available.

    Calls ``error_callback`` if there are no messages available of the requested type
    with a string describing the error condition.

    Note: this function is private, experimental and will likely be subject to change.

    :param model_class: Message type to consume
    :param Callable[[str], None] error_callback: Callback to call when error condition arises, e.g., raising the
                                                 StopActorExecutionError (default).
    cSst|��dS(N(R(RZ((sQ/usr/share/leapp-repository/repositories/system_upgrade/common/libraries/utils.pyR[�ssOExactly one {cls_name} message of type is required, however, none was received.R\N(RR]R^R_R(RA(R`RaR[RbRcRZ((sQ/usr/share/leapp-repository/repositories/system_upgrade/common/libraries/utils.pyt_require_some_message_of_type�s
		
(RSR4R0R
tleapp.exceptionsRtleapp.libraries.commonRtleapp.libraries.stdlibRRRRRtleapp.utils.deprecationRR_RMRRR.R=R$RERHRJRVRReRf(((sQ/usr/share/leapp-repository/repositories/system_upgrade/common/libraries/utils.pyt<module>s*(!		
					#