%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python2.7/site-packages/salt/modules/
Upload File :
Create Path :
Current File : //lib/python2.7/site-packages/salt/modules/cron.pyo

�
���^c@@s�dZddlmZmZmZddlZddlZddlZddl	Zddl
ZddlZddlZddl
mZddlmZdZdZdZd	�Zd
�Zd�Zdd�Zd
�Zd�Zdd�Zd�Zd�Zd�Zd�Zd�Z d�Z!d�Z"ej#j$j%e"d�Z&e'ddd�Z(d�Z)e'ddd�Z*ddd�Z+ddddddd�Z,ej#j$j%e,d�Z-dd�Z.d�Z/dS( u�
Work with cron

.. note::
    Salt does not escape cron metacharacters automatically. You should
    backslash-escape percent characters and any other metacharacters that might
    be interpreted incorrectly by the shell.
i(tabsolute_importtunicode_literalstprint_functionN(tsix(trangeu4# Lines below here are managed by Salt, do not edit
uSALT_CRON_IDENTIFIERu	NO ID SETcC@s'tjjjd�rtStdfSdS(Nucrontabu2Cannot load cron module: crontab command not found(tsalttutilstpathtwhichtTruetFalse(((s5/usr/lib/python2.7/site-packages/salt/modules/cron.pyt__virtual__scC@sQt|tj�s!t|�}nytjjj|�SWntk
rLdSXdS(Nu(	t
isinstanceRtstring_typeststrRRtstringutilst
to_unicodet	TypeError(tval((s5/usr/lib/python2.7/site-packages/salt/modules/cron.pyt_ensure_string&s
cC@s7d}|dr|d}nt}|r3t|�SdS(u4SAFETYBELT, Only set if we really have an identifieru
identifierN(tNonetSALT_CRON_NO_IDENTIFIERR(tcrontcid((s5/usr/lib/python2.7/site-packages/salt/modules/cron.pyt_cron_id1s

c	C@s�td}}t|�}|r�|s.t}nt|�}|jdd�|krs|tkrs|tkrst}q�|jdd�|kr�|tkr�|r�|}n||k}n|dkr�||jdd�ks�|r�t}n|S(u{Check if:
      - we find a cron with same cmd, old state behavior
      - but also be smart enough to remove states changed crons where we do
        not removed priorly by a cron.absent by matching on the provided
        identifier.
        We assure retrocompatibility by only checking on identifier if
        and only if an identifier was set on the serialized crontab
    ucmdN(R
RRRRtgetR	(Rtcmdt
identifiertrett
id_matchedRteidentifier((s5/usr/lib/python2.7/site-packages/salt/modules/cron.pyt
_cron_matched<s&	
			$	cC@sB||kr>|dkr+|dkr;tSq>|dk	r>tSntS(Nurandomu*(R	RR
(toldtnew((s5/usr/lib/python2.7/site-packages/salt/modules/cron.pyt
_needs_changeiscC@s�g}x(|dD]}|jdj|��qW|rZ|dtkrg|jt�qgn
|jt�xp|dD]d}|ddks�|ddkr�|jdj|d��qr|jd	j|d|d��qrWx�|d
D]�}|ddk	s|ddk	r�d
}|drA|dj|djdd��7}n|drh|djt|d�7}n|d7}|j|�n|jdj|dtkr�dp�d|d|d|d|d|d|d��q�Wx�|dD]�}|ddk	s
|ddk	r�d
}|drI|dj|dj�jdd��7}n|drp|djt|d�7}n|d7}|j|�n|jdj|dtkr�dp�d|d|d��q�W|S(u[
    Takes a tab list structure and renders it to a list for applying it to
    a file
    upreu{0}
i����uenvuvalueuu{0}=""
unameu{0}={1}
ucronsucommentu
identifieru#u {0}u
u
# u {0}:{1}u{0}{1} {2} {3} {4} {5} {6}
u	commentedu
#DISABLED#uminuteuhourudaymonthumonthudayweekucmduspecialu{0}{1} {2}
uspecN(tappendtformattTAGRtreplacetSALT_CRON_IDENTIFIERR	trstrip(tlstRtpretenvRtcomment((s5/usr/lib/python2.7/site-packages/salt/modules/cron.pyt_render_tabts\
 % 
	

 
	#

cC@s.|rdj|�}nd}dj||�S(uI
    Returns a format string, to be used to build a crontab command.
    ucrontab -u {0}ucrontabu{0} {1}(R$(RtuserR((s5/usr/lib/python2.7/site-packages/salt/modules/cron.pyt_get_cron_cmdstr�scC@stj�td|�kS(uO
    Returns true if running instance's UID matches the specified user UID
    ufile.user_to_uid(tostgeteuidt__salt__(R.((s5/usr/lib/python2.7/site-packages/salt/modules/cron.pyt_check_instance_uid_match�scC@snt|�s!tjd�d	krGtdt|�d|dt�dkStdt||�dt�dkSdS(
u1
    Writes the contents of a file to a user's crontab

    CLI Example:

    .. code-block:: bash

        salt '*' cron.write_cron_file root /tmp/new_cron

    .. versionchanged:: 2015.8.9

    .. note::

        Some OS' do not support specifying user via the `crontab` command i.e. (Solaris, AIX)
    u	os_familyuSolarisuAIXucmd.retcodetrunastpython_shelliN(uSolarisuAIX(R3t
__grains__RR2R/R
(R.R((s5/usr/lib/python2.7/site-packages/salt/modules/cron.pytwrite_cron_file�s!
cC@sbt|�s!tjd�dkrAtdt|�d|dt�Stdt||�dt�SdS(	u[
    Writes the contents of a file to a user's crontab and return error message on error

    CLI Example:

    .. code-block:: bash

        salt '*' cron.write_cron_file_verbose root /tmp/new_cron

    .. versionchanged:: 2015.8.9

    .. note::

        Some OS' do not support specifying user via the `crontab` command i.e. (Solaris, AIX)
    u	os_familyuSolarisuAIXucmd.run_allR4R5N(uSolarisuAIX(R3R6RR2R/R
(R.R((s5/usr/lib/python2.7/site-packages/salt/modules/cron.pytwrite_cron_file_verbose�s!cC@s(g|D]}tjjj|�^q}tjjj�}t|�s[tjd�d
kr�tjjj	|ddt
d|�dd��}|j|�Wd	QXt
d
t|�d|dt
�}nStjjj	|ddd��}|j|�Wd	QXt
d
t||�dt
�}tj|�|S(uQ
    Takes a list of lines to be committed to a user's crontab and writes it
    u	os_familyuSolarisuAIXuw+tuidufile.user_to_uidtmodei�Nucmd.run_allR4R5(uSolarisuAIX(RRRtto_strtfilestmkstempR3R6RtfpopenR2t
writelinesR/R
R0tremove(R.tlinest_lRtfp_R((s5/usr/lib/python2.7/site-packages/salt/modules/cron.pyt_write_cron_lines�s(!1!	
cK@sxtgdD]g}|j|�d	kpn||tj||�kpntj||�j�dkon||dk^q
�S(
u|
    Returns true if the minute, hour, etc. params match their counterparts from
    the dict returned from list_tab().
    uminuteuhourudaymonthumonthudayweekurandomu*(uminuteuhourudaymonthumonthudayweekN(tallRRRt	text_typetlower(Rtkwargstx((s5/usr/lib/python2.7/site-packages/salt/modules/cron.pyt_date_time_matchscC@s�t|�s!tjd�dkrjd}tjjjtd|d|dtdt	d	t	��j
t�}nId
j|�}tjjjtd|dtdt	d	t	��j
t�}t|�dkr�|dj
d�r�|dd
5ndj|�S(u�
    Return the contents of the user's crontab

    CLI Example:

    .. code-block:: bash

        salt '*' cron.raw_cron root
    u	os_familyuSolarisuAIXu
crontab -lucmd.run_stdoutR4tignore_retcodeR(R5ucrontab -u {0} -liu8# DO NOT EDIT THIS FILE - edit the master and reinstall.iu(uSolarisuAIX(R3R6RRRtdatatdecodeR2R	R
t
splitlinesR$tlent
startswithtjoin(R.RRA((s5/usr/lib/python2.7/site-packages/salt/modules/cron.pytraw_crons&
!

	%
cC@sSt|�}igd6gd6gd6gd6}t}d }d }x|j�D]�}|dkrkt}qMn|r:t}|jd�r�|d}t}n|jd�rNi}|j�}	t|	�d	kr�qMn|	d
|d<dj|	d
�|d<||d<||d<t|d<|r(t|d<n|dj	|�d }d }t}qK|jd�r�|j
d�}
t|
kr�|
jt�}|d
j�}
t|d
�d
kr�|d
d
}q�n|d kr�|
}q7|d|
7}qK|j
d�d
krnd|ks&|jd�|jd�krn|jdd
�}	i}|	d
|d<|	d
|d<|dj	|�qKt|jd��dkrK|jd�}	i	|	d
d6|	d
d6|	d	d6|	dd6|	dd6|d6dj|	d�d6|d6td6}|rt|d<n|dj	|�d }d }t}qKqM|dj	|�qMW|S(!u�
    Return the contents of the specified user's crontab

    CLI Example:

    .. code-block:: bash

        salt '*' cron.list_tab root
    upreucronsuspecialuenvu3# Lines below here are managed by Salt, do not editu
#DISABLED#i
u@iiuspecu iucmdu
identifierucommentu	commentedu#u# u
u=unameuvalueiuminuteuhourudaymonthiumonthiudayweekN(RRR
RRNR	RPtsplitRORQR#tlstripR'R(tfindtindex(R.RLRtflagR,Rtlinetcommented_cron_jobtdattcompstcomment_linetparts((s5/usr/lib/python2.7/site-packages/salt/modules/cron.pytlist_tab8s�



	



		?

ulscC@s�t|�}x|dD]}t|�}t|||�r|ddkrQtpX|d}	|d|f|d|f||	f|d|fg}
|s�|r�|
j|d|f�ntg|
D]\}}t||�^q��r&t||d|�t|d|�s|d}nt|d|�s8|d}nt|d|�sX|d}nt|d|�s�|d}|tkr�|r�|}n|tkr�|ddkr�d}n||d<q�n|s�|r�t||�r�|}nt	|||d|d	|d|�}
|
d
krdS|
SndSqWi|d6|d6|d6|d6|d6}|dj|�t
|t|��}|d
r�|dSd
S(u�
    Set up a special command in the crontab.

    CLI Example:

    .. code-block:: bash

        salt '*' cron.set_special root @hourly 'echo foobar'
    uspecialu
identifierucommentu	commenteduspecucmdRt	commentedR,unewuupdatedupresenturetcodeustderrN(R^RRRRR#tanyR"t
rm_specialtset_specialRDR-(R.tspecialRR_R,RR)RRttest_setted_idttestsRItytjrettcomdat((s5/usr/lib/python2.7/site-packages/salt/modules/cron.pyRb�sb


	.



			


c
K@sitttd���d6tttd���d6tttdd���d6tttd���d	6}i}x�dD]�}tj|j|d
��j�}|dkr�tjtj||d�d�||<qzt|j	d
��dkrJt
|j	d
��}t|d�t|d�}}tjtj||��||<qz|||<qzW|ddj	�krwd}n%|ddj	�kr�d}nd}tj|jdd
��j�}	|	dkrtjtjtttd|d���d�d�|d<n
|	|d<|S(uG
    Returns a dict of date/time values to be used in a cron entry
    i<uminuteiuhourii
umonthiudayweeku1urandomiu:iu1 3 5 7 8 10 12iu4 6 9 11iiudaymonth(uminuteuhourumonthudayweek(
tlistRRRFRRGtrandomtsampleRORStsortedtinttrandint(
RHt	range_maxRtparamtvaluet
cron_rangetstarttendtdaymonth_maxtdaymonth((s5/usr/lib/python2.7/site-packages/salt/modules/cron.pyt_get_cron_date_time�s2
!*!"		!?
c
C@s�tj|�j�}tj|�j�}tj|�j�}tj|�j�}tj|�j�}t|�}
x�|
dD]�}t|�}t|||	�r�|ddkr�tp�|d}
|d|f|d|f|	|
f|d|f|d|f|d|f|d|f|d	|fg}|s:|	rT|j|d
|f�nt	g|D]\}}t
||�^q^�rOt||d|�t
|d|�s�|d}nt
|d|�s�|d}nt
|d|�s�|d}nt
|d|�s|d}nt
|d	|�s5|d	}nt
|d|�sU|d}nt
|d|�su|d}nt
|d
|�s�|d
}|tkr�|	r�|	}n|tkr�|ddkr�d}n||d<q�n|s�|rt
||	�r|}	nt|||||||d|d
|d|	�}|dkrHdS|SndSq�Wi|d
6|	d6|d6|d6}|j
td|d|d|d|d|��|
dj|�t|t|
��}|dr�|dSdS(u�
    Sets a cron job up for a specified user.

    CLI Example:

    .. code-block:: bash

        salt '*' cron.set_job root '*' '*' '*' '*' 1 /usr/local/weekly
    ucronsu
identifierucommentu	commenteduminuteuhourudaymonthumonthudayweekucmdRR_R,unewuupdatedupresenttminutethourRvtmonthtdayweekuretcodeustderrN(RRFRGR^RRRRR#R`R"trm_jobtset_jobtupdateRwRDR-(R.RxRyRvRzR{RR_R,RR)RRRdReRIRfRgRh((s5/usr/lib/python2.7/site-packages/salt/modules/cron.pyR}s�


	



.







			



c	C@s�t|�}d}d}x�tt|d��D]l}|dk	rEPnt|d||d|�r/|dkrw|}q�|d|d|kr�|}q�q/q/W|dk	r�|dj|�d}nt|t|��}|dr�|dS|S(	u�
    Remove a special cron job for a specified user.

    CLI Example:

    .. code-block:: bash

        salt '*' cron.rm_special root /usr/bin/foo
    uabsentuspecialRuspecuremoveduretcodeustderrN(R^RRRORtpopRDR-(	R.RRcRR)Rtrm_tindRh((s5/usr/lib/python2.7/site-packages/salt/modules/cron.pyRaws$
		
c
C@s2t|�}d}	d}
x�tt|d��D]�}|
dk	rEPnt|d||d|�r/tg|||||fD]}|dk	^q{�s�|}
q�t|d|d|d|d|d|d|�r�|}
q�q/q/W|
dk	r.|dj|
�d	}	t|t	|��}
|
d
r.|
dSn|	S(
u8
    Remove a cron job for a specified user. If any of the day/time params are
    specified, the job will only be removed if the specified params match.

    CLI Example:

    .. code-block:: bash

        salt '*' cron.rm_job root /usr/local/weekly
        salt '*' cron.rm_job root /usr/bin/foo dayweek=1
    uabsentucronsRRxRyRvRzR{uremoveduretcodeustderrN(
R^RRRORR`RJRRDR-(R.RRxRyRvRzR{RR)RR�R�RIRh((s5/usr/lib/python2.7/site-packages/salt/modules/cron.pyR|�s0.		
urmcC@s�t|�}xl|dD]`}||dkr||dkrst||�t|||�}|dkrldS|SndSqWi|d6|d6}|dj|�t|t|��}|dr�|dSdS(	u�
    Set up an environment variable in the crontab.

    CLI Example:

    .. code-block:: bash

        salt '*' cron.set_env root MAILTO user@example.com
    uenvunameuvalueunewuupdatedupresenturetcodeustderr(R^trm_envtset_envR#RDR-(R.tnameRqR)R+RgRh((s5/usr/lib/python2.7/site-packages/salt/modules/cron.pyR��s 


cC@s�t|�}d}d}x?tt|d��D]'}||d|dkr/|}q/q/W|dk	r�|dj|�d}nt|t|��}|dr�|dS|S(u�
    Remove cron environment variable for a specified user.

    CLI Example:

    .. code-block:: bash

        salt '*' cron.rm_env root MAILTO
    uabsentuenvunameuremoveduretcodeustderrN(R^RRRORRDR-(R.R�R)RR�R�Rh((s5/usr/lib/python2.7/site-packages/salt/modules/cron.pyR��s

	
(0t__doc__t
__future__RRRR0Rjtsalt.utils.dataRtsalt.utils.filestsalt.utils.functoolstsalt.utils.pathtsalt.utils.stringutilstsalt.extRtsalt.ext.six.movesRR%R'RRRRRRR"R-R/R3R7R8RDRJRRR^Rt	functoolstalias_functiontlsR
RbRwR}RaR|trmR�R�(((s5/usr/lib/python2.7/site-packages/salt/modules/cron.pyt<module>	sZ			-		=					
	#	]I	1^#)

Zerion Mini Shell 1.0