%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python2.7/site-packages/salt/modules/
Upload File :
Create Path :
Current File : //usr/lib/python2.7/site-packages/salt/modules/mac_service.pyc

�
���^c@@s�dZddlmZmZmZddlZddlZddlZddlZ	ddl
Z	ddlZ	ddlZ	ddl
mZddlmZddlmZdZidd	6Zeje�Zd
�Zd�Zd�Zd
�Zed�Zd�Zd�Z d�Z!ddd�Z#dd�Z$dd�Z%dd�Z&dd�Z'dd�Z(ddd�Z)d�Z*d�Z+dd�Z,ddd�Z-dd�Z.dd�Z/dS( u]
The service module for macOS

.. versionadded:: 2016.3.0

This module has support for services in the following locations.

.. code-block:: bash

    /System/Library/LaunchDaemons/
    /System/Library/LaunchAgents/
    /Library/LaunchDaemons/
    /Library/LaunchAgents/

    # As of version "2019.2.0" support for user-specific services were added.
    /Users/foo/Library/LaunchAgents/

.. note::
    As of the 2019.2.0 release, if a service is located in a ``LaunchAgent``
    path and a ``runas`` user is NOT specified, the current console user will
    be used to properly interact with the service.

i(tabsolute_importtunicode_literalstprint_functionN(tCommandExecutionError(tLooseVersion(tsixuserviceulistulist_cC@s�tjjj�stdfStjjjd�s;tdfStjjjd�sZtdfSttd�td�kr�tdfSt	S(	u'
    Only for macOS with launchctl
    uGFailed to load the mac_service module:
Only available on macOS systems.u	launchctluMFailed to load the mac_service module:
Required binary not found: "launchctl"uplutiluJFailed to load the mac_service module:
Required binary not found: "plutil"u	osreleaseu10.11uDFailed to load the mac_service module:
Requires macOS 10.11 or newer(
tsalttutilstplatformt	is_darwintFalsetpathtwhicht
_LooseVersiont
__grains__t__virtualname__(((s</usr/lib/python2.7/site-packages/salt/modules/mac_service.pyt__virtual__5s



cC@s�||kr||Sxctj|�D]R}|dj�|krD|Stjj|d�\}}|j�|kr$|Sq$Wt�S(u+
    Checks to see if the given service is in the given services.

    :param str name: Service label, file name, or full path

    :param dict services: The currently available services.

    :return: The service information for the service, otherwise
    an empty dictionary

    :rtype: dict
    u	file_pathu	file_name(Rt
itervaluestlowertosRtsplitexttdict(tnametservicestservicetbasenametext((s</usr/lib/python2.7/site-packages/salt/modules/mac_service.pyt_name_in_servicesLs
cC@s�td�}|j�}t||�}|r2|Sy&tdsWtdj|���nWntk
rknXtddt�}t||�}|s�tdj|���n|S(u�
    Get information about a service.  If the service is not found, raise an
    error

    :param str name: Service label, file name, or full path

    :return: The service information for the service, otherwise an Error
    :rtype: dict
    umac_utils.available_servicesuusing_cached_servicesuService not found: {0}trefresh(t	__utils__RRt__context__RtformattKeyErrortTrue(RRR((s</usr/lib/python2.7/site-packages/salt/modules/mac_service.pyt_get_serviceis



cC@s�t|�}y|dd}Wntk
r2tSXt|t�r�xqtj|jdi��D]Q\}}|tkr�t	j
j|�r�tS|tkr^t	j
j|�r^tSq^Wn|tkr�tStS(uQ
    Check if the service should always be running based on the KeepAlive Key
    in the service plist.

    :param str name: Service label, file name, or full path

    :return: True if the KeepAlive key is set to True, False if set to False or
        not set in the plist at all.

    :rtype: bool

    .. versionadded:: 2019.2.0
    uplistu	KeepAliveu	PathState(tshowR R
t
isinstanceRRt	iteritemstgetR!RRtexists(Rtservice_infot
keep_alivet_filetvalue((s</usr/lib/python2.7/site-packages/salt/modules/mac_service.pyt_always_running_service�s
(cC@szt|�}|d}d}d|krGtd�}dj|�}n|tkrpdj||dd�}n||fS(	u
    Returns the domain/service target and path for a service. This is used to
    determine whether or not a service should be loaded in a user space or
    system space.

    :param str name: Service label, file name, or full path

    :param bool service_target: Whether to return a full
    service target. This is needed for the enable and disable
    subcommands of /bin/launchctl. Defaults to False

    :return: Tuple of the domain/service target and the path to the service.

    :rtype: tuple

    .. versionadded:: 2019.2.0
    u	file_pathusystemuLaunchAgentsumac_utils.console_userugui/{}u{}/{}uplistuLabel(R"RRR!(Rtservice_targetRRt
domain_targettuid((s</usr/lib/python2.7/site-packages/salt/modules/mac_service.pyt_get_domain_target�s

cC@s$t|�d}d|kr tStS(u�
    Checks to see if the provided service is a LaunchAgent

    :param str name: Service label, file name, or full path

    :return: True if a LaunchAgent, False if not.

    :rtype: bool

    .. versionadded:: 2019.2.0
    u	file_pathuLaunchAgents(R"R
R!(RR((s</usr/lib/python2.7/site-packages/salt/modules/mac_service.pyt
_launch_agent�scC@s
t|�S(u�
    Show properties of a launchctl service

    :param str name: Service label, file name, or full path

    :return: The service information if the service is found
    :rtype: dict

    CLI Example:

    .. code-block:: bash

        salt '*' service.show org.cups.cupsd  # service label
        salt '*' service.show org.cups.cupsd.plist  # file name
        salt '*' service.show /System/Library/LaunchDaemons/org.cups.cupsd.plist  # full path
    (R"(R((s</usr/lib/python2.7/site-packages/salt/modules/mac_service.pyR#�scO@std|||�S(u�
    Run a launchctl command and raise an error if it fails

    :param str sub_cmd: Sub command supplied to launchctl

    :param tuple args: Tuple containing additional arguments to pass to
        launchctl

    :param dict kwargs: Dictionary containing arguments to pass to
        ``cmd.run_all``

    :param bool return_stdout: A keyword argument.  If true return the stdout
        of the launchctl command

    :return: ``True`` if successful, raise ``CommandExecutionError`` if not, or
        the stdout of the launchctl command if requested
    :rtype: bool, str

    CLI Example:

    .. code-block:: bash

        salt '*' service.launchctl debug org.cups.cupsd
    umac_utils.launchctl(R(tsub_cmdtargstkwargs((s</usr/lib/python2.7/site-packages/salt/modules/mac_service.pyt	launchctlscC@sx|rbt|�}|dd}|rIt|�rItddt�}ntd|dtd|�Stddtd|�S(u�
    Run launchctl list and return the output

    :param str name: The name of the service to list

    :param str runas: User to run launchctl commands

    :return: If a name is passed returns information about the named service,
        otherwise returns a list of all services and pids
    :rtype: str

    CLI Example:

    .. code-block:: bash

        salt '*' service.list
        salt '*' service.list org.cups.cupsd
    uplistuLabelumac_utils.console_usertusernameulistt
return_stdouttrunas(R"R1RR!R5(RR8Rtlabel((s</usr/lib/python2.7/site-packages/salt/modules/mac_service.pytlist_*s	cC@s)t|dt�d}td|d|�S(u�
    Enable a launchd service. Raises an error if the service fails to be enabled

    :param str name: Service label, file name, or full path

    :param str runas: User to run launchctl commands

    :return: ``True`` if successful or if the service is already enabled
    :rtype: bool

    CLI Example:

    .. code-block:: bash

        salt '*' service.enable org.cups.cupsd
    R-iuenableR8(R0R!R5(RR8R-((s</usr/lib/python2.7/site-packages/salt/modules/mac_service.pytenableSscC@s)t|dt�d}td|d|�S(u�
    Disable a launchd service. Raises an error if the service fails to be
    disabled

    :param str name: Service label, file name, or full path

    :param str runas: User to run launchctl commands

    :return: ``True`` if successful or if the service is already disabled
    :rtype: bool

    CLI Example:

    .. code-block:: bash

        salt '*' service.disable org.cups.cupsd
    R-iudisableR8(R0R!R5(RR8R-((s</usr/lib/python2.7/site-packages/salt/modules/mac_service.pytdisablekscC@s(t|�\}}td||d|�S(u
    Start a launchd service.  Raises an error if the service fails to start

    .. note::
        To start a service in macOS the service must be enabled first. Use
        ``service.enable`` to enable the service.

    :param str name: Service label, file name, or full path

    :param str runas: User to run launchctl commands

    :return: ``True`` if successful or if the service is already running
    :rtype: bool

    CLI Example:

    .. code-block:: bash

        salt '*' service.start org.cups.cupsd
    u	bootstrapR8(R0R5(RR8R.R((s</usr/lib/python2.7/site-packages/salt/modules/mac_service.pytstart�scC@s(t|�\}}td||d|�S(u@
    Stop a launchd service.  Raises an error if the service fails to stop

    .. note::
        Though ``service.stop`` will unload a service in macOS, the service
        will start on next boot unless it is disabled. Use ``service.disable``
        to disable the service

    :param str name: Service label, file name, or full path

    :param str runas: User to run launchctl commands

    :return: ``True`` if successful or if the service is already stopped
    :rtype: bool

    CLI Example:

    .. code-block:: bash

        salt '*' service.stop org.cups.cupsd
    ubootoutR8(R0R5(RR8R.R((s</usr/lib/python2.7/site-packages/salt/modules/mac_service.pytstop�scC@s3t|�rt|d|�nt|d|�tS(uj
    Unloads and reloads a launchd service.  Raises an error if the service
    fails to reload

    :param str name: Service label, file name, or full path

    :param str runas: User to run launchctl commands

    :return: ``True`` if successful
    :rtype: bool

    CLI Example:

    .. code-block:: bash

        salt '*' service.restart org.cups.cupsd
    R8(tenabledR>R=R!(RR8((s</usr/lib/python2.7/site-packages/salt/modules/mac_service.pytrestart�scC@s4|rtd|�Syt|�Wn!tk
rE}tj|�dSX|rot|�rotddt�}ntd|�}d}x�|j	�D]w}d|kr�q�nt
j||j�d�r�|j�dj
�r|r�|d	7}n||j�d7}qq�q�Wt|�r0t|�r0|r0d
S|S(uO
    Return the status for a service.

    :param str name: Used to find the service from launchctl.  Can be any part
        of the service name or a regex expression.

    :param str sig: Find the service with status.pid instead.  Note that
        ``name`` must still be provided.

    :param str runas: User to run launchctl commands

    :return: The PID for the service if it is running, or 'loaded' if the
        service should not always have a PID, or otherwise an empty string

    :rtype: str

    CLI Example:

    .. code-block:: bash

        salt '*' service.status cups
    u
status.piduumac_utils.console_userR6R8uPIDi����iu
uloaded(t__salt__R"RtlogterrorR1RR!R:t
splitlinestretsearchtsplittisdigitR,R?(RtsigR8tmsgtoutputtpidstline((s</usr/lib/python2.7/site-packages/salt/modules/mac_service.pytstatus�s,

 cC@s+yt|�tSWntk
r&tSXdS(u
    Check that the given service is available.

    :param str name: The name of the service

    :return: True if the service is available, otherwise False
    :rtype: bool

    CLI Example:

    .. code-block:: bash

        salt '*' service.available com.openssh.sshd
    N(R"R!RR
(R((s</usr/lib/python2.7/site-packages/salt/modules/mac_service.pyt	availables


cC@st|�S(u?
    The inverse of service.available
    Check that the given service is not available.

    :param str name: The name of the service

    :return: True if the service is not available, otherwise False
    :rtype: bool

    CLI Example:

    .. code-block:: bash

        salt '*' service.missing com.openssh.sshd
    (RO(R((s</usr/lib/python2.7/site-packages/salt/modules/mac_service.pytmissing(scC@s4ytd|d|�tSWntk
r/tSXdS(uU
    Check if the specified service is enabled

    :param str name: The name of the service to look up

    :param str runas: User to run launchctl commands

    :return: True if the specified service enabled, otherwise False
    :rtype: bool

    CLI Example:

    .. code-block:: bash

        salt '*' service.enabled org.cups.cupsd
    RR8N(R:R!RR
(RR8((s</usr/lib/python2.7/site-packages/salt/modules/mac_service.pyR?;s

usystemcC@s�td|dtd|�}x�|jd�D]q}||kr+|jd�djd�d}|jd�d}||krq�d	|j�kr�tStSq+q+WtS(
u�
    Check if the specified service is not enabled. This is the opposite of
    ``service.enabled``

    :param str name: The name to look up

    :param str runas: User to run launchctl commands

    :param str domain: domain to check for disabled services. Default is system.

    :return: True if the specified service is NOT enabled, otherwise False
    :rtype: bool

    CLI Example:

    .. code-block:: bash

        salt '*' service.disabled org.cups.cupsd
    uprint-disabledR7R8u
u=>iu"iutrue(R5R!RGRR
(RR8tdomaintdisabledRtsrv_nameRN((s</usr/lib/python2.7/site-packages/salt/modules/mac_service.pyRRTs	 !cC@s<td|�}ttd�j��}tt||��S(uD
    Return a list of services that are enabled or available. Can be used to
    find the name of a service.

    :param str runas: User to run launchctl commands

    :return: A list of all the services available or enabled
    :rtype: list

    CLI Example:

    .. code-block:: bash

        salt '*' service.get_all
    R8umac_utils.available_services(tget_enabledtlistRtkeystsortedtset(R8R?RO((s</usr/lib/python2.7/site-packages/salt/modules/mac_service.pytget_allyscC@s�td|�}g|j�D]}|^q}g}xH|D]@}|jd�rVq;n|jd�\}}}|j|�q;Wtt|��S(u@
    Return a list of all services that are enabled. Can be used to find the
    name of a service.

    :param str runas: User to run launchctl commands

    :return: A list of all the services enabled on the system
    :rtype: list

    CLI Example:

    .. code-block:: bash

        salt '*' service.get_enabled
    R8uPIDu	(R:RDt
startswithRGtappendRWRX(R8tstdoutRMt
service_linesR?tpidRNR9((s</usr/lib/python2.7/site-packages/salt/modules/mac_service.pyRT�s
(0t__doc__t
__future__RRRtloggingRREtsalt.utils.filesRtsalt.utils.pathtsalt.utils.platformtsalt.utils.stringutilstsalt.exceptionsRtsalt.utils.versionsRR
tsalt.extRRt__func_alias__t	getLoggert__name__RBRRR"R,R
R0R1R#R5tNoneR:R;R<R=R>R@RNRORPR?RRRYRT(((s</usr/lib/python2.7/site-packages/salt/modules/mac_service.pyt<module>sH
			+	()			);		%

Zerion Mini Shell 1.0