File: //lib/python2.7/site-packages/azurelinuxagent/common/utils/shellutil.pyc
�
d�bc @ sc d d l Z d d l Z d d l Z d d l j j Z d d l m Z e e d � s� d � Z d e
f d � � YZ e e _ e e _ n d � Z e
d d � Z e
e
d d � Z d
� Z d � Z d e
f d
� � YZ d � Z d d e j e j e e
e
e
d � Z d e j e j e e
d � Z d � Z g Z e j � Z d � Z d � Z d � Z d S( i����N( t ustrt check_outputc O s� d | k r t d � � n t j d t j | | � } | j � \ } } | j � } | r� | j d � } | d k r� | d } n t j | | d | �� n | S( s/ Backport from subprocess module from python 2.7t stdouts3 stdout argument not allowed, it will be overridden.t argsi t outputN( t
ValueErrort
subprocesst Popent PIPEt communicatet pollt gett Nonet CalledProcessError( t popenargst kwargst processR t
unused_errt retcodet cmd( ( sJ /usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/shellutil.pyR s
R
c B s e Z d d � Z d � Z RS( c C s | | _ | | _ | | _ d S( N( t
returncodeR R ( t selfR R R ( ( sJ /usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/shellutil.pyt __init__/ s c C s d j | j | j � S( Ns/ Command '{0}' returned non-zero exit status {1}( t formatR R ( R ( ( sJ /usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/shellutil.pyt __str__4 s N( t __name__t
__module__R R R ( ( ( sJ /usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/shellutil.pyR
. s c C s t | t � S( s9
Return True if the given command is on the path
( t runt False( R ( ( sJ /usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/shellutil.pyt has_commandC s c C s7 | d k r g } n t | 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.
t chk_errt expected_errorsN( R t run_get_output( R R R R t out( ( sJ /usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/shellutil.pyR J s c C s? | d k r g } n | r. t j d | � n y� t | d t j d t j d t �} | j � \ } } t | j
� t | � } | j d k r� | r� d j
| | j | � } | j | k r� t j | � q� t j | � n | j | f SWnH t k
r4} | r$t j d j
| t | � � � n d t | � f SXd | f S(
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.
u Command: [{0}]R t stderrt shelli u1 Command: [{0}], return code: [{1}], result: [{2}]u0 Command [{0}] raised unexpected exception: [{1}]i����N( R t loggert verboset _popenR R t STDOUTt TrueR t _on_command_completedt pidt __encode_command_outputR R t infot errort ExceptionR ( R R t log_cmdR R R t _t msgt exception( ( sJ /usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/shellutil.pyR W s.
$
c C sb t | t � r^ | rQ t | d t � rQ d j g | D] } d j | � ^ q5 � Sd j | � 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'
i s | t ( t
isinstancet listt join( t commandR ( ( sJ /usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/shellutil.pyt __format_command� s
)
c C s( t | d k r | n d d d d d �S( sH
Encodes the stdout/stderr returned by subprocess.communicate()
t t encodings utf-8t errorst backslashreplaceN( R R ( R ( ( sJ /usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/shellutil.pyR+ � s t CommandErrorc B s&