MOON
Server: Apache
System: Linux vps.erhabenn.com.br 3.10.0-1160.119.1.el7.tuxcare.els2.x86_64 #1 SMP Mon Jul 15 12:09:18 UTC 2024 x86_64
User: machen (1008)
PHP: 8.2.31
Disabled: NONE
Upload Files
File: //usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/shellutil.pyc
�
d�bc	@scddlZddlZddlZddljjZddlmZeed�s�d�Z	de
fd��YZe	e_	ee_nd�Ze
dd�Ze
e
dd	�Zd
�Zd�Zde
fd
��YZd�Zddejejee
e
e
d�Zdejejee
d�Zd�ZgZej�Zd�Zd�Zd�ZdS(i����N(tustrtcheck_outputcOs�d|krtd��ntjdtj||�}|j�\}}|j�}|r�|jd�}|dkr�|d}ntj||d|��n|S(s/Backport from subprocess module from python 2.7tstdouts3stdout argument not allowed, it will be overridden.targsitoutputN(	t
ValueErrort
subprocesstPopentPIPEtcommunicatetpolltgettNonetCalledProcessError(t	popenargstkwargstprocessRt
unused_errtretcodetcmd((sJ/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/shellutil.pyRs
R
cBseZdd�Zd�ZRS(cCs||_||_||_dS(N(t
returncodeRR(tselfRRR((sJ/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/shellutil.pyt__init__/s		cCsdj|j|j�S(Ns/Command '{0}' returned non-zero exit status {1}(tformatRR(R((sJ/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/shellutil.pyt__str__4sN(t__name__t
__module__RRR(((sJ/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/shellutil.pyR
.scCst|t�S(s9
    Return True if the given command is on the path
    (truntFalse(R((sJ/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/shellutil.pythas_commandCscCs7|dkrg}nt|d|d|�\}}|S(s)
    Note: Deprecating in favour of `azurelinuxagent.common.utils.shellutil.run_command` function.
    Calls run_get_output on 'cmd', returning only the return code.
    If chk_err=True then errors will be reported in the log.
    If chk_err=False then errors will be suppressed from the log.
    tchk_errtexpected_errorsN(Rtrun_get_output(RRRRtout((sJ/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/shellutil.pyRJs	c	Cs?|d	krg}n|r.tjd|�ny�t|dtjdtjdt�}|j�\}}t	|j
�t|�}|jdkr�|r�dj
||j|�}|j|kr�tj|�q�tj|�n|j|fSWnHtk
r4}|r$tjdj
|t|���ndt|�fSXd|fS(
s�
    Wrapper for subprocess.check_output.
    Execute 'cmd'.  Returns return code and STDOUT, trapping expected
    exceptions.
    Reports exceptions to Error if chk_err parameter is True

    For new callers, consider using run_command instead as it separates stdout from stderr,
    returns only stdout on success, logs both outputs and return code on error and raises an exception.
    uCommand: [{0}]Rtstderrtshelliu1Command: [{0}], return code: [{1}], result: [{2}]u0Command [{0}] raised unexpected exception: [{1}]i����N(Rtloggertverboset_popenRRtSTDOUTtTrueR	t_on_command_completedtpidt__encode_command_outputRRtinfoterrort	ExceptionR(	RRtlog_cmdRRRt_tmsgt	exception((sJ/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/shellutil.pyR Ws.
	$
cCsbt|t�r^|rQt|dt�rQdjg|D]}dj|�^q5�Sdj|�S|S(s
    Formats the command taken by run_command/run_pipe.

    Examples:
        > __format_command("sort")
        'sort'
        > __format_command(["sort", "-u"])
        'sort -u'
        > __format_command([["sort"], ["unique", "-n"]])
        'sort | unique -n'
    is | t (t
isinstancetlisttjoin(tcommandR((sJ/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/shellutil.pyt__format_command�s
)
cCs(t|dk	r|nddddd�S(sH
    Encodes the stdout/stderr returned by subprocess.communicate()
    ttencodingsutf-8terrorstbackslashreplaceN(RR(R((sJ/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/shellutil.pyR+�stCommandErrorcBs&eZdZed��Zd�ZRS(sT
    Exception raised by run_command/run_pipe when the command returns an error
    cCsJt|t�r+t|�dkr+|dn|}dj|||j��S(Nis'{0}' failed: {1} ({2})(R4R5tlenRtrstrip(R7treturn_codeR"tcommand_name((sJ/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/shellutil.pyt_get_message�s1cCsMtt|�jtj|||��||_||_||_||_dS(N(	tsuperR.RR=RBR7RRR"(RR7R@RR"((sJ/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/shellutil.pyR�s
%			(RRt__doc__tstaticmethodRBR(((sJ/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/shellutil.pyR=�sc	Cs�y�|�\}}}|r6t|�}t|�}n|dkr�|rjtjdt|�|||�ntdt|�d|d|d|��n|SWnQtk
r��n>tk
r�}|r�tjdt|�t|��n�nXdS(	s�
    Executes the given command_action and returns its stdout. The command_action is a function that executes a command/pipe
    and returns its exit code, stdout, and stderr.

    If there are any errors executing the command it raises a RunCommandException; if 'log_error'
    is True, it also logs details about the error.

    If encode_output is True the stdout is returned as a string, otherwise it is returned as a bytes object.
    is?Command: [{0}], return code: [{1}], stdout: [{2}] stderr: [{3}]R7R@RR"u0Command [{0}] raised unexpected exception: [{1}]N(R+R$R-R8R=R.R(tcommand_actionR7t	log_errort
encode_outputR@RR"R2((sJ/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/shellutil.pyt
__run_command�s*
	
*
"c	

sg�dk	r'�dk	r'td��n�������fd�}	td|	d�d|d|�S(sV
        Executes the given command and returns its stdout.

        If there are any errors executing the command it raises a RunCommandException; if 'log_error'
        is True, it also logs details about the error.

        If encode_output is True the stdout is returned as a string, otherwise it is returned as a bytes object.

        If track_process is False the command is not added to list of running commands

        This function is a thin wrapper around Popen/communicate in the subprocess module:
           * The 'input' parameter corresponds to the same parameter in communicate
           * The 'stdin' parameter corresponds to the same parameters in Popen
           * Only one of 'input' and 'stdin' can be specified
           * The 'stdout' and 'stderr' parameters correspond to the same parameters in Popen, except that they
             default to subprocess.PIPE instead of None
           * If the output of the command is redirected using the 'stdout' or 'stderr' parameters (i.e. if the
             value for these parameters is anything other than the default (subprocess.PIPE)), then the corresponding
             values returned by this function or the CommandError exception will be empty strings.

        Note: This is the preferred method to execute shell commands over `azurelinuxagent.common.utils.shellutil.run` function.
    s4The input and stdin arguments are mutually exclusivecs�d}}�dk	rItj}�r@t�t�r@�j�n�}n�dk	rd�}d}n�r�t�d|d�d�dt�}n'tj�d|d�d�dt�}|j	d|�\}}�r�t
|j�n|j||fS(NtstdinRR"R#tinput(
RRRR4tstrtencodeR&RRR	R)R*R(tpopen_stdintcommunicate_inputRtcommand_stdouttcommand_stderr(R7tencode_inputRKR"RJRt
track_process(sJ/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/shellutil.pyRF�s
	*	''RFR7RGRHN(RRRI(
R7RKRJRR"RGRRRHRSRF((R7RRRKR"RJRRSsJ/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/shellutil.pytrun_command�s!c	sXt��dkr!td��n����fd�}td|d�d|d|�S(sN
        Executes the given commands as a pipe and returns its stdout as a string.

        The pipe is a list of commands, which in turn are a list of strings, e.g.

            [["sort"], ["uniq", "-n"]] represents 'sort | unique -n'

        If there are any errors executing the command it raises a RunCommandException; if 'log_error'
        is True, it also logs details about the error.

        If encode_output is True the stdout is returned as a string, otherwise it is returned as a bytes object.

        This function is a thin wrapper around Popen/communicate in the subprocess module:
           * The 'stdin' parameter is used as input for the first command in the pipe
           * The 'stdout', and 'stderr' can be used to redirect the output of the pipe
           * If the output of the pipe is redirected using the 'stdout' or 'stderr' parameters (i.e. if the
             value for these parameters is anything other than the default (subprocess.PIPE)), then the corresponding
             values returned by this function or the CommandError exception will be empty strings.
    is,The pipe must consist of at least 2 commandsc	s�d}zw�}�tjkr3tj�}|}n�}g}d}x]|t��dkr�|jt�|d|dtjd|��||j}|d7}qHW|jt�|d|d�d|��d}x5|t|�dkr||jj	�|d7}q�W||j
�\}}x|D]}t|j�q)W|dk	rh|j
d�|j�}n||j||fSWd|dk	r�|j	�nXdS(NiiRJRR"(RRRttempfilet
TemporaryFileR>tappendR&RtcloseR	R)R*tseektreadR(tstderr_fileRNtpopen_stderrt	processestitpipe_stdouttpipe_stderrtproc(tpipeR"RJR(sJ/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/shellutil.pyRFs6	,
)

RFR7RGRH(R>RRI(RbRJRR"RGRHRF((RbR"RJRsJ/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/shellutil.pytrun_pipes)cCs>t|ttf�s!|f}ndjtd�|D���S(s�
    Quote a list or tuple of strings for Unix Shell as words, using the
    byte-literal single quote.

    The resulting string is safe for use with ``shell=True`` in ``subprocess``,
    and in ``os.system``. ``assert shlex.split(ShellQuote(wordList)) == wordList``.

    See POSIX.1:2013 Vol 3, Chap 2, Sec 2.2.2:
    http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_02_02
    R3css*|] }dj|jdd��VqdS(s'{0}'t's'\''N(Rtreplace(t.0ts((sJ/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/shellutil.pys	<genexpr>Ss(R4ttupleR5R6(t	word_list((sJ/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/shellutil.pytquoteEscOs7t�+tj||�}tj|j�|SWdQXdS(N(t_running_commands_lockRRt_running_commandsRWR*(RRR((sJ/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/shellutil.pyR&^scCst�tj|�WdQXdS(N(RkRltremove(R*((sJ/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/shellutil.pyR)escCst�
tSWdQXdS(sr
    Returns the commands started by run/run_get_output/run_command/run_pipe that are currently running.

    NOTE: This function is not synchronized with process completion, so the returned array may include processes that have
    already completed. Also, keep in mind that by the time this function returns additional processes may have
    started or completed.
    N(RkRl(((sJ/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/shellutil.pytget_running_commandsjs( RRUt	threadingtazurelinuxagent.common.loggertcommonR$tazurelinuxagent.common.futureRthasattrRR.R
RR(RRR R8R+R=RIRRRTRcRjRltRLockRkR&R)Rn(((sJ/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/shellutil.pyt<module>s0				
)			&'1C