Mini Shell

Direktori : /usr/share/lvemanager/__pycache__/
Upload File :
Current File : //usr/share/lvemanager/__pycache__/crontab.cpython-311.pyc

�

J��q�(����ddlmZddlmZddlmZddlZddlZddlZgd�Z	dd�Zdd	�Z	d
�Z
d�Zd�Zd
�Z
dd�Zd�Zd�Zdd�ZdS)�)�print_function)�division)�absolute_importN)�add_cron�
erase_cron�remove_cron�
add_cron_taskTc		��|dkr/tttjdd������}|dkr/tttjdd������}	t	|||||||��}	n/#t
$r"tj�d��YnwxYwt||	|��dS)a�
    Add new cron task into crontab schedule iff this task or command wasn't already existed in the cron-file.

    :param str file_name: Name of cron-file in /etc/cron.d
    :param minute: Integer or char 'r' if to set random minute
    :param hour: Integer or char 'r' if to set random hour
    :param int, str day: Day number
    :param int, str month: Month number
    :param int, str day_of_week: Day of week number
    :param str user: Under what user do run command
    :param str command: What command do run
    :param bool check_command: If it is False, check that whole cron-task line already exists in crontab,
        check that command string exists instead. Default is True, check a command string.
    �rr�;�z"Can not add task with wrong syntaxN)
�int�round�random�uniform�format_cron_task�	TypeError�sys�stderr�writer	)
�	file_name�minute�hour�day�month�day_of_week�user�command�
check_command�	cron_tasks
          �
crontab.pyrrs��� ��}�}��U�6�>�!�R�0�0�1�1�2�2���s�{�{��5����2�.�.�/�/�0�0��?�$�V�T�3��{�D�RY�Z�Z�	�	���?�?�?��
���=�>�>�>�>�>�?�����)�Y�
�6�6�6�6�6s�,B�)B.�-B.Fc�
�d}	td|zd��}t|||��s|�d|z��n.#ttf$r|�|���YdSwxYw|���dS)a�
    Add new cron task in cron format iff this task or command in this task wasn't already existed in the cron-file.

    :param str file_name: Name of cron-file in /etc/cron.d
    :param str task: Cron task in format "min hour day mon d_of_w user command"
    :param bool check_command: If it is False, check that whole cron-task line already exists in crontab,
        check that command string exists instead. Default is False, check a whole cron-task string.
    N�/etc/cron.d/za+z%s
FT)�open�
is_in_cronr�IOError�OSError�close)r�taskr�fs    r!r	r	-s���	
�A����)�+�T�2�2���$��=�1�1�	#�
�G�G�F�T�M�"�"�"����W������=�
�G�G�I�I�I��u�u������G�G�I�I�I��4s�<A�'A,�+A,c�f�	tjd|z��dS#ttf$rYdSwxYw)z^
    Remove cron-file from fs

    :param str file_name: Name of cron-file in /etc/cron.d
    r#N)�os�remover'r&)rs r!rrCsI��
�
�	�.�9�,�-�-�-�-�-���W��
�
�
����
���s��0�0c	��d}	td|zd��}nQ#ttf$r=}tj�d|�dt
|���d���Yd}~nd}~wwxYw|�|���dSdS)zZ
    Make cron-file empty

    :param str file_name: Name of cron-file in /etc/cron.d
    Nr#�wzCan not erase crontab file z	 because �
)r$r&r'rrr�strr()rr*�errs   r!rrOs���	
�A�"���)�+�S�1�1�����W��"�"�"��
�����I�I�s�3�x�x�x�x�!�	"�	"�	"�	"�	"�	"�	"�	"�����"����	�}�	���	�	�	�	�	��}s��A&�3A!�!A&c�J�|||||||f}|D]}|�td����d|zS)a�
    Build cron-task string in the cron format

    :param minute: Integer or char 'r' if to set random minute
    :param hour: Integer or char 'r' if to set random hour
    :param int day: Day number
    :param int month: Month number
    :param int day_of_week: Day of week number
    :param str user: Under what user do run command
    :param str command: What command do run
    :return: Cron-task in the cron format
    :rtype: str
    NzWrong schedule for cron taskz%2s %2s %2s %2s %2s %10s %s)r)	rrrrrrr�	arguments�args	         r!rr_sK����s�E�;��g�F�I��<�<���;��:�;�;�;��(�9�4�4�c�.�|�dd��S)z�
    Split cron task string into cron task parts

    :param str task: Cron-task string in the cron format
    :return: List of cron-task parts
    :rtype: list of str
    N�)�split)r)s r!�parse_cron_taskr:ts���:�:�d�A���r6c#��K�d�|D��D]a}	|rt|��}ntt|���}|V��0#t$r%tj�d|z��Y�^wxYwdS)a<
    Returns iterator through crontab tasks

    :param iterable crontab: Iterator with crontab tasks' strings
    :param bool get_parsed: If it is True, return crontab task as list of task's parts
        return crontab task as a string instead
    :return: Crontab task
    :rtype: str
    :rtype: list of str
    c3�>K�|]}|���V��dS)N)�strip)�.0�ss  r!�	<genexpr>z#get_task_in_cron.<locals>.<genexpr>�s*����.�.��1�7�7�9�9�.�.�.�.�.�.r6zWrong crontab task syntax: %s
N)r:rrrrr)�crontab�
get_parsed�cron_t�ts    r!�get_task_in_cronrEs�����/�.�g�.�.�.�	�	��	��
?�#�F�+�+���$�o�f�&=�&=�>���G�G�G�G���	I�	I�	I��J���>��G�H�H�H�H�H�	I����
	�	s�(?�,A.�-A.c�`�t|�����D]}||krdS�dS)a
    Find first occurence of task in cron-file if it has

    :param str task: Cron-task in cront format to compare with
    :param file fd: File descriptor of opened cron file
    :return: True if such a task is already existed in cron-file, False instead
    :rtype: bool
    TF)rE�	readlines)r)�fdrDs   r!�is_task_in_cronrI�s=���b�l�l�n�n�
-�
-������9�9��4�4���5r6c��t|��d}t|���d���D]}|d|krdS�dS)a
    :param str task: Task with command to looking for
    :param file fd: File descriptor of opened cron file
    :return: True if such a command is already existed in cron-file, False instead
    :rtype: bool

    Find first occurence of command in cron-file if it has
    ���T)rBF)r:rErG)r)rHrrDs    r!�is_command_in_cronrL�sZ���d�#�#�B�'�G�
�b�l�l�n�n��
>�
>�
>�����R�5�G����4�4���5r6c�F�|rt||��St||��S)a�
    Find first occurence of command or task in cron-file if it has

    :param str task: Task or command to looking for
    :param file, BinaryIO fd: File descriptor of opened cron file
    :param bool check_command: If it is True, check command occurence, check task occurence instead
    :return: True if such a command or task is already existed in cron-file, False instead
    :rtype: bool
    )rLrI)r)rHrs   r!r%r%�s,���,�!�$��+�+�+��4��$�$�$r6)T)F)�
__future__rrrr,rr�__ALL__rr	rrrr:rErIrLr%�r6r!�<module>rQs��&�%�%�%�%�%�������&�&�&�&�&�&�	�	�	�	�
�
�
�
�
�
�
�
�
D�
D�
D�� �7�7�7�7�6����,	
�	
�	
�
�
�
� 5�5�5�*�������.���
�
�
� %�%�%�%�%�%r6

Zerion Mini Shell 1.0