Mini Shell
�
J��q�(�� � � d dl mZ d dl mZ d dl mZ d dlZd dlZd dlZg d�Z dd�Zdd �Z d
� Z
d� Zd� Zd
� Z
dd�Zd� Zd� Zdd�ZdS )� )�print_function)�division)�absolute_importN)�add_cron�
erase_cron�remove_cron�
add_cron_taskTc � � |dk r/t t t j dd� � � � � � }|dk r/t t t j dd� � � � � � } t |||||||� � } n/# t
$ r" t j � d� � Y nw xY wt | | |� � 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.pyr r s� � � ��}�}��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} t d| z d� � }t |||� � s|� d|z � � n.# t t f$ r |�|� � � Y dS w xY w|� � � 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 � t j d| z � � dS # t t f$ r Y dS w xY w)z^
Remove cron-file from fs
:param str file_name: Name of cron-file in /etc/cron.d
r# N)�os�remover'