File manager - Edit - /opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/mac_power.cpython-310.pyc
Back
o ;j5 � @ s� d Z ddlZddlZddlmZ dZdd� Zdd� Zd d � Z dd� Z d d� Zdd� Zdd� Z dd� Zdd� Zdd� Zdd� Zdd� Zdd� Zdd � Zd!d"� Zd#d$� Zd%d&� Zd'd(� Zd)d*� Zd+d,� ZdS )-zI Module for editing power settings on macOS .. versionadded:: 2016.3.0 � N)�SaltInvocationErrorZpowerc C s t jj�� sdS tS )z Only for macOS )FzMThe mac_power module could not be loaded: module only works on macOS systems.)�salt�utils�platformZ is_darwin�__virtualname__� r r �J/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/mac_power.py�__virtual__ s r c C s� t | t�r| �� dv r dS d�| �}t|��t | t�r(| r&d�| �}t|��dS t | t�r?| tdd�v r6| S d�| �}t|��d| � �}t|��) aA Helper function that validates the minutes parameter. Can be any number between 1 and 180. Can also be the string values "Never" and "Off". Because "On" and "Off" get converted to boolean values on the command line it will error if "On" is passed Returns: The value to be passed to the command )�neverZoffZNeverzTInvalid String Value for Minutes. String values must be "Never" or "Off". Passed: {}z�Invalid Boolean Value for Minutes. Boolean value "On" or "True" is not allowed. Salt CLI converts "On" to boolean True. Passed: {}� � zWInvalid Integer Value for Minutes. Integer values must be between 1 and 180. Passed: {}z2Unknown Variable Type Passed for Minutes. Passed: )� isinstance�str�lower�formatr �bool�int�range)�minutes�msgr r r �_validate_sleep s. � � � r c C s t � t� t� d�S )aI Displays the amount of idle time until the machine sleeps. Settings for Computer, Display, and Hard Disk are displayed. :return: A dictionary containing the sleep status for Computer, Display, and Hard Disk :rtype: dict CLI Example: .. code-block:: bash salt '*' power.get_sleep )ZComputerZDisplayz Hard Disk)�get_computer_sleep�get_display_sleep�get_harddisk_sleepr r r r � get_sleepK s �r c C sR t | �}d|� �}tjj�|� g }tttfD ] }|�tjj� ||�� qt |�S )a� Sets the amount of idle time until the machine sleeps. Sets the same value for Computer, Display, and Hard Disk. Pass "Never" or "Off" for computers that should never sleep. :param minutes: Can be an integer between 1 and 180 or "Never" or "Off" :ptype: int, str :return: True if successful, False if not :rtype: bool CLI Example: .. code-block:: bash salt '*' power.set_sleep 120 salt '*' power.set_sleep never zsystemsetup -setsleep )r r r � mac_utils�execute_return_successr r r �append�confirm_updated�all)r �value�cmd�state�checkr r r � set_sleepb s ��r$ c C � t jj�d�} t jj�| �S )z� Display the amount of idle time until the computer sleeps. :return: A string representing the sleep settings for the computer :rtype: str CLI Example: .. code-block:: bash salt '*' power.get_computer_sleep zsystemsetup -getcomputersleep�r r r �execute_return_result�parse_return��retr r r r � � r c C �4 t | �}d|� �}tjj�|� tjj�t|�t�S )a� Set the amount of idle time until the computer sleeps. Pass "Never" of "Off" to never sleep. :param minutes: Can be an integer between 1 and 180 or "Never" or "Off" :ptype: int, str :return: True if successful, False if not :rtype: bool CLI Example: .. code-block:: bash salt '*' power.set_computer_sleep 120 salt '*' power.set_computer_sleep off zsystemsetup -setcomputersleep )r r r r r r r r �r r r! r r r �set_computer_sleep� � �r. c C r% )z� Display the amount of idle time until the display sleeps. :return: A string representing the sleep settings for the displey :rtype: str CLI Example: .. code-block:: bash salt '*' power.get_display_sleep zsystemsetup -getdisplaysleepr&