%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python2.7/site-packages/salt/utils/
Upload File :
Create Path :
Current File : //usr/lib/python2.7/site-packages/salt/utils/mac_utils.pyo

�
���^c@@sdZddlmZmZddlZddlZddlZddlZddlZddl	Z
yddlZWnek
r�nXddl
ZddlZddlZddlZddlZddlZddlZddlZddlmZmZmZddlmZddlmZejjj �dZ!ej"e#�Z$dZ%iej&j'j(d	6ej&j'j)d
6Z*ej+r�de,fd��YZ-e-e_-nd
�Z.d�Z/d�Z0d�Z1d�Z2d�Z3d�Z4e5dd�Z6d�Z7e5d�Z8e5d�Z9e5d�Z:dS(uD
Helper functions for use by mac modules
.. versionadded:: 2016.3.0
i(tabsolute_importtunicode_literalsN(tCommandExecutionErrortSaltInvocationErrortTimedProcTimeoutError(trange(tsixushellu	mac_utilsucmd.run_allucmd.runtInvalidFileExceptioncB@seZRS((t__name__t
__module__(((s8/usr/lib/python2.7/site-packages/salt/utils/mac_utils.pyR2scC@s tjjj�stdfStS(u
    Load only on Mac OS
    uOThe mac_utils utility could not be loaded: utility only works on MacOS systems.(tsalttutilstplatformt	is_darwintFalset__virtualname__(((s8/usr/lib/python2.7/site-packages/salt/utils/mac_utils.pyt__virtual__7s
c
C@s7t|t�s-tjjj|dt�}nxJt|�D]<\}}t||tj	�s:tj
||�||<q:q:Wdj|�}tj
j�}i	dd6td6|d6dd6tjd6tjd6td	6dd
6td6}ytjjj||�}Wn4ttfk
r5}tdj|||���nXi}y|j�WnKtk
r�}tj
|�|d<d
|d<d|d<|jj|d<|SX|j|j}}	|dk	r�tjj j!|�j"�}n|	dk	r�tjj j!|	�j"�}	n|jj|d<|jj#|d<||d<|	|d<|S(u,

    Args:
        cmd:

    Returns:

    tposixu ucwdushelluenvustdinustdoutustderruwith_communicateutimeoutubgu?Unable to run command '{0}' with the context '{1}', reason: {2}uiuretcodeupidN($t
isinstancetlistR
Rtargstshlex_splitRt	enumerateRtstring_typest	text_typetjointostenvirontcopytNonet
DEFAULT_SHELLt
subprocesstPIPEtTruettimed_subprocesst	TimedProctOSErrortIOErrorRtformattrunRtprocesstpidtstdouttstderrtstringutilstto_strtrstript
returncode(
tcmdtidxtitemtrun_envtkwargstproctexctrettoutterr((s8/usr/lib/python2.7/site-packages/salt/utils/mac_utils.pyt_run_allBsR	







cC@s$|dj�}d|kr tStS(u�
    helper class to check the launchctl stderr.
    launchctl does not always return bad exit code
    if there is a failure
    ustderruservice is disabled(tlowerR!R(R7R9((s8/usr/lib/python2.7/site-packages/salt/utils/mac_utils.pyt_check_launchctl_stderr�scC@s�t|�}tjd||�|ddksEd|dj�kr�dj|�}|dj|d�7}|dj|d�7}|d	j|d
�7}t|��ntS(u�
    Executes the passed command. Returns True if successful

    :param str cmd: The command to run

    :return: True if successful, otherwise False
    :rtype: bool

    :raises: Error if command fails or is not supported
    uExecute return success %s: %ruretcodeiu
not supportedustdoutuCommand Failed: {0}
uReturn Code: {0}
uOutput: {0}
uError: {0}
ustderr(R:tlogtdebugR;R&RR!(R0R7tmsg((s8/usr/lib/python2.7/site-packages/salt/utils/mac_utils.pytexecute_return_success�s&cC@s�t|�}|ddks2d|dj�kr�dj|�}|dj|d�7}|dj|d�7}|dj|d	�7}t|��n|dS(
u
    Executes the passed command. Returns the standard out if successful

    :param str cmd: The command to run

    :return: The standard out of the command if successful, otherwise returns
    an error
    :rtype: str

    :raises: Error if command fails or is not supported
    uretcodeiu
not supportedustdoutuCommand Failed: {0}
uReturn Code: {0}
uOutput: {0}
uError: {0}
ustderr(R:R;R&R(R0R7R?((s8/usr/lib/python2.7/site-packages/salt/utils/mac_utils.pytexecute_return_result�s&cC@sBd|kr|jd�dSd|kr:|jd�dS|SdS(u
    Returns the data portion of a string that is colon separated.

    :param str data: The string that contains the data to be parsed. Usually the
    standard out from a command

    For example:
    ``Time Zone: America/Denver``
    will return:
    ``America/Denver``
    u: iu:
N(tsplit(tdata((s8/usr/lib/python2.7/site-packages/salt/utils/mac_utils.pytparse_return�s

cC@spt|tj�r\|j�dkrBdj|�}t|��n|j�dkrXdSdSt|�rldSdS(u�
    Helper function to validate the enabled parameter. Boolean values are
    converted to "on" and "off". String values are checked to make sure they are
    either "on" or "off"/"yes" or "no". Integer ``0`` will return "off". All
    other integers will return "on"

    :param enabled: Enabled can be boolean True or False, Integers, or string
    values "on" and "off"/"yes" and "no".
    :type: str, int, bool

    :return: "on" or "off" or errors
    :rtype: str
    uonuoffuyesunoul
Mac Power: Invalid String Value for Enabled.
String values must be 'on' or 'off'/'yes' or 'no'.
Passed: {0}(uonuoffuyesuno(uonuyes(RRRR;R&Rtbool(tenabledR?((s8/usr/lib/python2.7/site-packages/salt/utils/mac_utils.pytvalidate_enabled�s	icC@soxht|�D]Z}|r(t|��n|�}tjd||||�||krZtStjd�q
WtS(u�
    Wait up to ``wait`` seconds for a system parameter to be changed before
    deciding it hasn't changed.

    :param str value: The value indicating a successful change

    :param function check_fun: The function whose return is compared with
        ``value``

    :param bool normalize_ret: Whether to normalize the return from
        ``check_fun`` with ``validate_enabled``

    :param int wait: The maximum amount of seconds to wait for a system
        parameter to change
    u0Confirm update try: %d func:%r state:%s value:%si(RRGR=R>R!ttimetsleepR(tvaluet	check_funt
normalize_rettwaittitstate((s8/usr/lib/python2.7/site-packages/salt/utils/mac_utils.pytconfirm_updated�scO@s�|jdt�}d|g}|j|�t|d<tjjj|�}td||�}t|�}|dsy|r�dj	|�}|dj	|d�7}|d	j	|d
�7}|dj	|d�7}t
|��n|r�|dStSdS(
u�
    Run a launchctl command and raise an error if it fails

    Args: additional args are passed to launchctl
        sub_cmd (str): Sub command supplied to launchctl

    Kwargs: passed to ``cmd.run_all``
        return_stdout (bool): A keyword argument. If true return the stdout of
            the launchctl command

    Returns:
        bool: ``True`` if successful
        str: The stdout of the launchctl command if requested

    Raises:
        CommandExecutionError: If command fails

    CLI Example:

    .. code-block:: bash

        import salt.utils.mac_service
        salt.utils.mac_service.launchctl('debug', 'org.cups.cupsd')
    u
return_stdoutu	launchctlupython_shellucmd.run_alluretcodeuFailed to {0} service:
ustdout: {0}
ustdoutustderr: {0}
ustderruretcode: {0}N(tpopRtextendR
RRtclean_kwargst__salt__R<R&RR!(tsub_cmdRR4t
return_stdoutR0R7terrorR8((s8/usr/lib/python2.7/site-packages/salt/utils/mac_utils.pyt	launchctls

c
C@s
y4tdr3|r3tjd�ttd<tdSWntk
rGnXddddg}yOxHtjd�D]7}d	j|�}tjj	|�rm|j
|�qmqmWWntk
r�nXt�}x%|D]}xt
jjj|�D]�\}}}x�|D]�}	|	jd
�sq�ntjj||	�}
tjj|
�}tjd|�tjj|�siq�nyOtjr�tj|�}n0t
jjj|d��}
tj|
�}Wd
QXWn�tjk
r�d}tj||�q�n�tj j!j"k
r�tj#r"d}tj||�q�ndj|�}y#t$d|�}tj%|�}Wq�tj j!j"k
r�d}tj||�q�q�XnXy-i|	d6|d6|d6||dj&�<Wq�tk
r�tjd|�q�q�Xq�Wq�Wq�W|td<t'td<tdS(u�
    This is a helper function for getting the available macOS services.

    The strategy is to look through the known system locations for
    launchd plist files, parse them, and use their information for
    populating the list of services. Services can run without a plist
    file present, but normally services which have an automated startup
    will have a plist file, so this is a minor compromise.
    uavailable_servicesu%Found context for available services.uusing_cached_servicesu/Library/LaunchAgentsu/Library/LaunchDaemonsu/System/Library/LaunchAgentsu/System/Library/LaunchDaemonsu/Users/u/Users/{}/Library/LaunchAgentsu.plistuGathering service info for %surbNu@Unable to parse "%s" as it is invalid XML: InvalidFileException.uHUnable to parse "%s" as it is invalid XML: xml.parsers.expat.ExpatError.u+/usr/bin/plutil -convert xml1 -o - -- "{0}"ucmd.runu	file_nameu	file_pathuplistuLabelu2Service %s does not contain a Label key. Skipping.((t__context__R=R>R!tKeyErrorRtlistdirR&tpathtisdirtappendR$tdictR
Rtos_walktendswithRtrealpathttracetexistsRtPY2tplistlibt	readPlisttfilestfopentloadRtloggingtwarningtxmltparserstexpatt
ExpatErrortPY3RTtreadPlistFromStringR;R(trefresht
launchd_pathstusert
agent_patht_available_servicest
launch_dirtroottdirsRht	file_namet	file_patht	true_pathtplistthandleR?R0t	plist_xml((s8/usr/lib/python2.7/site-packages/salt/utils/mac_utils.pyRw=s�



	
	
%
			
	

cC@stjd�t|�S(ut
    Return a dictionary of all available services on the system

    :param bool refresh: If you wish to refresh the available services
    as this data is cached on the first run.

    Returns:
        dict: All available services

    CLI Example:

    .. code-block:: bash

        import salt.utils.mac_service
        salt.utils.mac_service.available_services()
    uLoading available services(R=R>Rw(Rs((s8/usr/lib/python2.7/site-packages/salt/utils/mac_utils.pytavailable_services�s
cC@sXytjd�d}Wn#ttfk
r<td��nX|rTtj|�dS|S(u�
    Gets the UID or Username of the current console user.

    :return: The uid or username of the console user.

    :param bool username: Whether to return the username of the console
    user instead of the UID. Defaults to False

    :rtype: Interger of the UID, or a string of the username.

    Raises:
        CommandExecutionError: If we fail to get the UID.

    CLI Example:

    .. code-block:: bash

        import salt.utils.mac_service
        salt.utils.mac_service.console_user()
    u/dev/consoleiu)Failed to get a UID for the console user.i(RtstatR$t
IndexErrorRtpwdtgetpwuid(tusernametuid((s8/usr/lib/python2.7/site-packages/salt/utils/mac_utils.pytconsole_user�s(;t__doc__t
__future__RRRkRRRfRHtxml.parsers.expatRmR�tImportErrortsalt.modules.cmdmodR
tsalt.utils.argstsalt.utils.filestsalt.utils.pathtsalt.utils.platformtsalt.utils.stringutilstsalt.utils.timed_subprocesstsalt.grains.extratsalt.exceptionsRRRtsalt.ext.six.movesRtsalt.extRtgrainstextratshellRt	getLoggerRR=Rtmodulestcmdmodt_run_all_quiett
_run_quietRTRet	ExceptionRRR:R<R@RARDRGRRPRXRwR�R�(((s8/usr/lib/python2.7/site-packages/salt/utils/mac_utils.pyt<module>sV
			B						1l

Zerion Mini Shell 1.0